Skip to content

Commit

Permalink
Add some TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
abyss7 committed Sep 2, 2017
1 parent ff65b88 commit d5345ac
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/base/c_utils_posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ inline bool GetSelfPath(String& result, String* error) {
return true;
}

// TODO: refactor on |std::filesystem|.
inline bool SetPermissions(const String& path, int mask, String* error) {
if (chmod(path.c_str(), mask) == -1) {
GetLastError(error);
Expand Down
17 changes: 16 additions & 1 deletion src/base/file_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@
namespace dist_clang {
namespace base {

// TODO: refactor on |std::filesystem|.
void WalkDirectory(
const Path& path,
Fn<void(const Path& file_path, ui64 mtime, ui64 size)> visitor,
String* error = nullptr);

// TODO: refactor on |std::filesystem|.
ui64 CalculateDirectorySize(const Path& path, String* error = nullptr);

// TODO: refactor on |std::filesystem| and |std::chrono|.
Pair<time_t /* unix timestamp, nanoseconds */> GetModificationTime(
const String& path, String* error = nullptr);

// TODO: refactor on |std::filesystem|.
inline bool RemoveEmptyDirectory(const String& path) {
return !rmdir(path.c_str());
}
Expand All @@ -28,7 +33,17 @@ inline bool ChangeOwner(const String& path, ui32 uid, String* error = nullptr) {
return true;
}

bool CreateDirectory(const String& path, String* error = nullptr);
inline bool CreateDirectory(const Path& path, String* error = nullptr) {
std::error_code ec;
std::experimental::filesystem::create_directories(path, ec);
if (ec) {
if (error) {
*error = ec.message();
}
return false;
}
return true;
}

inline bool ChangeCurrentDir(const Path& path, String* error = nullptr) {
std::error_code ec;
Expand Down
17 changes: 0 additions & 17 deletions src/base/file_utils_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,5 @@ Pair<time_t> GetModificationTime(const String& path, String* error) {
return {time_spec.tv_sec, time_spec.tv_nsec};
}

bool CreateDirectory(const String& path, String* error) {
for (size_t i = 1; i < path.size(); ++i) {
if (path[i] == '/' && mkdir(path.substr(0, i).c_str(), 0755) == -1 &&
errno != EEXIST) {
GetLastError(error);
return false;
}
}

if (mkdir(path.c_str(), 0755) == -1 && errno != EEXIST) {
GetLastError(error);
return false;
}

return true;
}

} // namespace base
} // namespace dist_clang
1 change: 1 addition & 0 deletions src/base/file_utils_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ TEST(FileUtilsTest, CreateDirectory) {
const TemporaryDir temp_dir;
const auto temp = temp_dir.path() / "1" / "2" / "3";

ASSERT_TRUE(CreateDirectory(temp, &error)) << error;
ASSERT_TRUE(CreateDirectory(temp, &error)) << error;

DIR* dir = opendir(temp.c_str());
Expand Down

0 comments on commit d5345ac

Please sign in to comment.