Use rename to bypass windows lockfile issue
This commit is contained in:
parent
cce4d108ce
commit
c81c631ae8
|
@ -261,11 +261,15 @@ public class FilesystemPackageCacheManagerLocks {
|
||||||
try {
|
try {
|
||||||
result = function.get();
|
result = function.get();
|
||||||
} finally {
|
} finally {
|
||||||
|
|
||||||
|
lockFile.renameTo(File.createTempFile(lockFile.getName(), ".lock-renamed"));
|
||||||
|
|
||||||
|
fileLock.release();
|
||||||
|
channel.close();
|
||||||
|
|
||||||
if (!lockFile.delete()) {
|
if (!lockFile.delete()) {
|
||||||
lockFile.deleteOnExit();
|
lockFile.deleteOnExit();
|
||||||
}
|
}
|
||||||
fileLock.release();
|
|
||||||
channel.close();
|
|
||||||
|
|
||||||
lock.writeLock().unlock();
|
lock.writeLock().unlock();
|
||||||
cacheLock.getLock().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 {
|
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);
|
FileLock fileLock = channel.tryLock(0, Long.MAX_VALUE, false);
|
||||||
if (fileLock != null) {
|
if (fileLock != null) {
|
||||||
final ByteBuffer buff = ByteBuffer.wrap("Hello world".getBytes(StandardCharsets.UTF_8));
|
final ByteBuffer buff = ByteBuffer.wrap("Hello world".getBytes(StandardCharsets.UTF_8));
|
||||||
channel.write(buff);
|
channel.write(buff);
|
||||||
System.out.println("File "+lockFileName+" is locked. Waiting for " + seconds + " seconds to release. ");
|
System.out.println("File "+lockFileName+" is locked. Waiting for " + seconds + " seconds to release. ");
|
||||||
Thread.sleep(seconds * 1000L);
|
Thread.sleep(seconds * 1000L);
|
||||||
file.delete();
|
|
||||||
|
lockFile.renameTo(File.createTempFile(lockFile.getName(), ".lock-renamed"));
|
||||||
|
|
||||||
fileLock.release();
|
fileLock.release();
|
||||||
|
channel.close();
|
||||||
System.out.println(System.currentTimeMillis());
|
System.out.println(System.currentTimeMillis());
|
||||||
System.out.println("File "+lockFileName+" is released.");
|
System.out.println("File "+lockFileName+" is released.");
|
||||||
|
|
||||||
channel.close();
|
lockFile.delete();
|
||||||
}}finally {
|
}}finally {
|
||||||
if (file.exists()) {
|
if (lockFile.exists()) {
|
||||||
file.delete();
|
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
|
// 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
|
// 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.
|
// 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