Skip to content

Fix for FileUtils.recursiveDelete() when dealing with symbolic links #3141

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
May 15, 2015

Conversation

cmaglie
Copy link
Member

@cmaglie cmaglie commented May 14, 2015

More detailed info in the commit message:

The documentation for File.delete() says that the method return true
if the the file is successfully deleted, otherwise false is returned.
An exception is thrown only when the file is not accessible (for
permission problem).

Removing the extra check solves another problem, for example in a
folder with the following situation:

    linkToFileA -> FileA
    FileA

if we remove FileA, we remain with a broken link that can't be removed
using FileUtils.deleteIfExists() because calling File.exists() on a
broken link returns *false*. This commit solve this problem.

note that the bug not always happens, it depends on the order the files are deleted.

cmaglie added 2 commits May 14, 2015 19:18
The documentation for File.delete() says that the method return true
if the the file is successfully deleted, otherwise false is returned.
An exception is thrown only when the file is not accessible (for
permission problem).

Removing the extra check solves another problem, for example in a
folder with the following situation:

    linkToFileA -> FileA
    FileA

if we remove FileA, we remain with a broken link that can't be removed
using FileUtils.deleteIfExists() because calling File.exists() on a
broken link returns *false*. This commit solve this problem.
file is already checked for being not null, no need to check again.
@@ -85,7 +85,7 @@ public static void recursiveDelete(File file) {
recursiveDelete(current);
}
}
deleteIfExists(file);
file.delete();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you deleted the .exists() check in deleteIfExists, could you still call that function instead of file.delete()? It uses a defensive approach checking if File is null

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's explained in the second commit: file is already checked for being not null, no need to check again
the check is here: https://github.com/arduino/Arduino/pull/3141/files#diff-fb3046d74e0c4a32b94edd584638ecd3L76

BTW if you prefer to keep the defensive approach and check anyway, just drop the second commit and keep only the first one!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed that. Thanks

@ffissore ffissore self-assigned this May 15, 2015
ffissore added a commit that referenced this pull request May 15, 2015
Fix for FileUtils.recursiveDelete() when dealing with symbolic links
@ffissore ffissore merged commit d008d9d into arduino:master May 15, 2015
@cmaglie cmaglie deleted the fix-recursive-delete branch May 15, 2015 14:51
@ffissore ffissore modified the milestone: Release 1.6.5 May 20, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants