4#include <cosmos/fs/DirFD.hxx>
5#include <cosmos/fs/types.hxx>
6#include <cosmos/SysString.hxx>
32 Directory{path, mode, {OpenFlag::CLOEXEC}} {}
39 open(path, mode, flags);
44 Directory{dir_fd, path, mode, {OpenFlag::CLOEXEC}} {}
49 open(dir_fd, path, mode, flags);
57 *
this = std::move(other);
60 Directory& operator=(Directory &&other)
noexcept {
61 m_auto_close = other.m_auto_close;
64 other.m_auto_close = AutoCloseFD{
true};
73 return open(path, mode, {OpenFlag::CLOEXEC});
86 open(dir_fd, path, mode, {OpenFlag::CLOEXEC});
105 m_auto_close = auto_close;
108 bool isOpen()
const {
return m_fd.valid(); }
130 DirFD fd()
const {
return m_fd; }
133 inline void unlinkFileAt(
const SysString path)
const;
136 inline void makeDirAt(
const SysString path,
const FileMode mode)
const;
139 inline void removeDirAt(
const SysString path)
const;
142 inline std::string readSymlinkAt(
const SysString path)
const;
145 inline void makeSymlinkAt(
const SysString target,
const SysString path)
const;
149 AutoCloseFD m_auto_close;
156#include <cosmos/fs/filesystem.hxx>
160void Directory::unlinkFileAt(
const SysString path)
const {
161 fs::unlink_file_at(m_fd, path);
164void Directory::makeDirAt(
const SysString path,
const FileMode mode)
const {
165 fs::make_dir_at(m_fd, path, mode);
168void Directory::removeDirAt(
const SysString path)
const {
169 fs::remove_dir_at(m_fd, path);
172std::string Directory::readSymlinkAt(
const SysString path)
const {
173 return fs::read_symlink_at(m_fd, path);
176void Directory::makeSymlinkAt(
const SysString target,
const SysString path)
const {
177 fs::make_symlink_at(target, m_fd, path);
A typesafe bit mask representation using class enums.
A specialized FileDescriptor for directory objects.
Representation of open directory file descriptors.
Directory(const SysString path, const OpenMode mode, const OpenFlags flags)
Open a directory by path using the given mode and flags.
Directory(const SysString path, const OpenMode mode=OpenMode::READ_ONLY)
Open a directory by path without special flags (close-on-exec will be set).
Directory(const DirFD dir_fd, const SysString path, const OpenMode mode, const OpenFlags flags)
Open a directory by path relative to dir_fd using the given mode and flags.
void open(const SysString path, const OpenMode mode=OpenMode::READ_ONLY)
Open a directory by path without special flags (close-on-exec will be set).
void open(DirFD fd, const AutoCloseFD auto_close)
Takes the already open directory file descriptor fd and operators on it.
void open(const DirFD dir_fd, const SysString path, const OpenMode mode)
Open a directory by path relative to dir_fd using the given mode and default flags.
Directory(const DirFD dir_fd, const SysString path, const OpenMode mode=OpenMode::READ_ONLY)
Open a directory by path relative to dir_fd using the given mode and default flags.
void close()
Close the current dir object.
OpenMode
Strong enum type wrapper for the basic open() mode flag.
Wrapper type around a C-style string for use with system APIs.