mirror of
https://github.com/matrix-construct/construct
synced 2024-12-26 15:33:54 +01:00
ircd::fs: Add remove() / rename() support.
This commit is contained in:
parent
121be689e8
commit
e37a8599f7
2 changed files with 46 additions and 0 deletions
|
@ -78,6 +78,12 @@ namespace ircd::fs
|
|||
std::vector<std::string> ls(const string_view &path);
|
||||
std::vector<std::string> ls_recursive(const string_view &path);
|
||||
|
||||
bool rename(std::nothrow_t, const string_view &old, const string_view &new_);
|
||||
void rename(const string_view &old, const string_view &new_);
|
||||
|
||||
bool remove(std::nothrow_t, const string_view &path);
|
||||
bool remove(const string_view &path);
|
||||
|
||||
std::string cwd();
|
||||
void chdir(const string_view &path);
|
||||
bool mkdir(const string_view &path);
|
||||
|
|
40
ircd/fs.cc
40
ircd/fs.cc
|
@ -239,6 +239,13 @@ catch(const filesystem::filesystem_error &e)
|
|||
"%s", e.what()
|
||||
};
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::fs::remove(const string_view &path)
|
||||
try
|
||||
{
|
||||
return filesystem::remove(fs::path(path));
|
||||
}
|
||||
catch(const filesystem::filesystem_error &e)
|
||||
{
|
||||
throw filesystem_error
|
||||
|
@ -247,6 +254,39 @@ catch(const filesystem::filesystem_error &e)
|
|||
};
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::fs::remove(std::nothrow_t,
|
||||
const string_view &path)
|
||||
{
|
||||
error_code ec;
|
||||
return filesystem::remove(fs::path(path), ec);
|
||||
}
|
||||
|
||||
void
|
||||
ircd::fs::rename(const string_view &old,
|
||||
const string_view &new_)
|
||||
try
|
||||
{
|
||||
filesystem::rename(path(old), path(new_));
|
||||
}
|
||||
catch(const filesystem::filesystem_error &e)
|
||||
{
|
||||
throw filesystem_error
|
||||
{
|
||||
"%s", e.what()
|
||||
};
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::fs::rename(std::nothrow_t,
|
||||
const string_view &old,
|
||||
const string_view &new_)
|
||||
{
|
||||
error_code ec;
|
||||
filesystem::rename(path(old), path(new_), ec);
|
||||
return !ec;
|
||||
}
|
||||
|
||||
std::vector<std::string>
|
||||
ircd::fs::ls_recursive(const string_view &path)
|
||||
try
|
||||
|
|
Loading…
Reference in a new issue