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

Do not delete files open and folder content when cleaning log #1523

Conversation

patrickelectric
Copy link
Member

No description provided.

Copy link
Collaborator

@joaoantoniocardoso joaoantoniocardoso left a comment

Choose a reason for hiding this comment

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

good

@patrickelectric patrickelectric force-pushed the do_not_delete_files_open_and_folder_content branch from 1ffe3ad to 72ed185 Compare March 2, 2023 00:58
@joaoantoniocardoso
Copy link
Collaborator

@patrickelectric I was thinking if this recursive implementation would be following soft links and if that is desirable or not. What do you think?

Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
@patrickelectric patrickelectric force-pushed the do_not_delete_files_open_and_folder_content branch from 72ed185 to fd0c298 Compare March 2, 2023 01:06
@patrickelectric
Copy link
Member Author

@patrickelectric I was thinking if this recursive implementation would be following soft links and if that is desirable or not. What do you think?

Are you talking about recursive symlinks ? If someone ends up doing that they deserve the cpu lock.

@joaoantoniocardoso
Copy link
Collaborator

joaoantoniocardoso commented Mar 2, 2023

@patrickelectric I was thinking if this recursive implementation would be following soft links and if that is desirable or not. What do you think?

Are you talking about recursive symlinks ? If someone ends up doing that they deserve the cpu lock.

Nope, both is_file and is_dir follow symbolic links, so we are deleting links to files and entering linked directories to remove everything there, which is unsound in some scenarios. Just take a moment to think if this is desired in every situation in which this function will be used.

And the behavior was different before this patch - it was deleting using this other function, which, if I understood it correctly, wouldn't follow links to directories.

@patrickelectric
Copy link
Member Author

@patrickelectric I was thinking if this recursive implementation would be following soft links and if that is desirable or not. What do you think?

Are you talking about recursive symlinks ? If someone ends up doing that they deserve the cpu lock.

Nope, both is_file and is_dir follow symbolic links, so we are deleting links to files and entering linked directories to remove everything there, which is unsound in some scenarios. Just take a moment to think if this is desired in every situation in which this function will be used.

And the behavior was different before this patch - it was deleting using this other function, which, if I understood it correctly, wouldn't follow links to directories.

Yes, I changed it to delete only files and not the folder structure.

@patrickelectric patrickelectric force-pushed the do_not_delete_files_open_and_folder_content branch from fd0c298 to d0b1e61 Compare March 2, 2023 01:16
@joaoantoniocardoso
Copy link
Collaborator

@patrickelectric I was thinking if this recursive implementation would be following soft links and if that is desirable or not. What do you think?

Are you talking about recursive symlinks ? If someone ends up doing that they deserve the cpu lock.

Nope, both is_file and is_dir follow symbolic links, so we are deleting links to files and entering linked directories to remove everything there, which is unsound in some scenarios. Just take a moment to think if this is desired in every situation in which this function will be used.
And the behavior was different before this patch - it was deleting using this other function, which, if I understood it correctly, wouldn't follow links to directories.

Yes, I changed it to delete only files and not the folder structure.

Yes I know, this is what we want. But now instead of deleting a link to a directory, we would be entering the linked directory and deleting everything there. This is quite a change in its behavior, can we write a comment on this function saying something like warning: every symbolic link to a directory present in this directory tree will be followed/entered and all the files in the destination's directory tree are going to be deleted.

@joaoantoniocardoso
Copy link
Collaborator

joaoantoniocardoso commented Mar 2, 2023

Maybe bikeshedding, but I was thinking again here... We might don't actually want to follow symbolic links to directories - considering that this function will be used against directories to which the user has access, if he creates a symbolic link to any system file, say / (to be more dramatic), it would lead to an undesired loss. Probably no one would do this for logs, but is this function used anywhere else, now here and in the future? 👀

@patrickelectric patrickelectric force-pushed the do_not_delete_files_open_and_folder_content branch from d0b1e61 to 85ca243 Compare March 2, 2023 01:41
@patrickelectric
Copy link
Member Author

@joaoantoniocardoso changed to not follow subfolder symlinks of the desired bath.

Copy link
Collaborator

@joaoantoniocardoso joaoantoniocardoso left a comment

Choose a reason for hiding this comment

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

💯

Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
@patrickelectric patrickelectric force-pushed the do_not_delete_files_open_and_folder_content branch from 85ca243 to 73be494 Compare March 2, 2023 02:37
@patrickelectric patrickelectric merged commit 5daa274 into bluerobotics:master Mar 2, 2023
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.

None yet

2 participants