Handle race in EncFSLocalFileProvider.listFiles()

It's possible for the source directory to be deleted after the
isDirectory() check but before the File.listFiles() call, so we should
handle this case by throwing an exception.
master
Mark Pariente 2013-10-24 00:31:58 -07:00
parent 2ec34cfb76
commit d1d14bea35
1 changed files with 9 additions and 0 deletions
src/main/java/org/mrpdaemon/sec/encfs

View File

@ -112,6 +112,15 @@ public class EncFSLocalFileProvider implements EncFSFileProvider {
}
File[] files = srcDir.listFiles();
if (files == null) {
/*
* It's possible for a race condition to occur and srcDir to be
* renamed or deleted between the isDirectory() check above and the
* listFiles() call after it. We throw an exception in this case.
*/
throw new IOException("Path: " + dirPath + " was removed!");
}
List<EncFSFileInfo> results = new ArrayList<EncFSFileInfo>(files.length);
for (File file : files) {
results.add(convertToFileInfo(file));