From 411aab02e3abf3bde0891b1cba4d77de1f3a9971 Mon Sep 17 00:00:00 2001 From: Lotus Date: Sun, 15 Jan 2012 19:01:05 +0100 Subject: [PATCH] Windows installer now detects reliably whether YaCy runs. A file lock on the yacy.running file has been implemented. --- build.nsi | 4 +++- source/net/yacy/yacy.java | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/build.nsi b/build.nsi index 436bd95dd..3fcd99e79 100755 --- a/build.nsi +++ b/build.nsi @@ -207,7 +207,9 @@ SectionEnd ; UNINSTALLER Section "Uninstall" - IfFileExists "$INSTDIR\DATA\yacy.running" 0 uninstall + ClearErrors + Delete "$INSTDIR\DATA\yacy.running" + IfErrors 0 uninstall MessageBox MB_ICONSTOP "$(stillRunning)" /SD IDOK Goto nouninstall diff --git a/source/net/yacy/yacy.java b/source/net/yacy/yacy.java index b6af8112e..77d6a4861 100644 --- a/source/net/yacy/yacy.java +++ b/source/net/yacy/yacy.java @@ -36,6 +36,9 @@ import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; +import java.io.RandomAccessFile; +import java.nio.channels.FileChannel; +import java.nio.channels.FileLock; import java.util.Iterator; import java.util.Map; import java.util.Properties; @@ -200,6 +203,12 @@ public final class yacy { Log.logSevere("STARTUP", "WARNING: the file " + f + " can not be created!"); try { new FileOutputStream(f).write(Integer.toString(OS.getPID()).getBytes()); } catch (final Exception e) { } // write PID f.deleteOnExit(); + FileChannel channel = null; + FileLock lock = null; + try { + channel = new RandomAccessFile(f,"rw").getChannel(); + lock = channel.tryLock(); // lock yacy.running + } catch (final Exception e) { }; final String oldconf = "DATA/SETTINGS/httpProxy.conf".replace("/", File.separator); final String newconf = "DATA/SETTINGS/yacy.conf".replace("/", File.separator); @@ -403,6 +412,8 @@ public final class yacy { Log.logSevere("STARTUP", "Unexpected Error: " + e.getClass().getName(),e); //System.exit(1); } + if(lock != null) lock.release(); + if(channel != null) channel.close(); } catch (final Exception ee) { Log.logSevere("STARTUP", "FATAL ERROR: " + ee.getMessage(),ee); } finally {