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

Move file operations to <filesystem> where possible #113

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

matthewtff
Copy link
Contributor

No description provided.

@matthewtff matthewtff force-pushed the move-to-filesystem branch from 78bcdd8 to 14bbdf8 Compare June 30, 2017 13:19
}

return buffer.st_size;
return File::Size(path_, error);
Copy link
Contributor Author

@matthewtff matthewtff Jul 1, 2017

Choose a reason for hiding this comment

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

This one may be a bad idea, as we can't track directory changes and path could be a relative one =/

Copy link
Owner

Choose a reason for hiding this comment

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

It also doesn't reuse opened descriptor.

Copy link
Owner

@abyss7 abyss7 left a comment

Choose a reason for hiding this comment

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

Reviewed til file_cache.cc

@@ -16,6 +16,7 @@ namespace base {

class Literal {
public:
inline const char* c_str() const { return str_; }
Copy link
Owner

Choose a reason for hiding this comment

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

Where is it used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In ReplaceTildeInPath from file_cache.cc.
GetHomeDir() returns a Literal thats why I should use c_str() to create a Path form it.

@@ -52,5 +59,19 @@ inline void GetLastError(String* error) {
}
}

inline bool SetPermissions(const Path& path, const Perms permissions,
Copy link
Owner

Choose a reason for hiding this comment

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

const Perms& ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should fit the machine word, but I'll make it a const ref no difference for me.

return false;
}

return (buffer.st_mode & S_IFDIR) == 0;
return std::experimental::filesystem::is_regular_file(status);
Copy link
Owner

Choose a reason for hiding this comment

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

It's not equivalent replacement - now we can't work with pipes, sockets, char or block devices.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I'll change it to !is_directory


return true;
return std::experimental::filesystem::exists(status) &&
std::experimental::filesystem::is_regular_file(status);
Copy link
Owner

Choose a reason for hiding this comment

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

is_regular_file() here is not equivalent too.

}

return buffer.st_size;
return File::Size(path_, error);
Copy link
Owner

Choose a reason for hiding this comment

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

It also doesn't reuse opened descriptor.


namespace dist_clang {
namespace base {

TEST(FileTest, Read) {
const auto expected_content = "All your base are belong to us"_l;
const base::TemporaryDir temp_dir;
const String file_path = String(temp_dir) + "/file";
const Path temp_dir_path = temp_dir.GetPath();
Copy link
Owner

Choose a reason for hiding this comment

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

Why not simply add operator Path? Then it will look like: Path(tmp_dir) / …

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As tmp_dir.GetPath() looks more explicit than operator Path().
But that's matter of taste, so let get the operator way...

namespace dist_clang {
namespace base {

void WalkDirectory(
Copy link
Owner

Choose a reason for hiding this comment

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

This is a hard part - I'll review this function later.


bool RemoveEmptyDirectory(const Path& path) {
std::error_code ec;
return std::experimental::filesystem::remove(path, ec);
Copy link
Owner

Choose a reason for hiding this comment

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

We can accidentally pass the file and remove it!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it OK to add a std::fs::is_directory check, or you would like to leave previous code for performance reasons?


bool CreateDirectory(const Path& path, String* error) {
std::error_code ec;
std::experimental::filesystem::create_directories(path, ec);
Copy link
Owner

Choose a reason for hiding this comment

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

It sets 0777 perms by default, while we want 0755

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like there's no way to implement this using :(
I'll revert this change, thanks.


ASSERT_TRUE(CreateDirectory(temp, &error)) << error;
ASSERT_TRUE(CreateDirectory(temp.string(), &error)) << error;
Copy link
Owner

Choose a reason for hiding this comment

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

Why .string()?

@matthewtff
Copy link
Contributor Author

Should I close this one now?

@abyss7
Copy link
Owner

abyss7 commented Sep 7, 2017

No, I want to use this PR as a reference for a further work.

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.

2 participants