Add more file utils
Reviewers: teon.banek Reviewed By: teon.banek Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D2384
This commit is contained in:
parent
9652f8e265
commit
fe2196b403
@ -39,12 +39,22 @@ void EnsureDirOrDie(const std::filesystem::path &dir) {
|
||||
"isn't a directory!";
|
||||
}
|
||||
|
||||
bool DirExists(const std::filesystem::path &dir) {
|
||||
std::error_code error_code; // For exception suppression.
|
||||
return std::filesystem::is_directory(dir, error_code);
|
||||
}
|
||||
|
||||
bool DeleteDir(const std::filesystem::path &dir) noexcept {
|
||||
std::error_code error_code; // For exception suppression.
|
||||
if (!std::filesystem::is_directory(dir, error_code)) return false;
|
||||
return std::filesystem::remove_all(dir, error_code) > 0;
|
||||
}
|
||||
|
||||
bool DeleteFile(const std::filesystem::path &file) noexcept {
|
||||
std::error_code error_code; // For exception suppression.
|
||||
return std::filesystem::remove(file, error_code);
|
||||
}
|
||||
|
||||
bool CopyFile(const std::filesystem::path &src,
|
||||
const std::filesystem::path &dst) noexcept {
|
||||
std::error_code error_code; // For exception suppression.
|
||||
|
@ -26,9 +26,15 @@ bool EnsureDir(const std::filesystem::path &dir) noexcept;
|
||||
/// an error message for which directory the ensuring failed.
|
||||
void EnsureDirOrDie(const std::filesystem::path &dir);
|
||||
|
||||
/// Returns a boolean indicating whether the directory exists.
|
||||
bool DirExists(const std::filesystem::path &dir);
|
||||
|
||||
/// Deletes everything from the given directory including the directory.
|
||||
bool DeleteDir(const std::filesystem::path &dir) noexcept;
|
||||
|
||||
/// Deletes just the specified file. Symlinks are not followed.
|
||||
bool DeleteFile(const std::filesystem::path &file) noexcept;
|
||||
|
||||
/// Copies the file from `src` to `dst`.
|
||||
bool CopyFile(const std::filesystem::path &src,
|
||||
const std::filesystem::path &dst) noexcept;
|
||||
|
Loading…
Reference in New Issue
Block a user