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

Fix filesystem helpers for directory manipulation. #30

Merged
merged 3 commits into from
Jan 15, 2020

Conversation

hidmic
Copy link
Contributor

@hidmic hidmic commented Jan 14, 2020

Precisely what the title says. Also added a partial std::filesystem::remove() equivalent for rcpputils::fs::create_directories() testing purposes.

Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
@hidmic hidmic requested a review from a team as a code owner January 14, 2020 19:05
@hidmic
Copy link
Contributor Author

hidmic commented Jan 14, 2020

CI up to rcpputils:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

inline bool remove(const path & p)
{
#ifdef _WIN32
return _rmdir(p.string().c_str()) == 0;
Copy link
Member

Choose a reason for hiding this comment

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

What if the path is a file?
remove is supposed to delete both files and empty directories.
See https://en.cppreference.com/w/cpp/filesystem/remove.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's why I said it's a partial implementation. We can make it full, I simply didn't have a use case.

Copy link
Member

Choose a reason for hiding this comment

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

Add a comment in the docsrting of the function. If not, later users might not realize.

@@ -183,16 +183,31 @@ inline bool create_directories(const path & p)
{
path p_built;

Copy link
Member

Choose a reason for hiding this comment

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

nit: delete this new line and add one between status and the for loop?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A bit of a taste nit, but sure, either way is fine. See 6ac7378.

include/rcpputils/filesystem_helper.hpp Show resolved Hide resolved
#else
mkdir(p_built.string().c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
status = mkdir(p_built.string().c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
Copy link
Member

Choose a reason for hiding this comment

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

According to create_directory docs, the directory is created with 0777 perms (see here).

Copy link
Member

Choose a reason for hiding this comment

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

Also, shouldn't break the loop if status is not zero?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

According to create_directory docs, the directory is created with 0777 perms (see here).

True. I do not know why the original author made it 0775 instead though.

Also, shouldn't break the loop if status is not zero?

It is.

Copy link
Member

Choose a reason for hiding this comment

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

It is.

Didn't realize.

Copy link

@thomas-moulard thomas-moulard left a comment

Choose a reason for hiding this comment

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

LGTM

Note that rcutils now provide rcutils_mkdir and other filesystem related functions. In the future, this class should probably just become a wrapper around the C code.

Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
@hidmic
Copy link
Contributor Author

hidmic commented Jan 14, 2020

So, @ivanpauno has two good points:

  • rcpputils::fs::create_directories should use 0777 permissions to fully imitate std::filesystem::create_directories -- and to actually be consistent with its behavior in Windows.
  • rcpputils::fs::remove should also allow file removal to fully imitate its std::filesystem counterpart.

@thomas-moulard any comments in favor or against?

@jacobperron
Copy link
Member

+1 on both raised points in order to match the behavior of std equivalents.

Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
@hidmic
Copy link
Contributor Author

hidmic commented Jan 14, 2020

@ivanpauno @jacobperron alright, done in 449e1a4.

Copy link
Member

@jacobperron jacobperron left a comment

Choose a reason for hiding this comment

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

LGTM pending another round of CI

@prajakta-gokhale
Copy link

Re-running CI for rcpputils

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@prajakta-gokhale prajakta-gokhale merged commit f601ee5 into master Jan 15, 2020
@prajakta-gokhale prajakta-gokhale deleted the hidmic/fix-filesystem-utils branch January 15, 2020 20:47
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.

5 participants