diff --git a/src/io/devices/Device.cpp b/src/io/devices/Device.cpp new file mode 100644 index 00000000..600f9c26 --- /dev/null +++ b/src/io/devices/Device.cpp @@ -0,0 +1,16 @@ +#include "Device.hpp" + +#include "../io.hpp" + +using namespace io; + +SubDevice::SubDevice( + std::shared_ptr parent, + const std::string& path, + bool createDirectory +) + : parent(std::move(parent)), root(path) { + if (createDirectory && !this->parent->exists(path)) { + this->parent->mkdirs(path); + } +} diff --git a/src/io/devices/Device.hpp b/src/io/devices/Device.hpp index 30d885fa..ee40d2f9 100644 --- a/src/io/devices/Device.hpp +++ b/src/io/devices/Device.hpp @@ -28,8 +28,11 @@ namespace io { class SubDevice : public Device { public: - SubDevice(std::shared_ptr parent, const std::string& path) - : parent(std::move(parent)), root(path) {} + SubDevice( + std::shared_ptr parent, + const std::string& path, + bool createDirectory = true + ); std::filesystem::path resolve(std::string_view path) override { return parent->resolve((root / path).pathPart());