-
Notifications
You must be signed in to change notification settings - Fork 75
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
FileUtilities#remove(): do nothing if file does not exist #2159
Conversation
What would happen if the to be deleted file is a directory? |
@madoar Probably the same as removing the file because PhoenicisOrg/scripts#1124 is still open |
If the directory doesn't exist, nothing. Otherwise: FileUtils.deleteDirectory(fileToDelete); |
Which order is wrong? |
@@ -162,7 +166,8 @@ public void remove(String path) throws IOException { | |||
final File fileToDelete = new File(path); | |||
|
|||
if (!fileToDelete.exists()) { | |||
throw new IllegalArgumentException(String.format("Path \"%s\" does not exist", path)); | |||
LOGGER.debug(String.format("Cannot remove file or directory: path \"%s\" does not exist", path)); | |||
return; | |||
} | |||
|
|||
assertInDirectory(fileToDelete); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the assertion should then be moved before if (!fileToDelete.exists()) { .. }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why should it matter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The order seems wrong like this. Let us say the script wants to execute remove("/home/<your/home>/important-file");
then I wouldn't expect a debug message that says the file does not exist but an error message that tells me that the script tries to access files it has no access to
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want we can handle this in another PR. I just want to talk about this now that it is still fresh on my mind
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks :)
fixes PhoenicisOrg/scripts#1162
It seems that this behavior was intended anyways because we use