Github user StephanEwen commented on a diff in the pull request:
https://github.com/apache/flink/pull/3219#discussion_r98687559
--- Diff: flink-core/src/main/java/org/apache/flink/util/FileUtils.java ---
@@ -148,14 +158,49 @@ public static void deleteDirectory(File directory)
throws IOException {
return;
}
- // delete the directory. this fails if the directory is
not empty, meaning
- // if new files got concurrently created. we want to
fail then.
- try {
- Files.delete(directory.toPath());
- }
- catch (NoSuchFileException ignored) {
- // if someone else deleted this concurrently,
we don't mind
- // the result is the same for us, after all
+ java.nio.file.Path directoryPath = directory.toPath();
+ if (OperatingSystem.isWindows()) {
+ // delete the directory. this fails if the
directory is not empty, meaning
+ // if new files got concurrently created. we
want to fail then.
+ try {
+ Files.delete(directoryPath);
+ } catch (NoSuchFileException ignored) {
+ // if someone else deleted this
concurrently, we don't mind
+ // the result is the same for us, after
all
+ } catch (AccessDeniedException e) {
+ // This may occur on Windows if another
process is currently
+ // deleting the file, since the file
must be opened in order
+ // to delete it. We double check here
to make sure the file
+ // was actually deleted by another
process. Note that this
+ // isn't a perfect solution, but it's
better than nothing.
+ if (Files.exists(directoryPath)) {
+ throw e;
+ }
+ } catch (DirectoryNotEmptyException e) {
+ // This may occur on Windows for some
reason even for empty
+ // directories. Apparently there's a
timing/visibility
+ // issue when concurrently deleting the
contents of a directory
+ // and afterwards deleting the
directory itself.
+ try {
+ Thread.sleep(50);
--- End diff --
Then I do not understand the comment above. It reads like that can happen
even if there is no other thread attempting to delete the directory?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---