Skip to content

Only ignore IOException when fsyncing on dirs #42972

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 7, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -264,17 +264,19 @@ public FileVisitResult visitFileFailed(final Path file, final IOException exc) t
*/
public static void fsync(final Path fileToSync, final boolean isDir) throws IOException {
try (FileChannel file = FileChannel.open(fileToSync, isDir ? StandardOpenOption.READ : StandardOpenOption.WRITE)) {
file.force(true);
} catch (final IOException ioe) {
if (isDir) {
assert (LINUX || MAC_OS_X) == false :
"on Linux and MacOSX fsyncing a directory should not throw IOException, "+
"we just don't want to rely on that in production (undocumented); got: " + ioe;
// ignore exception if it is a directory
return;
try {
file.force(true);
} catch (final IOException e) {
if (isDir) {
assert (LINUX || MAC_OS_X) == false :
"on Linux and MacOSX fsyncing a directory should not throw IOException, "+
"we just don't want to rely on that in production (undocumented); got: " + e;
// ignore exception if it is a directory
return;
}
// throw original exception
throw e;
}
// throw original exception
throw ioe;
}
}
}