|
@@ -599,8 +599,12 @@ public abstract class Storage extends StorageInfo {
|
|
|
* @throws IOException if locking fails.
|
|
|
*/
|
|
|
FileLock tryLock() throws IOException {
|
|
|
+ boolean deletionHookAdded = false;
|
|
|
File lockF = new File(root, STORAGE_FILE_LOCK);
|
|
|
- lockF.deleteOnExit();
|
|
|
+ if (!lockF.exists()) {
|
|
|
+ lockF.deleteOnExit();
|
|
|
+ deletionHookAdded = true;
|
|
|
+ }
|
|
|
RandomAccessFile file = new RandomAccessFile(lockF, "rws");
|
|
|
FileLock res = null;
|
|
|
try {
|
|
@@ -613,6 +617,12 @@ public abstract class Storage extends StorageInfo {
|
|
|
file.close();
|
|
|
throw e;
|
|
|
}
|
|
|
+ if (res != null && !deletionHookAdded) {
|
|
|
+ // If the file existed prior to our startup, we didn't
|
|
|
+ // call deleteOnExit above. But since we successfully locked
|
|
|
+ // the dir, we can take care of cleaning it up.
|
|
|
+ lockF.deleteOnExit();
|
|
|
+ }
|
|
|
return res;
|
|
|
}
|
|
|
|