From 32510e9511491f258c18d628845c0b49a09457e1 Mon Sep 17 00:00:00 2001 From: Iwein Fuld Date: Sat, 19 Sep 2009 17:04:57 +0000 Subject: [PATCH] removed Java 6 dependency --- .../integration/file/locking/LockFileFileLocker.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/org.springframework.integration.file/src/main/java/org/springframework/integration/file/locking/LockFileFileLocker.java b/org.springframework.integration.file/src/main/java/org/springframework/integration/file/locking/LockFileFileLocker.java index a9f6179a12..dcc3fdf7e1 100644 --- a/org.springframework.integration.file/src/main/java/org/springframework/integration/file/locking/LockFileFileLocker.java +++ b/org.springframework.integration.file/src/main/java/org/springframework/integration/file/locking/LockFileFileLocker.java @@ -43,7 +43,7 @@ public class LockFileFileLocker implements FileLocker { * Makes a best effort attempt at locking the file atomically. The chances of success are wholly dependant on the * underlying operating system. * - * The locking mechanism will create a prelock file, remove write permissions from that file and move it to a lock + * The locking mechanism will create a prelock file and move it to a lock * file location. */ public boolean lock(File fileToLock) { @@ -58,8 +58,8 @@ public class LockFileFileLocker implements FileLocker { logger.warn("Failed to lock file", e); return false; } - preLockFile.setWritable(false); - if (preLockFile.renameTo(lockFile)) { + //there is still a small chance that the next line will be done concurrently and the file will be picked up twice + if (!lockFile.exists()&&preLockFile.renameTo(lockFile)) { return true; } preLockFile.delete(); @@ -73,7 +73,6 @@ public class LockFileFileLocker implements FileLocker { */ public void unlock(File fileToUnlock) { File lockFile = new File(workdir, fileToUnlock.getName() + LOCK_SUFFIX); - lockFile.setWritable(true); lockFile.delete(); } }