add io::Device::mkdir

This commit is contained in:
MihailRis
2025-02-04 14:10:23 +03:00
parent f8d0ded70e
commit 1ec8f89599
6 changed files with 37 additions and 9 deletions
+8 -3
View File
@@ -20,7 +20,8 @@ namespace io {
virtual bool exists(std::string_view path) = 0;
virtual bool isdir(std::string_view path) = 0;
virtual bool isfile(std::string_view path) = 0;
virtual void mkdirs(std::string_view path) = 0;
virtual bool mkdir(std::string_view path) = 0;
virtual bool mkdirs(std::string_view path) = 0;
virtual bool remove(std::string_view path) = 0;
virtual uint64_t removeAll(std::string_view path) = 0;
virtual std::unique_ptr<PathsGenerator> list(std::string_view path) = 0;
@@ -62,8 +63,12 @@ namespace io {
return parent->isfile((root / path).pathPart());
}
void mkdirs(std::string_view path) override {
parent->mkdirs((root / path).pathPart());
bool mkdir(std::string_view path) override {
return parent->mkdir((root / path).pathPart());
}
bool mkdirs(std::string_view path) override {
return parent->mkdirs((root / path).pathPart());
}
bool remove(std::string_view path) override {
+15 -2
View File
@@ -64,15 +64,28 @@ bool StdfsDevice::isfile(std::string_view path) {
return fs::is_regular_file(resolved);
}
void StdfsDevice::mkdirs(std::string_view path) {
bool StdfsDevice::mkdir(std::string_view path) {
auto resolved = resolve(path);
std::error_code ec;
fs::create_directories(resolved, ec);
bool created = fs::create_directory(resolved, ec);
if (ec) {
logger.error() << "error creating directory " << resolved << ": "
<< ec.message();
}
return created;
}
bool StdfsDevice::mkdirs(std::string_view path) {
auto resolved = resolve(path);
std::error_code ec;
bool created = fs::create_directories(resolved, ec);
if (ec) {
logger.error() << "error creating directories " << resolved << ": "
<< ec.message();
}
return created;
}
bool StdfsDevice::remove(std::string_view path) {
+2 -1
View File
@@ -12,7 +12,8 @@ namespace io {
bool exists(std::string_view path) override;
bool isdir(std::string_view path) override;
bool isfile(std::string_view path) override;
void mkdirs(std::string_view path) override;
bool mkdir(std::string_view path) override;
bool mkdirs(std::string_view path) override;
bool remove(std::string_view path) override;
uint64_t removeAll(std::string_view path) override;
std::unique_ptr<PathsGenerator> list(std::string_view path) override;