Skip to content
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

Merged
merged 2 commits into from
Jan 3, 2020
Merged

FileUtilities#remove(): do nothing if file does not exist #2159

merged 2 commits into from
Jan 3, 2020

Conversation

plata
Copy link
Collaborator

@plata plata commented Jan 3, 2020

fixes PhoenicisOrg/scripts#1162

It seems that this behavior was intended anyways because we use

Files.deleteIfExists(fileToDelete.toPath());

@madoar
Copy link
Collaborator

madoar commented Jan 3, 2020

What would happen if the to be deleted file is a directory?

@Zemogiter
Copy link
Contributor

@madoar Probably the same as removing the file because PhoenicisOrg/scripts#1124 is still open

@plata
Copy link
Collaborator Author

plata commented Jan 3, 2020

If the directory doesn't exist, nothing. Otherwise:

FileUtils.deleteDirectory(fileToDelete);

madoar
madoar previously approved these changes Jan 3, 2020
@madoar madoar dismissed their stale review January 3, 2020 10:54

Wrong order of statements

@plata
Copy link
Collaborator Author

plata commented Jan 3, 2020

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);
Copy link
Collaborator

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()) { .. }

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Why should it matter?

Copy link
Collaborator

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

Copy link
Collaborator

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok.

Copy link
Collaborator

@madoar madoar left a comment

Choose a reason for hiding this comment

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

Thanks :)

@plata plata merged commit eb875cb into PhoenicisOrg:master Jan 3, 2020
@plata plata deleted the file-remove-no-exception branch January 3, 2020 11:21
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.

vcrun6sp6 crash
3 participants