Don’t delete lockfile on exit if file could not be locked.
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Wed, 22 Oct 2008 23:38:54 +0000 (01:38 +0200)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Wed, 22 Oct 2008 23:38:54 +0000 (01:38 +0200)
src/de/todesbaum/jsite/main/Configuration.java

index 3322c03..b38e986 100644 (file)
@@ -113,9 +113,12 @@ public class Configuration {
                        return false;
                }
                File lockFile = new File(lockFilename);
-               lockFile.deleteOnExit();
                try {
-                       return lockFile.createNewFile();
+                       boolean fileLocked = lockFile.createNewFile();
+                       if (fileLocked) {
+                               lockFile.deleteOnExit();
+                       }
+                       return fileLocked;
                } catch (IOException e) {
                        /* ignore. */
                }
@@ -123,6 +126,13 @@ public class Configuration {
        }
 
        /**
+        * Tells the VM to remove the lock file on program exit.
+        */
+       public void removeLockfileOnExit() {
+               new File(lockFilename).deleteOnExit();
+       }
+
+       /**
         * Reads the configuration from the file.
         */
        private void readConfiguration() {