add io::Device::mkdir
This commit is contained in:
@@ -20,7 +20,8 @@ namespace io {
|
|||||||
virtual bool exists(std::string_view path) = 0;
|
virtual bool exists(std::string_view path) = 0;
|
||||||
virtual bool isdir(std::string_view path) = 0;
|
virtual bool isdir(std::string_view path) = 0;
|
||||||
virtual bool isfile(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 bool remove(std::string_view path) = 0;
|
||||||
virtual uint64_t removeAll(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;
|
virtual std::unique_ptr<PathsGenerator> list(std::string_view path) = 0;
|
||||||
@@ -62,8 +63,12 @@ namespace io {
|
|||||||
return parent->isfile((root / path).pathPart());
|
return parent->isfile((root / path).pathPart());
|
||||||
}
|
}
|
||||||
|
|
||||||
void mkdirs(std::string_view path) override {
|
bool mkdir(std::string_view path) override {
|
||||||
parent->mkdirs((root / path).pathPart());
|
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 {
|
bool remove(std::string_view path) override {
|
||||||
|
|||||||
@@ -64,15 +64,28 @@ bool StdfsDevice::isfile(std::string_view path) {
|
|||||||
return fs::is_regular_file(resolved);
|
return fs::is_regular_file(resolved);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StdfsDevice::mkdirs(std::string_view path) {
|
bool StdfsDevice::mkdir(std::string_view path) {
|
||||||
auto resolved = resolve(path);
|
auto resolved = resolve(path);
|
||||||
|
|
||||||
std::error_code ec;
|
std::error_code ec;
|
||||||
fs::create_directories(resolved, ec);
|
bool created = fs::create_directory(resolved, ec);
|
||||||
if (ec) {
|
if (ec) {
|
||||||
logger.error() << "error creating directory " << resolved << ": "
|
logger.error() << "error creating directory " << resolved << ": "
|
||||||
<< ec.message();
|
<< 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) {
|
bool StdfsDevice::remove(std::string_view path) {
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ namespace io {
|
|||||||
bool exists(std::string_view path) override;
|
bool exists(std::string_view path) override;
|
||||||
bool isdir(std::string_view path) override;
|
bool isdir(std::string_view path) override;
|
||||||
bool isfile(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;
|
bool remove(std::string_view path) override;
|
||||||
uint64_t removeAll(std::string_view path) override;
|
uint64_t removeAll(std::string_view path) override;
|
||||||
std::unique_ptr<PathsGenerator> list(std::string_view path) override;
|
std::unique_ptr<PathsGenerator> list(std::string_view path) override;
|
||||||
|
|||||||
+10
-2
@@ -213,13 +213,21 @@ bool io::exists(const io::path& file) {
|
|||||||
return device->exists(file.pathPart());
|
return device->exists(file.pathPart());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool io::create_directory(const io::path& file) {
|
||||||
|
auto& device = io::require_device(file.entryPoint());
|
||||||
|
if (device.isdir(file.pathPart())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return device.mkdirs(file.pathPart());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool io::create_directories(const io::path& file) {
|
bool io::create_directories(const io::path& file) {
|
||||||
auto& device = io::require_device(file.entryPoint());
|
auto& device = io::require_device(file.entryPoint());
|
||||||
if (device.isdir(file.pathPart())) {
|
if (device.isdir(file.pathPart())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
device.mkdirs(file.pathPart());
|
return device.mkdirs(file.pathPart());
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool io::remove(const io::path& file) {
|
bool io::remove(const io::path& file) {
|
||||||
|
|||||||
@@ -151,6 +151,7 @@ namespace io {
|
|||||||
bool is_regular_file(const io::path& file);
|
bool is_regular_file(const io::path& file);
|
||||||
bool is_directory(const io::path& file);
|
bool is_directory(const io::path& file);
|
||||||
bool exists(const io::path& file);
|
bool exists(const io::path& file);
|
||||||
|
bool create_directory(const io::path& file);
|
||||||
bool create_directories(const io::path& file);
|
bool create_directories(const io::path& file);
|
||||||
bool remove(const io::path& file);
|
bool remove(const io::path& file);
|
||||||
uint64_t remove_all(const io::path& file);
|
uint64_t remove_all(const io::path& file);
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ static int l_length(lua::State* L) {
|
|||||||
|
|
||||||
static int l_mkdir(lua::State* L) {
|
static int l_mkdir(lua::State* L) {
|
||||||
io::path path = lua::require_string(L, 1);
|
io::path path = lua::require_string(L, 1);
|
||||||
return lua::pushboolean(L, io::create_directories(path)); // FIXME
|
return lua::pushboolean(L, io::create_directory(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int l_mkdirs(lua::State* L) {
|
static int l_mkdirs(lua::State* L) {
|
||||||
|
|||||||
Reference in New Issue
Block a user