From e37a8599f790a322434498328b1d3b0130ec9f6e Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 26 Feb 2018 20:37:19 -0800 Subject: [PATCH] ircd::fs: Add remove() / rename() support. --- include/ircd/fs/fs.h | 6 ++++++ ircd/fs.cc | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/include/ircd/fs/fs.h b/include/ircd/fs/fs.h index cabc58429..b71c78c16 100644 --- a/include/ircd/fs/fs.h +++ b/include/ircd/fs/fs.h @@ -78,6 +78,12 @@ namespace ircd::fs std::vector ls(const string_view &path); std::vector 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); diff --git a/ircd/fs.cc b/ircd/fs.cc index 8a6cfb5f1..2fdaf5038 100644 --- a/ircd/fs.cc +++ b/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 ircd::fs::ls_recursive(const string_view &path) try