LUCENE-5588: Workaround for fsyncing non-existing directory

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1586475 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Uwe Schindler 2014-04-10 21:53:54 +00:00
parent 63d67496cf
commit d825efca44
1 changed files with 7 additions and 2 deletions

View File

@ -289,10 +289,15 @@ public abstract class FSDirectory extends BaseDirectory {
Set<String> toSync = new HashSet<>(names);
toSync.retainAll(staleFiles);
for (String name : toSync)
for (String name : toSync) {
fsync(name);
}
IOUtils.fsync(directory, true);
// fsync the directory itsself, but only if there was any file fsynced before
// (otherwise it can happen that the directory does not yet exist)!
if (!toSync.isEmpty()) {
IOUtils.fsync(directory, true);
}
staleFiles.removeAll(toSync);
}