Skip to content
Snippets Groups Projects
Commit 412f2103 authored by Jan Kožusznik's avatar Jan Kožusznik
Browse files

fix: lock workspace

parent 45dc6078
Branches
No related tags found
No related merge requests found
...@@ -17,11 +17,11 @@ public class FileLock implements Closeable { ...@@ -17,11 +17,11 @@ public class FileLock implements Closeable {
public static final Logger log = LoggerFactory.getLogger(cz.it4i.fiji.haas_spim_benchmark.commands.FileLock.class); public static final Logger log = LoggerFactory.getLogger(cz.it4i.fiji.haas_spim_benchmark.commands.FileLock.class);
private final Path localPath; private final Path localPath;
private FileChannel fileChannel; private FileChannel fileChannel;
private java.nio.channels.FileLock lock; private java.nio.channels.FileLock lock;
public FileLock(Path lockPath) throws FileNotFoundException { public FileLock(Path lockPath) throws FileNotFoundException {
this.localPath = lockPath; this.localPath = lockPath;
} }
...@@ -31,11 +31,15 @@ public class FileLock implements Closeable { ...@@ -31,11 +31,15 @@ public class FileLock implements Closeable {
StandardOpenOption.CREATE); StandardOpenOption.CREATE);
try { try {
this.lock = fileChannel.tryLock(); this.lock = fileChannel.tryLock();
if (this.lock != null) {
return true;
}
} catch (OverlappingFileLockException e) { } catch (OverlappingFileLockException e) {
this.fileChannel.close(); // IGNORE
return false;
} }
return true; this.fileChannel.close();
this.fileChannel = null;
return false;
} }
@Override @Override
...@@ -47,10 +51,12 @@ public class FileLock implements Closeable { ...@@ -47,10 +51,12 @@ public class FileLock implements Closeable {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
} }
} }
try { if (fileChannel != null) {
fileChannel.close(); try {
} catch (IOException e) { fileChannel.close();
log.error(e.getMessage(), e); } catch (IOException e) {
log.error(e.getMessage(), e);
}
} }
try { try {
Files.delete(localPath); Files.delete(localPath);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment