Use rename to bypass windows lockfile issue
This commit is contained in:
parent
cce4d108ce
commit
c81c631ae8
|
@ -261,11 +261,15 @@ public class FilesystemPackageCacheManagerLocks {
|
|||
try {
|
||||
result = function.get();
|
||||
} finally {
|
||||
|
||||
lockFile.renameTo(File.createTempFile(lockFile.getName(), ".lock-renamed"));
|
||||
|
||||
fileLock.release();
|
||||
channel.close();
|
||||
|
||||
if (!lockFile.delete()) {
|
||||
lockFile.deleteOnExit();
|
||||
}
|
||||
fileLock.release();
|
||||
channel.close();
|
||||
|
||||
lock.writeLock().unlock();
|
||||
cacheLock.getLock().writeLock().unlock();
|
||||
|
|
|
@ -93,24 +93,27 @@ public class LockfileTestProcessUtility {
|
|||
*/
|
||||
private static void lockWaitAndDelete(String path, String lockFileName, int seconds) throws InterruptedException, IOException {
|
||||
|
||||
File file = Paths.get(path,lockFileName).toFile();
|
||||
File lockFile = Paths.get(path,lockFileName).toFile();
|
||||
|
||||
try (FileChannel channel = new RandomAccessFile(file.getAbsolutePath(), "rw").getChannel()) {
|
||||
try (FileChannel channel = new RandomAccessFile(lockFile.getAbsolutePath(), "rw").getChannel()) {
|
||||
FileLock fileLock = channel.tryLock(0, Long.MAX_VALUE, false);
|
||||
if (fileLock != null) {
|
||||
final ByteBuffer buff = ByteBuffer.wrap("Hello world".getBytes(StandardCharsets.UTF_8));
|
||||
channel.write(buff);
|
||||
System.out.println("File "+lockFileName+" is locked. Waiting for " + seconds + " seconds to release. ");
|
||||
Thread.sleep(seconds * 1000L);
|
||||
file.delete();
|
||||
|
||||
lockFile.renameTo(File.createTempFile(lockFile.getName(), ".lock-renamed"));
|
||||
|
||||
fileLock.release();
|
||||
channel.close();
|
||||
System.out.println(System.currentTimeMillis());
|
||||
System.out.println("File "+lockFileName+" is released.");
|
||||
|
||||
channel.close();
|
||||
lockFile.delete();
|
||||
}}finally {
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
if (lockFile.exists()) {
|
||||
lockFile.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ public class LockfileTestUtility {
|
|||
// the file system immediately. It is unlikely to appear in production environments, but should it occur, it will
|
||||
// result in a lock file being erroneously reported as not having an owning process, and will cause a package to
|
||||
// fail to be loaded from that cache until the lock is cleaned up by cache initialization.
|
||||
Thread.sleep(100);
|
||||
//Thread.sleep(100);
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue