jaulib v1.3.0
Jau Support Library (C++, Java, ..)
Classes | Typedefs | Enumerations | Functions
File Utilities

File types and functionality. More...

Classes

class  jau::fs::dir_item
 Representing a directory item split into dirname() and basename(). More...
 
class  jau::fs::file_stats
 Platform agnostic representation of POSIX ::lstat() and ::stat() for a given pathname. More...
 
struct  jau::fs::mount_ctx
 

Typedefs

typedef jau::function< void(const dir_item &)> jau::fs::consume_dir_item
 void consume_dir_item(const dir_item& item) More...
 
typedef uint64_t jau::fs::mountflags_t
 Generic flag bit values for mount() flags. More...
 
typedef jau::function< bool(traverse_event, const file_stats &, size_t)> jau::fs::path_visitor
 path_visitor jau::FunctionDef definition More...
 
typedef int jau::fs::umountflags_t
 Generic flag bit values for umount() flags. More...
 

Enumerations

enum class  jau::fs::copy_options : uint16_t {
  jau::fs::copy_options::none = 0 , jau::fs::copy_options::recursive = 1 << 0 , jau::fs::copy_options::follow_symlinks = 1 << 1 , jau::fs::copy_options::into_existing_dir = 1 << 2 ,
  jau::fs::copy_options::ignore_symlink_errors = 1 << 8 , jau::fs::copy_options::overwrite = 1 << 9 , jau::fs::copy_options::preserve_all = 1 << 10 , jau::fs::copy_options::sync = 1 << 11 ,
  jau::fs::copy_options::verbose = 1 << 15
}
 Filesystem copy options used to copy() path elements. More...
 
enum class  jau::fs::fmode_t : uint32_t {
  jau::fs::fmode_t::none = 0 , jau::fs::fmode_t::set_uid = 04000 , jau::fs::fmode_t::set_gid = 02000 , jau::fs::fmode_t::sticky = 01000 ,
  jau::fs::fmode_t::ugs_set = 07000 , jau::fs::fmode_t::read_usr = 00400 , jau::fs::fmode_t::write_usr = 00200 , jau::fs::fmode_t::exec_usr = 00100 ,
  jau::fs::fmode_t::rwx_usr = 00700 , jau::fs::fmode_t::read_grp = 00040 , jau::fs::fmode_t::write_grp = 00020 , jau::fs::fmode_t::exec_grp = 00010 ,
  jau::fs::fmode_t::rwx_grp = 00070 , jau::fs::fmode_t::read_oth = 00004 , jau::fs::fmode_t::write_oth = 00002 , jau::fs::fmode_t::exec_oth = 00001 ,
  jau::fs::fmode_t::rwx_oth = 00007 , jau::fs::fmode_t::rwx_all = 00777 , jau::fs::fmode_t::def_dir_prot = 00750 , jau::fs::fmode_t::def_file_prot = 00640 ,
  jau::fs::fmode_t::protection_mask = 0b00000000000000000000111111111111 , jau::fs::fmode_t::sock = 0b00000000000000000001000000000000 , jau::fs::fmode_t::blk = 0b00000000000000000010000000000000 , jau::fs::fmode_t::chr = 0b00000000000000000100000000000000 ,
  jau::fs::fmode_t::fifo = 0b00000000000000001000000000000000 , jau::fs::fmode_t::dir = 0b00000000000000010000000000000000 , jau::fs::fmode_t::file = 0b00000000000000100000000000000000 , jau::fs::fmode_t::link = 0b00000000000001000000000000000000 ,
  jau::fs::fmode_t::no_access = 0b00100000000000000000000000000000 , jau::fs::fmode_t::not_existing = 0b01000000000000000000000000000000 , jau::fs::fmode_t::type_mask = 0b01100000000001111111000000000000
}
 Generic file type and POSIX protection mode bits as used in file_stats, touch(), mkdir() etc. More...
 
enum class  jau::fs::mountflags_linux : mountflags_t {
  jau::fs::mountflags_linux::none = 0 , jau::fs::mountflags_linux::rdonly = 1 , jau::fs::mountflags_linux::nosuid = 2 , jau::fs::mountflags_linux::nodev = 4 ,
  jau::fs::mountflags_linux::noexec = 8 , jau::fs::mountflags_linux::synchronous = 16 , jau::fs::mountflags_linux::remount = 32 , jau::fs::mountflags_linux::mandlock = 64 ,
  jau::fs::mountflags_linux::dirsync = 128 , jau::fs::mountflags_linux::noatime = 1024 , jau::fs::mountflags_linux::nodiratime = 2048 , jau::fs::mountflags_linux::bind = 4096 ,
  jau::fs::mountflags_linux::move = 8192 , jau::fs::mountflags_linux::rec = 16384 , jau::fs::mountflags_linux::silent = 32768 , jau::fs::mountflags_linux::posixacl = 1 << 16 ,
  jau::fs::mountflags_linux::unbindable = 1 << 17 , jau::fs::mountflags_linux::private_ = 1 << 18 , jau::fs::mountflags_linux::slave = 1 << 19 , jau::fs::mountflags_linux::shared = 1 << 20 ,
  jau::fs::mountflags_linux::relatime = 1 << 21 , jau::fs::mountflags_linux::kernmount = 1 << 22 , jau::fs::mountflags_linux::i_version = 1 << 23 , jau::fs::mountflags_linux::strictatime = 1 << 24 ,
  jau::fs::mountflags_linux::lazytime = 1 << 25 , jau::fs::mountflags_linux::active = 1 << 30 , jau::fs::mountflags_linux::nouser = 1UL << 31
}
 Flag bit values for mount() flags under GNU/Linux. More...
 
enum class  jau::fs::traverse_event : uint16_t {
  jau::fs::traverse_event::none = 0 , jau::fs::traverse_event::symlink = 1 << 0 , jau::fs::traverse_event::file = 1 << 1 , jau::fs::traverse_event::file_symlink = symlink | file ,
  jau::fs::traverse_event::dir_symlink = 1 << 2 , jau::fs::traverse_event::dir_check_entry = 1 << 7 , jau::fs::traverse_event::dir_entry = 1 << 8 , jau::fs::traverse_event::dir_exit = 1 << 9 ,
  jau::fs::traverse_event::dir_non_recursive = dir_entry | dir_exit
}
 Filesystem traverse event used to call path_visitor for path elements from visit(). More...
 
enum class  jau::fs::traverse_options : uint16_t {
  jau::fs::traverse_options::none = 0 , jau::fs::traverse_options::recursive = 1 << 0 , jau::fs::traverse_options::follow_symlinks = 1 << 1 , jau::fs::traverse_options::lexicographical_order = 1 << 2 ,
  jau::fs::traverse_options::dir_check_entry = 1 << 7 , jau::fs::traverse_options::dir_entry = 1 << 8 , jau::fs::traverse_options::dir_exit = 1 << 9 , jau::fs::traverse_options::verbose = 1 << 15
}
 Filesystem traverse options used to visit() path elements. More...
 
enum class  jau::fs::umountflags_linux : umountflags_t { jau::fs::umountflags_linux::force = 1 , jau::fs::umountflags_linux::detach = 2 , jau::fs::umountflags_linux::expire = 4 , jau::fs::umountflags_linux::nofollow = 8 }
 Flag bit values for umount() flags under GNU/Linux. More...
 

Functions

std::string jau::fs::absolute (const std::string_view &relpath) noexcept
 Returns the absolute path of given relpath if existing, otherwise an empty string. More...
 
std::string jau::fs::basename (const std::string_view &path) noexcept
 Return stripped leading directory components from given path separated by /. More...
 
bool jau::fs::chdir (const std::string &path) noexcept
 Change working directory. More...
 
bool jau::fs::compare (const file_stats &source1, const file_stats &source2, const bool verbose=false) noexcept
 Compare the bytes of both files, denoted by source1 and source2. More...
 
bool jau::fs::compare (const std::string &source1, const std::string &source2, const bool verbose=false) noexcept
 Compare the bytes of both files, denoted by source1 and source2. More...
 
bool jau::fs::copy (const std::string &source_path, const std::string &dest_path, const copy_options copts=copy_options::none) noexcept
 Copy the given source_path to dest_path using copy_options. More...
 
std::string jau::fs::dirname (const std::string_view &path) noexcept
 Return stripped last component from given path separated by /, excluding the trailing separator /. More...
 
int jau::fs::from_named_fd (const std::string &named_fd) noexcept
 Returns the file descriptor from the given named file descriptor. More...
 
std::string jau::fs::get_cwd () noexcept
 Return the current working directory or empty on failure. More...
 
bool jau::fs::get_dir_content (const int dirfd, const std::string &path, const consume_dir_item &digest) noexcept
 Returns a list of directory elements excluding . More...
 
bool jau::fs::get_dir_content (const std::string &path, const consume_dir_item &digest) noexcept
 Returns a list of directory elements excluding . More...
 
constexpr bool jau::fs::is_set (const copy_options mask, const copy_options bit) noexcept
 
constexpr bool jau::fs::is_set (const file_stats::field_t mask, const file_stats::field_t bits) noexcept
 
constexpr bool jau::fs::is_set (const fmode_t mask, const fmode_t bits) noexcept
 
constexpr bool jau::fs::is_set (const mountflags_linux mask, const mountflags_linux bit) noexcept
 
constexpr bool jau::fs::is_set (const traverse_event mask, const traverse_event bit) noexcept
 
constexpr bool jau::fs::is_set (const traverse_options mask, const traverse_options bit) noexcept
 
constexpr bool jau::fs::is_set (const umountflags_linux mask, const umountflags_linux bit) noexcept
 
bool jau::fs::isAbsolute (const std::string_view &path) noexcept
 Returns true if first character is / or - in case of Windows - \\. More...
 
bool jau::fs::mkdir (const std::string &path, const fmode_t mode=jau::fs::fmode_t::def_dir_prot, const bool verbose=false) noexcept
 Create directory. More...
 
mount_ctx jau::fs::mount (const std::string &source, const std::string &target, const std::string &fs_type, const mountflags_t flags, const std::string &fs_options="")
 Attach the filesystem named in source to target using the given filesystem source directly. More...
 
mount_ctx jau::fs::mount_image (const std::string &image_path, const std::string &target, const std::string &fs_type, const mountflags_t flags, const std::string &fs_options="")
 Attach the filesystem image named in image_path to target using an intermediate platform specific filesystem image loop-device. More...
 
constexpr uint16_t jau::fs::number (const copy_options rhs) noexcept
 
constexpr uint32_t jau::fs::number (const file_stats::field_t rhs) noexcept
 
constexpr uint32_t jau::fs::number (const fmode_t rhs) noexcept
 
constexpr mountflags_t jau::fs::number (const mountflags_linux rhs) noexcept
 
constexpr uint16_t jau::fs::number (const traverse_event rhs) noexcept
 
constexpr uint16_t jau::fs::number (const traverse_options rhs) noexcept
 
constexpr umountflags_t jau::fs::number (const umountflags_linux rhs) noexcept
 
constexpr bool jau::fs::operator!= (const copy_options lhs, const copy_options rhs) noexcept
 
constexpr bool jau::fs::operator!= (const file_stats::field_t lhs, const file_stats::field_t rhs) noexcept
 
constexpr bool jau::fs::operator!= (const fmode_t lhs, const fmode_t rhs) noexcept
 
constexpr bool jau::fs::operator!= (const mountflags_linux lhs, const mountflags_linux rhs) noexcept
 
constexpr bool jau::fs::operator!= (const traverse_event lhs, const traverse_event rhs) noexcept
 
constexpr bool jau::fs::operator!= (const traverse_options lhs, const traverse_options rhs) noexcept
 
constexpr bool jau::fs::operator!= (const umountflags_linux lhs, const umountflags_linux rhs) noexcept
 
constexpr copy_options jau::fs::operator& (const copy_options lhs, const copy_options rhs) noexcept
 
constexpr file_stats::field_t jau::fs::operator& (const file_stats::field_t lhs, const file_stats::field_t rhs) noexcept
 
constexpr fmode_t jau::fs::operator& (const fmode_t lhs, const fmode_t rhs) noexcept
 
constexpr mountflags_linux jau::fs::operator& (const mountflags_linux lhs, const mountflags_linux rhs) noexcept
 
constexpr traverse_event jau::fs::operator& (const traverse_event lhs, const traverse_event rhs) noexcept
 
constexpr traverse_options jau::fs::operator& (const traverse_options lhs, const traverse_options rhs) noexcept
 
constexpr umountflags_linux jau::fs::operator& (const umountflags_linux lhs, const umountflags_linux rhs) noexcept
 
constexpr copy_optionsjau::fs::operator&= (copy_options &lhs, const copy_options rhs) noexcept
 
constexpr file_stats::field_tjau::fs::operator&= (file_stats::field_t &lhs, const file_stats::field_t rhs) noexcept
 
constexpr fmode_tjau::fs::operator&= (fmode_t &lhs, const fmode_t rhs) noexcept
 
constexpr mountflags_linuxjau::fs::operator&= (mountflags_linux &lhs, const mountflags_linux rhs) noexcept
 
constexpr mountflags_tjau::fs::operator&= (mountflags_t &lhs, const mountflags_linux rhs) noexcept
 
constexpr traverse_eventjau::fs::operator&= (traverse_event &lhs, const traverse_event rhs) noexcept
 
constexpr traverse_optionsjau::fs::operator&= (traverse_options &lhs, const traverse_options rhs) noexcept
 
constexpr umountflags_linuxjau::fs::operator&= (umountflags_linux &lhs, const umountflags_linux rhs) noexcept
 
constexpr umountflags_tjau::fs::operator&= (umountflags_t &lhs, const umountflags_linux rhs) noexcept
 
constexpr bool jau::fs::operator== (const copy_options lhs, const copy_options rhs) noexcept
 
constexpr bool jau::fs::operator== (const file_stats::field_t lhs, const file_stats::field_t rhs) noexcept
 
constexpr bool jau::fs::operator== (const fmode_t lhs, const fmode_t rhs) noexcept
 
constexpr bool jau::fs::operator== (const mountflags_linux lhs, const mountflags_linux rhs) noexcept
 
constexpr bool jau::fs::operator== (const traverse_event lhs, const traverse_event rhs) noexcept
 
constexpr bool jau::fs::operator== (const traverse_options lhs, const traverse_options rhs) noexcept
 
constexpr bool jau::fs::operator== (const umountflags_linux lhs, const umountflags_linux rhs) noexcept
 
constexpr copy_options jau::fs::operator^ (const copy_options lhs, const copy_options rhs) noexcept
 
constexpr file_stats::field_t jau::fs::operator^ (const file_stats::field_t lhs, const file_stats::field_t rhs) noexcept
 
constexpr fmode_t jau::fs::operator^ (const fmode_t lhs, const fmode_t rhs) noexcept
 
constexpr mountflags_linux jau::fs::operator^ (const mountflags_linux lhs, const mountflags_linux rhs) noexcept
 
constexpr traverse_event jau::fs::operator^ (const traverse_event lhs, const traverse_event rhs) noexcept
 
constexpr traverse_options jau::fs::operator^ (const traverse_options lhs, const traverse_options rhs) noexcept
 
constexpr umountflags_linux jau::fs::operator^ (const umountflags_linux lhs, const umountflags_linux rhs) noexcept
 
constexpr copy_optionsjau::fs::operator^= (copy_options &lhs, const copy_options rhs) noexcept
 
constexpr file_stats::field_tjau::fs::operator^= (file_stats::field_t &lhs, const file_stats::field_t rhs) noexcept
 
constexpr fmode_tjau::fs::operator^= (fmode_t &lhs, const fmode_t rhs) noexcept
 
constexpr mountflags_linuxjau::fs::operator^= (mountflags_linux &lhs, const mountflags_linux rhs) noexcept
 
constexpr mountflags_tjau::fs::operator^= (mountflags_t &lhs, const mountflags_linux rhs) noexcept
 
constexpr traverse_eventjau::fs::operator^= (traverse_event &lhs, const traverse_event rhs) noexcept
 
constexpr traverse_optionsjau::fs::operator^= (traverse_options &lhs, const traverse_options rhs) noexcept
 
constexpr umountflags_linuxjau::fs::operator^= (umountflags_linux &lhs, const umountflags_linux rhs) noexcept
 
constexpr umountflags_tjau::fs::operator^= (umountflags_t &lhs, const umountflags_linux rhs) noexcept
 
constexpr copy_options jau::fs::operator| (const copy_options lhs, const copy_options rhs) noexcept
 
constexpr file_stats::field_t jau::fs::operator| (const file_stats::field_t lhs, const file_stats::field_t rhs) noexcept
 
constexpr fmode_t jau::fs::operator| (const fmode_t lhs, const fmode_t rhs) noexcept
 
constexpr mountflags_linux jau::fs::operator| (const mountflags_linux lhs, const mountflags_linux rhs) noexcept
 
constexpr traverse_event jau::fs::operator| (const traverse_event lhs, const traverse_event rhs) noexcept
 
constexpr traverse_options jau::fs::operator| (const traverse_options lhs, const traverse_options rhs) noexcept
 
constexpr umountflags_linux jau::fs::operator| (const umountflags_linux lhs, const umountflags_linux rhs) noexcept
 
constexpr copy_optionsjau::fs::operator|= (copy_options &lhs, const copy_options rhs) noexcept
 
constexpr file_stats::field_tjau::fs::operator|= (file_stats::field_t &lhs, const file_stats::field_t rhs) noexcept
 
constexpr fmode_tjau::fs::operator|= (fmode_t &lhs, const fmode_t rhs) noexcept
 
constexpr mountflags_linuxjau::fs::operator|= (mountflags_linux &lhs, const mountflags_linux rhs) noexcept
 
constexpr mountflags_tjau::fs::operator|= (mountflags_t &lhs, const mountflags_linux rhs) noexcept
 
constexpr traverse_eventjau::fs::operator|= (traverse_event &lhs, const traverse_event rhs) noexcept
 
constexpr traverse_optionsjau::fs::operator|= (traverse_options &lhs, const traverse_options rhs) noexcept
 
constexpr umountflags_linuxjau::fs::operator|= (umountflags_linux &lhs, const umountflags_linux rhs) noexcept
 
constexpr umountflags_tjau::fs::operator|= (umountflags_t &lhs, const umountflags_linux rhs) noexcept
 
constexpr copy_options jau::fs::operator~ (const copy_options rhs) noexcept
 
constexpr file_stats::field_t jau::fs::operator~ (const file_stats::field_t rhs) noexcept
 
constexpr fmode_t jau::fs::operator~ (const fmode_t rhs) noexcept
 
constexpr mountflags_linux jau::fs::operator~ (const mountflags_linux rhs) noexcept
 
constexpr traverse_event jau::fs::operator~ (const traverse_event rhs) noexcept
 
constexpr traverse_options jau::fs::operator~ (const traverse_options rhs) noexcept
 
constexpr umountflags_linux jau::fs::operator~ (const umountflags_linux rhs) noexcept
 
constexpr ::mode_t jau::fs::posix_protection_bits (const fmode_t mask) noexcept
 Returns the POSIX protection bits: rwx_all | set_uid | set_gid | sticky, i.e. More...
 
bool jau::fs::remove (const std::string &path, const traverse_options topts=traverse_options::none) noexcept
 Remove the given path. More...
 
bool jau::fs::rename (const std::string &oldpath, const std::string &newpath) noexcept
 Rename oldpath to newpath using POSIX rename(), with the following combinations. More...
 
void jau::fs::sync () noexcept
 Synchronizes filesystems, i.e. More...
 
std::string jau::fs::to_named_fd (const int fd) noexcept
 Returns platform dependent named file descriptor of given file descriptor, if supported. More...
 
std::string jau::fs::to_string (const copy_options mask) noexcept
 
std::string jau::fs::to_string (const file_stats::field_t mask) noexcept
 
std::string jau::fs::to_string (const fmode_t mask, const bool show_rwx=false) noexcept
 Return the string representation of fmode_t. More...
 
std::string jau::fs::to_string (const traverse_event mask) noexcept
 
std::string jau::fs::to_string (const traverse_options mask) noexcept
 
bool jau::fs::touch (const std::string &path, const fmode_t mode=jau::fs::fmode_t::def_file_prot) noexcept
 Touch the file with current time and create file if not existing yet. More...
 
bool jau::fs::touch (const std::string &path, const jau::fraction_timespec &atime, const jau::fraction_timespec &mtime, const fmode_t mode=jau::fs::fmode_t::def_file_prot) noexcept
 Touch the file with given atime and mtime and create file if not existing yet. More...
 
bool jau::fs::umount (const mount_ctx &context, const umountflags_t flags)
 Detach the given mount_ctx context More...
 
bool jau::fs::umount (const std::string &target, const umountflags_t flags)
 Detach the topmost filesystem mounted on target optionally using given umountflags options if supported. More...
 
bool jau::fs::visit (const file_stats &item_stats, const traverse_options topts, const path_visitor &visitor, std::vector< int > *dirfds=nullptr) noexcept
 Visit element(s) of a given path, see traverse_options for detailed settings. More...
 
bool jau::fs::visit (const std::string &path, const traverse_options topts, const path_visitor &visitor, std::vector< int > *dirfds=nullptr) noexcept
 Visit element(s) of a given path, see traverse_options for detailed settings. More...
 

Detailed Description

File types and functionality.

Typedef Documentation

◆ consume_dir_item

void consume_dir_item(const dir_item& item)

Definition at line 730 of file file_util.hpp.

◆ path_visitor

path_visitor jau::FunctionDef definition

  • bool visitor(traverse_event tevt, const file_stats& item_stats, size_t depth)

Depth being the recursive directory depth starting with 1 for the initial directory.

Returning false stops traversal in general but traverse_options::dir_check_entry will only skip traversing the denied directory.

Definition at line 869 of file file_util.hpp.

◆ mountflags_t

typedef uint64_t jau::fs::mountflags_t

Generic flag bit values for mount() flags.

See mount(2) for a detailed description.

Definition at line 1191 of file file_util.hpp.

◆ umountflags_t

Generic flag bit values for umount() flags.

See umount(2) for a detailed description.

Definition at line 1328 of file file_util.hpp.

Enumeration Type Documentation

◆ fmode_t

enum class jau::fs::fmode_t : uint32_t
strong

Generic file type and POSIX protection mode bits as used in file_stats, touch(), mkdir() etc.

The POSIX protection mode bits reside in the lower 16-bits and are bit-wise POSIX compliant while the file type bits reside in the upper 16-bits and are platform agnostic.

This enum class type fulfills C++ named requirements: BitmaskType.

See also
file_stats
file_stats::mode()
Enumerator
none 

No mode bit set.

set_uid 

Protection bit: POSIX S_ISUID.

set_gid 

Protection bit: POSIX S_ISGID.

sticky 

Protection bit: POSIX S_ISVTX.

ugs_set 

Protection bit: POSIX S_ISUID | S_ISGID | S_ISVTX.

read_usr 

Protection bit: POSIX S_IRUSR.

write_usr 

Protection bit: POSIX S_IWUSR.

exec_usr 

Protection bit: POSIX S_IXUSR.

rwx_usr 

Protection bit: POSIX S_IRWXU.

read_grp 

Protection bit: POSIX S_IRGRP.

write_grp 

Protection bit: POSIX S_IWGRP.

exec_grp 

Protection bit: POSIX S_IXGRP.

rwx_grp 

Protection bit: POSIX S_IRWXG.

read_oth 

Protection bit: POSIX S_IROTH.

write_oth 

Protection bit: POSIX S_IWOTH.

exec_oth 

Protection bit: POSIX S_IXOTH.

rwx_oth 

Protection bit: POSIX S_IRWXO.

rwx_all 

Protection bit: POSIX S_IRWXU | S_IRWXG | S_IRWXO or rwx_usr | rwx_grp | rwx_oth.

def_dir_prot 

Default directory protection bit: Safe default: POSIX S_IRWXU | S_IRGRP | S_IXGRP or rwx_usr | read_grp | exec_grp.

def_file_prot 

Default file protection bit: Safe default: POSIX S_IRUSR | S_IWUSR | S_IRGRP or read_usr | write_usr | read_grp.

protection_mask 

12 bit protection bit mask 07777 for rwx_all | set_uid | set_gid | sticky .

sock 

Type: Entity is a socket, might be in combination with link.

blk 

Type: Entity is a block device, might be in combination with link.

chr 

Type: Entity is a character device, might be in combination with link.

fifo 

Type: Entity is a fifo/pipe, might be in combination with link.

dir 

Type: Entity is a directory, might be in combination with link.

file 

Type: Entity is a file, might be in combination with link.

link 

Type: Entity is a symbolic link, might be in combination with file or dir, fifo, chr, blk or sock.

no_access 

Type: Entity gives no access to user, exclusive bit.

not_existing 

Type: Entity does not exist, exclusive bit.

type_mask 

Type mask for sock | blk | chr | fifo | dir | file | link | no_access | not_existing.

Definition at line 236 of file file_util.hpp.

◆ traverse_event

enum class jau::fs::traverse_event : uint16_t
strong

Filesystem traverse event used to call path_visitor for path elements from visit().

This enum class type fulfills C++ named requirements: BitmaskType.

See also
path_visitor
visit()
Enumerator
none 

No value, neither file, symlink nor dir_entry or dir_exit.

Implying an error state in file_stat, e.g. !file_stats::has_access().

symlink 

Visiting a symbolic-link, either to a file or a non-existing entity.

Not followed symbolic-links to a directory is expressed via dir_symlink.

In case of a symbolic-link to an existing file, file is also set, i.e. file_symlink.

file 

Visiting a file, may be in conjunction with symlink, i.e.

file_symlink.

file_symlink 

Visiting a symlink to a file, i.e.

symlink | file

dir_symlink 

Visiting a symbolic-link to a directory which is not followed, i.e.

traverse_options::follow_symlinks not set.

dir_check_entry 

Visiting a directory on entry, see traverse_options::dir_check_entry.

This allows the path_visitor to deny traversal into the directory by returning false, otherwise continuing traversal.

dir_entry 

Visiting a directory on entry, see traverse_options::dir_entry.

If a directory is visited non-recursive, i.e. traverse_options::recursive not set, dir_entry and dir_exit are set, see dir_non_recursive.

If a directory is a symbolic link which is not followed, i.e. traverse_options::follow_symlinks not set, dir_symlink is used instead.

dir_exit 

Visiting a directory on exit, see traverse_options::dir_exit.

If a directory is visited non-recursive, i.e. traverse_options::recursive not set, dir_entry and dir_exit are set, see dir_non_recursive.

If a directory is a symbolic link which is not followed, i.e. traverse_options::follow_symlinks not set, dir_symlink is used instead.

dir_non_recursive 

Visiting a directory non-recursive, i.e.

traverse_options::recursive not set.

Value is a bit-mask of dir_entry | dir_exit

Definition at line 763 of file file_util.hpp.

◆ traverse_options

enum class jau::fs::traverse_options : uint16_t
strong

Filesystem traverse options used to visit() path elements.

This enum class type fulfills C++ named requirements: BitmaskType.

See also
visit()
remove()
Enumerator
none 

No option set.

recursive 

Traverse through directories, i.e.

perform visit, copy, remove etc actions recursively throughout the directory structure.

follow_symlinks 

Traverse through symbolic linked directories if traverse_options::recursive is set, i.e.

directories with property fmode_t::link set.

lexicographical_order 

Traverse through elements in lexicographical order.

This might be required when computing an order dependent outcome like a hash value.

dir_check_entry 

Call path_visitor at directory entry, allowing path_visitor to skip traversal of this directory if returning false.

dir_entry 

Call path_visitor at directory entry.

Both, dir_entry and dir_exit can be set, only one or none.

dir_exit 

Call path_visitor at directory exit.

Both, dir_entry and dir_exit can be set, only one or none.

verbose 

Enable verbosity mode, potentially used by a path_visitor implementation like remove().

Definition at line 879 of file file_util.hpp.

◆ copy_options

enum class jau::fs::copy_options : uint16_t
strong

Filesystem copy options used to copy() path elements.

By default, the fmode_t POSIX protection mode bits are preserved while using the caller's uid and gid as well as current timestamps.
Use copy_options::preserve_all to preserve uid and gid if allowed from the caller and access- and modification-timestamps.

This enum class type fulfills C++ named requirements: BitmaskType.

See also
copy()
Enumerator
none 

No option set.

recursive 

Traverse through directories, i.e.

perform visit, copy, remove etc actions recursively throughout the directory structure.

follow_symlinks 

Copy referenced symbolic linked files or directories instead of just the symbolic link with property fmode_t::link set.

into_existing_dir 

Copy source dir content into an already existing destination directory as if destination directory did not exist.

Otherwise, if destination directory already exist, the source directory will be copied below the destination directory.

ignore_symlink_errors 

Ignore errors from erroneous symlinks, e.g.

non-existing link-targets, recursive loop-errors.or unsupported symmlinks on target filesystem.

This flag is required to

  • copy erroneous non-existing symlinks if using follow_symlinks
  • copy erroneous recursive loop-error symlinks if using follow_symlinks
  • ignore symlinks if not supported by target filesystem if not using follow_symlinks
overwrite 

Overwrite existing destination files.

preserve_all 

Preserve uid and gid if allowed and access- and modification-timestamps, i.e.

producing a most exact meta-data copy.

sync 

Ensure data and meta-data file synchronization is performed via ::fsync() after asynchronous copy operations of a file's content.

verbose 

Enable verbosity mode, show error messages on stderr.

Definition at line 1035 of file file_util.hpp.

◆ mountflags_linux

Flag bit values for mount() flags under GNU/Linux.

See mount(2) for a detailed description.

Enumerator
none 
rdonly 
nosuid 
nodev 
noexec 
synchronous 
remount 
mandlock 
dirsync 
noatime 
nodiratime 
bind 
move 
rec 
silent 
posixacl 
unbindable 
private_ 
slave 
shared 
relatime 
kernmount 
i_version 
strictatime 
lazytime 
active 
nouser 

Definition at line 1198 of file file_util.hpp.

◆ umountflags_linux

Flag bit values for umount() flags under GNU/Linux.

See umount(2) for a detailed description.

Enumerator
force 
detach 
expire 
nofollow 

Definition at line 1335 of file file_util.hpp.

Function Documentation

◆ get_cwd()

std::string jau::fs::get_cwd ( )
noexcept

Return the current working directory or empty on failure.

Definition at line 82 of file file_util.cpp.

Here is the caller graph for this function:

◆ chdir()

bool jau::fs::chdir ( const std::string &  path)
noexcept

Change working directory.

Definition at line 98 of file file_util.cpp.

Here is the caller graph for this function:

◆ absolute()

std::string jau::fs::absolute ( const std::string_view &  relpath)
noexcept

Returns the absolute path of given relpath if existing, otherwise an empty string.

Parameters
relpatha path, might be relative

Definition at line 102 of file file_util.cpp.

Here is the caller graph for this function:

◆ dirname()

std::string jau::fs::dirname ( const std::string_view &  path)
noexcept

Return stripped last component from given path separated by /, excluding the trailing separator /.

If no directory separator / is contained, return ..

If only the root path / is given, return /.

Parameters
pathgiven path
Returns
leading directory name w/o slash or .

Definition at line 129 of file file_util.cpp.

Here is the caller graph for this function:

◆ basename()

std::string jau::fs::basename ( const std::string_view &  path)
noexcept

Return stripped leading directory components from given path separated by /.

If only the root path / is given, return /.

Parameters
pathgiven path
Returns
last non-slash component or .

Definition at line 151 of file file_util.cpp.

Here is the caller graph for this function:

◆ isAbsolute()

bool jau::fs::isAbsolute ( const std::string_view &  path)
noexcept

Returns true if first character is / or - in case of Windows - \\.

Definition at line 172 of file file_util.cpp.

Here is the caller graph for this function:

◆ number() [1/7]

constexpr uint32_t jau::fs::number ( const fmode_t  rhs)
constexprnoexcept

Definition at line 309 of file file_util.hpp.

Here is the caller graph for this function:

◆ operator~() [1/7]

constexpr fmode_t jau::fs::operator~ ( const fmode_t  rhs)
constexprnoexcept

Definition at line 312 of file file_util.hpp.

◆ operator^() [1/7]

constexpr fmode_t jau::fs::operator^ ( const fmode_t  lhs,
const fmode_t  rhs 
)
constexprnoexcept

Definition at line 315 of file file_util.hpp.

◆ operator|() [1/7]

constexpr fmode_t jau::fs::operator| ( const fmode_t  lhs,
const fmode_t  rhs 
)
constexprnoexcept

Definition at line 318 of file file_util.hpp.

◆ operator&() [1/7]

constexpr fmode_t jau::fs::operator& ( const fmode_t  lhs,
const fmode_t  rhs 
)
constexprnoexcept

Definition at line 321 of file file_util.hpp.

◆ operator|=() [1/9]

constexpr fmode_t & jau::fs::operator|= ( fmode_t lhs,
const fmode_t  rhs 
)
constexprnoexcept

Definition at line 324 of file file_util.hpp.

◆ operator&=() [1/9]

constexpr fmode_t & jau::fs::operator&= ( fmode_t lhs,
const fmode_t  rhs 
)
constexprnoexcept

Definition at line 328 of file file_util.hpp.

◆ operator^=() [1/9]

constexpr fmode_t & jau::fs::operator^= ( fmode_t lhs,
const fmode_t  rhs 
)
constexprnoexcept

Definition at line 332 of file file_util.hpp.

◆ operator==() [1/7]

constexpr bool jau::fs::operator== ( const fmode_t  lhs,
const fmode_t  rhs 
)
constexprnoexcept

Definition at line 336 of file file_util.hpp.

◆ operator!=() [1/7]

constexpr bool jau::fs::operator!= ( const fmode_t  lhs,
const fmode_t  rhs 
)
constexprnoexcept

Definition at line 339 of file file_util.hpp.

◆ is_set() [1/7]

constexpr bool jau::fs::is_set ( const fmode_t  mask,
const fmode_t  bits 
)
constexprnoexcept

Definition at line 342 of file file_util.hpp.

Here is the caller graph for this function:

◆ to_string() [1/5]

std::string jau::fs::to_string ( const fmode_t  mask,
const bool  show_rwx = false 
)
noexcept

Return the string representation of fmode_t.

Parameters
maskthe fmode_t to convert
show_rwxif true, return verbose POSIX protection bit string representation using rwx for user, group and others. Otherwise simply show the octal representation (default)
Returns
the string representation.

Definition at line 368 of file file_util.cpp.

Here is the caller graph for this function:

◆ posix_protection_bits()

constexpr ::mode_t jau::fs::posix_protection_bits ( const fmode_t  mask)
noexcept

Returns the POSIX protection bits: rwx_all | set_uid | set_gid | sticky, i.e.

fmode_t masked with fmode_t::protection_mask.

Definition at line 354 of file file_util.hpp.

Here is the caller graph for this function:

◆ to_named_fd()

std::string jau::fs::to_named_fd ( const int  fd)
noexcept

Returns platform dependent named file descriptor of given file descriptor, if supported.

Implementation returns (d stands for integer):

  • /dev/fd/d (GNU/Linux, FreeBSD, ..)

Following standard POSIX mappings exist

  • fd 0, /dev/fd/0, /dev/stdin
  • fd 1, /dev/fd/1, /dev/stdout
  • fd 2, /dev/fd/2, /dev/stderr
  • fd [0-99], /dev/fd/[0-99]

Currently implementation always returns above pattern, not handling the target OS differences.

Parameters
fdfile descriptor.
Returns
the named file descriptor or an empty string if fd < 0 or not supported by OS.
See also
jau::fs::from_named_fd()
jau::fs::file_stats:has_fd()

Definition at line 401 of file file_util.cpp.

Here is the caller graph for this function:

◆ from_named_fd()

int jau::fs::from_named_fd ( const std::string &  named_fd)
noexcept

Returns the file descriptor from the given named file descriptor.

Detected named file descriptors are (d stands for integer)

  • /dev/fd/d (GNU/Linux, FreeBSD, ..)
  • /proc/self/fd/d (GNU/Linux)
Parameters
named_fdthe named file descriptor
Returns
file descriptor or -1 if invalid or not supported by OS.
See also
jau::fs::to_named_fd()
jau::fs::file_stats:has_fd()

Definition at line 410 of file file_util.cpp.

Here is the caller graph for this function:

◆ number() [2/7]

constexpr uint32_t jau::fs::number ( const file_stats::field_t  rhs)
constexprnoexcept

Definition at line 661 of file file_util.hpp.

◆ operator~() [2/7]

constexpr file_stats::field_t jau::fs::operator~ ( const file_stats::field_t  rhs)
constexprnoexcept

Definition at line 664 of file file_util.hpp.

◆ operator^() [2/7]

constexpr file_stats::field_t jau::fs::operator^ ( const file_stats::field_t  lhs,
const file_stats::field_t  rhs 
)
constexprnoexcept

Definition at line 667 of file file_util.hpp.

◆ operator|() [2/7]

constexpr file_stats::field_t jau::fs::operator| ( const file_stats::field_t  lhs,
const file_stats::field_t  rhs 
)
constexprnoexcept

Definition at line 670 of file file_util.hpp.

◆ operator&() [2/7]

constexpr file_stats::field_t jau::fs::operator& ( const file_stats::field_t  lhs,
const file_stats::field_t  rhs 
)
constexprnoexcept

Definition at line 673 of file file_util.hpp.

◆ operator|=() [2/9]

constexpr file_stats::field_t & jau::fs::operator|= ( file_stats::field_t lhs,
const file_stats::field_t  rhs 
)
constexprnoexcept

Definition at line 676 of file file_util.hpp.

◆ operator&=() [2/9]

constexpr file_stats::field_t & jau::fs::operator&= ( file_stats::field_t lhs,
const file_stats::field_t  rhs 
)
constexprnoexcept

Definition at line 680 of file file_util.hpp.

◆ operator^=() [2/9]

constexpr file_stats::field_t & jau::fs::operator^= ( file_stats::field_t lhs,
const file_stats::field_t  rhs 
)
constexprnoexcept

Definition at line 684 of file file_util.hpp.

◆ operator==() [2/7]

constexpr bool jau::fs::operator== ( const file_stats::field_t  lhs,
const file_stats::field_t  rhs 
)
constexprnoexcept

Definition at line 688 of file file_util.hpp.

◆ operator!=() [2/7]

constexpr bool jau::fs::operator!= ( const file_stats::field_t  lhs,
const file_stats::field_t  rhs 
)
constexprnoexcept

Definition at line 691 of file file_util.hpp.

◆ is_set() [2/7]

constexpr bool jau::fs::is_set ( const file_stats::field_t  mask,
const file_stats::field_t  bits 
)
constexprnoexcept

Definition at line 694 of file file_util.hpp.

◆ to_string() [2/5]

std::string jau::fs::to_string ( const file_stats::field_t  mask)
noexcept

Definition at line 436 of file file_util.cpp.

◆ mkdir()

bool jau::fs::mkdir ( const std::string &  path,
const fmode_t  mode = jau::fs::fmode_t::def_dir_prot,
const bool  verbose = false 
)
noexcept

Create directory.

Parameters
pathfull path to new directory
modefmode_t POSIX protection bits used, defaults to jau::fs::fmode_t::def_dir_prot
verbosedefaults to false
Returns
true if successful, otherwise false

Definition at line 909 of file file_util.cpp.

Here is the caller graph for this function:

◆ touch() [1/2]

bool jau::fs::touch ( const std::string &  path,
const jau::fraction_timespec atime,
const jau::fraction_timespec mtime,
const fmode_t  mode = jau::fs::fmode_t::def_file_prot 
)
noexcept

Touch the file with given atime and mtime and create file if not existing yet.

Parameters
pathfull path to file
atimenew access time
mtimenew modification time
modefmode_t POSIX protection bits used, defaults to jau::fs::fmode_t::def_file_prot
Returns
true if successful, otherwise false

Definition at line 931 of file file_util.cpp.

Here is the caller graph for this function:

◆ touch() [2/2]

bool jau::fs::touch ( const std::string &  path,
const fmode_t  mode = jau::fs::fmode_t::def_file_prot 
)
noexcept

Touch the file with current time and create file if not existing yet.

Parameters
pathfull path to file
modefmode_t POSIX protection bits used, defaults to jau::fs::fmode_t::def_file_prot
Returns
true if successful, otherwise false

Definition at line 949 of file file_util.cpp.

◆ get_dir_content() [1/2]

bool jau::fs::get_dir_content ( const std::string &  path,
const consume_dir_item digest 
)
noexcept

Returns a list of directory elements excluding .

and .. for the given path, non recursive.

The custom consume_dir_item digest may also be used to filter the element, besides storing it.

Parameters
pathpath to directory
digestconsume_dir_item function to receive each directory item, e.g. void consume_dir_item(const dir_item& item)
Returns
true if given path exists, is directory and is readable, otherwise false

Definition at line 966 of file file_util.cpp.

Here is the caller graph for this function:

◆ get_dir_content() [2/2]

bool jau::fs::get_dir_content ( const int  dirfd,
const std::string &  path,
const consume_dir_item digest 
)
noexcept

Returns a list of directory elements excluding .

and .. for the given path, non recursive.

The custom consume_dir_item digest may also be used to filter the element, besides storing it.

Parameters
dirfdfile descriptor to given path left untouched as a copy is being used to retrieve the directory content.
pathpath to directory
digestconsume_dir_item function to receive each directory item, e.g. void consume_dir_item(const dir_item& item)
Returns
true if given path exists, is directory and is readable, otherwise false

Definition at line 984 of file file_util.cpp.

◆ number() [3/7]

constexpr uint16_t jau::fs::number ( const traverse_event  rhs)
constexprnoexcept

Definition at line 822 of file file_util.hpp.

◆ operator~() [3/7]

constexpr traverse_event jau::fs::operator~ ( const traverse_event  rhs)
constexprnoexcept

Definition at line 825 of file file_util.hpp.

◆ operator^() [3/7]

constexpr traverse_event jau::fs::operator^ ( const traverse_event  lhs,
const traverse_event  rhs 
)
constexprnoexcept

Definition at line 828 of file file_util.hpp.

◆ operator|() [3/7]

constexpr traverse_event jau::fs::operator| ( const traverse_event  lhs,
const traverse_event  rhs 
)
constexprnoexcept

Definition at line 831 of file file_util.hpp.

◆ operator&() [3/7]

constexpr traverse_event jau::fs::operator& ( const traverse_event  lhs,
const traverse_event  rhs 
)
constexprnoexcept

Definition at line 834 of file file_util.hpp.

◆ operator|=() [3/9]

constexpr traverse_event & jau::fs::operator|= ( traverse_event lhs,
const traverse_event  rhs 
)
constexprnoexcept

Definition at line 837 of file file_util.hpp.

◆ operator&=() [3/9]

constexpr traverse_event & jau::fs::operator&= ( traverse_event lhs,
const traverse_event  rhs 
)
constexprnoexcept

Definition at line 841 of file file_util.hpp.

◆ operator^=() [3/9]

constexpr traverse_event & jau::fs::operator^= ( traverse_event lhs,
const traverse_event  rhs 
)
constexprnoexcept

Definition at line 845 of file file_util.hpp.

◆ operator==() [3/7]

constexpr bool jau::fs::operator== ( const traverse_event  lhs,
const traverse_event  rhs 
)
constexprnoexcept

Definition at line 849 of file file_util.hpp.

◆ operator!=() [3/7]

constexpr bool jau::fs::operator!= ( const traverse_event  lhs,
const traverse_event  rhs 
)
constexprnoexcept

Definition at line 852 of file file_util.hpp.

◆ is_set() [3/7]

constexpr bool jau::fs::is_set ( const traverse_event  mask,
const traverse_event  bit 
)
constexprnoexcept

Definition at line 855 of file file_util.hpp.

◆ to_string() [3/5]

std::string jau::fs::to_string ( const traverse_event  mask)
noexcept

Definition at line 1014 of file file_util.cpp.

◆ number() [4/7]

constexpr uint16_t jau::fs::number ( const traverse_options  rhs)
constexprnoexcept

Definition at line 904 of file file_util.hpp.

◆ operator~() [4/7]

constexpr traverse_options jau::fs::operator~ ( const traverse_options  rhs)
constexprnoexcept

Definition at line 907 of file file_util.hpp.

◆ operator^() [4/7]

constexpr traverse_options jau::fs::operator^ ( const traverse_options  lhs,
const traverse_options  rhs 
)
constexprnoexcept

Definition at line 910 of file file_util.hpp.

◆ operator|() [4/7]

constexpr traverse_options jau::fs::operator| ( const traverse_options  lhs,
const traverse_options  rhs 
)
constexprnoexcept

Definition at line 913 of file file_util.hpp.

◆ operator&() [4/7]

constexpr traverse_options jau::fs::operator& ( const traverse_options  lhs,
const traverse_options  rhs 
)
constexprnoexcept

Definition at line 916 of file file_util.hpp.

◆ operator|=() [4/9]

constexpr traverse_options & jau::fs::operator|= ( traverse_options lhs,
const traverse_options  rhs 
)
constexprnoexcept

Definition at line 919 of file file_util.hpp.

◆ operator&=() [4/9]

constexpr traverse_options & jau::fs::operator&= ( traverse_options lhs,
const traverse_options  rhs 
)
constexprnoexcept

Definition at line 923 of file file_util.hpp.

◆ operator^=() [4/9]

constexpr traverse_options & jau::fs::operator^= ( traverse_options lhs,
const traverse_options  rhs 
)
constexprnoexcept

Definition at line 927 of file file_util.hpp.

◆ operator==() [4/7]

constexpr bool jau::fs::operator== ( const traverse_options  lhs,
const traverse_options  rhs 
)
constexprnoexcept

Definition at line 931 of file file_util.hpp.

◆ operator!=() [4/7]

constexpr bool jau::fs::operator!= ( const traverse_options  lhs,
const traverse_options  rhs 
)
constexprnoexcept

Definition at line 934 of file file_util.hpp.

◆ is_set() [4/7]

constexpr bool jau::fs::is_set ( const traverse_options  mask,
const traverse_options  bit 
)
constexprnoexcept

Definition at line 937 of file file_util.hpp.

◆ to_string() [4/5]

std::string jau::fs::to_string ( const traverse_options  mask)
noexcept

Definition at line 1031 of file file_util.cpp.

◆ visit() [1/2]

bool jau::fs::visit ( const std::string &  path,
const traverse_options  topts,
const path_visitor visitor,
std::vector< int > *  dirfds = nullptr 
)
noexcept

Visit element(s) of a given path, see traverse_options for detailed settings.

All elements of type fmode_t::file, fmode_t::dir and fmode_t::no_access or fmode_t::not_existing will be visited by the given path_visitor visitor.

Depth passed to path_visitor is the recursive directory depth and starts with 1 for the initial directory.

path_visitor returning false stops traversal in general but traverse_options::dir_check_entry will only skip traversing the denied directory.

Parameters
paththe starting path
toptsgiven traverse_options for this operation
visitorpath_visitor function bool visitor(const file_stats& item_stats, size_t depth).
dirfdsoptional empty dirfd stack pointer defaults to nullptr. If user provided, exposes the used dirfd stack, which last entry represents the currently visited directory. The dirfd stack starts and ends empty, i.e. all directory file descriptor are closed. In case of recursive directory traversion, the initial dir_entry visit starts with depth 1 and 2 fds, its parent and current directory.
Returns
true if successful including no path_visitor stopped traversal by returning false excluding traverse_options::dir_check_entry.

Definition at line 1169 of file file_util.cpp.

Here is the caller graph for this function:

◆ visit() [2/2]

bool jau::fs::visit ( const file_stats item_stats,
const traverse_options  topts,
const path_visitor visitor,
std::vector< int > *  dirfds = nullptr 
)
noexcept

Visit element(s) of a given path, see traverse_options for detailed settings.

All elements of type fmode_t::file, fmode_t::dir and fmode_t::no_access or fmode_t::not_existing will be visited by the given path_visitor visitor.

Depth passed to path_visitor is the recursive directory depth and starts with 1 for the initial directory.

path_visitor returning false stops traversal in general but traverse_options::dir_check_entry will only skip traversing the denied directory.

Parameters
item_statspre-fetched file_stats for a given dir_item, used for efficiency
toptsgiven traverse_options for this operation
visitorpath_visitor function bool visitor(const file_stats& item_stats, size_t depth).
dirfdsoptional empty dirfd stack pointer defaults to nullptr. If user provided, exposes the used dirfd stack, which last entry represents the currently visited directory. The dirfd stack starts and ends empty, i.e. all directory file descriptor are closed. In case of recursive directory traversion, the initial dir_entry visit starts with depth 1 and 2 fds, its parent and current directory.
Returns
true if successful including no path_visitor stopped traversal by returning false excluding traverse_options::dir_check_entry.

Definition at line 1131 of file file_util.cpp.

◆ remove()

bool jau::fs::remove ( const std::string &  path,
const traverse_options  topts = traverse_options::none 
)
noexcept

Remove the given path.

If path represents a director, recursive must be set to true.

The given traverse_options options are handled as follows:

  • traverse_options::parent_dir_last will be added by implementation to operate correct
  • traverse_options::recursive shall shall be set by caller to remove directories
  • traverse_options::follow_symlinks shall be set by caller to remove symbolic linked directories recursively, which is kind of dangerous. If not set, only the symbolic link will be removed (default)

Implementation is most data-race-free (DRF), utilizes following safeguards

  • utilizing parent directory file descriptor and openat() and unlinkat() operations against concurrent mutation
Parameters
pathpath to remove
toptsgiven traverse_options for this operation, defaults to traverse_options::none
Returns
true only if the file or the directory with content has been deleted, otherwise false

Definition at line 1173 of file file_util.cpp.

Here is the caller graph for this function:

◆ compare() [1/2]

bool jau::fs::compare ( const file_stats source1,
const file_stats source2,
const bool  verbose = false 
)
noexcept

Compare the bytes of both files, denoted by source1 and source2.

Parameters
source1first source file to compare
source2second source file to compare
verbosedefaults to false
Returns
true if both elements are files and their bytes are equal, otherwise false.
Examples
test_basictypeconv.cpp.

Definition at line 1268 of file file_util.cpp.

Here is the caller graph for this function:

◆ compare() [2/2]

bool jau::fs::compare ( const std::string &  source1,
const std::string &  source2,
const bool  verbose = false 
)
noexcept

Compare the bytes of both files, denoted by source1 and source2.

Parameters
source1first source file to compare
source2second source file to compare
verbosedefaults to false
Returns
true if both elements are files and their bytes are equal, otherwise false.

Definition at line 1262 of file file_util.cpp.

◆ number() [5/7]

constexpr uint16_t jau::fs::number ( const copy_options  rhs)
constexprnoexcept

Definition at line 1074 of file file_util.hpp.

◆ operator~() [5/7]

constexpr copy_options jau::fs::operator~ ( const copy_options  rhs)
constexprnoexcept

Definition at line 1077 of file file_util.hpp.

◆ operator^() [5/7]

constexpr copy_options jau::fs::operator^ ( const copy_options  lhs,
const copy_options  rhs 
)
constexprnoexcept

Definition at line 1080 of file file_util.hpp.

◆ operator|() [5/7]

constexpr copy_options jau::fs::operator| ( const copy_options  lhs,
const copy_options  rhs 
)
constexprnoexcept

Definition at line 1083 of file file_util.hpp.

◆ operator&() [5/7]

constexpr copy_options jau::fs::operator& ( const copy_options  lhs,
const copy_options  rhs 
)
constexprnoexcept

Definition at line 1086 of file file_util.hpp.

◆ operator|=() [5/9]

constexpr copy_options & jau::fs::operator|= ( copy_options lhs,
const copy_options  rhs 
)
constexprnoexcept

Definition at line 1089 of file file_util.hpp.

◆ operator&=() [5/9]

constexpr copy_options & jau::fs::operator&= ( copy_options lhs,
const copy_options  rhs 
)
constexprnoexcept

Definition at line 1093 of file file_util.hpp.

◆ operator^=() [5/9]

constexpr copy_options & jau::fs::operator^= ( copy_options lhs,
const copy_options  rhs 
)
constexprnoexcept

Definition at line 1097 of file file_util.hpp.

◆ operator==() [5/7]

constexpr bool jau::fs::operator== ( const copy_options  lhs,
const copy_options  rhs 
)
constexprnoexcept

Definition at line 1101 of file file_util.hpp.

◆ operator!=() [5/7]

constexpr bool jau::fs::operator!= ( const copy_options  lhs,
const copy_options  rhs 
)
constexprnoexcept

Definition at line 1104 of file file_util.hpp.

◆ is_set() [5/7]

constexpr bool jau::fs::is_set ( const copy_options  mask,
const copy_options  bit 
)
constexprnoexcept

Definition at line 1107 of file file_util.hpp.

◆ to_string() [5/5]

std::string jau::fs::to_string ( const copy_options  mask)
noexcept

Definition at line 1375 of file file_util.cpp.

◆ copy()

bool jau::fs::copy ( const std::string &  source_path,
const std::string &  dest_path,
const copy_options  copts = copy_options::none 
)
noexcept

Copy the given source_path to dest_path using copy_options.

The behavior is similar like POSIX cp commandline tooling.

The following behavior is being followed regarding dest_path:

  • If source_path is a directory and copy_options::recursive set
    • If dest_path doesn't exist, source_path dir content is copied into the newly created dest_path.
    • If dest_path exists as a directory, source_path dir will be copied below the dest_path directory if copy_options::into_existing_dir is not set. Otherwise its content is copied into the existing dest_path.
    • Everything else is considered an error
  • If source_path is a file
    • If dest_path doesn't exist, source_path file is copied to dest_path as a file.
    • If dest_path exists as a directory, source_path file will be copied below the dest_path directory.
    • If dest_path exists as a file, copy_options::overwrite must be set to have it overwritten by the source_path file
    • Everything else is considered an error

Implementation either uses ::sendfile() if running under GNU/Linux, otherwise POSIX ::read() and ::write().

Implementation is most data-race-free (DRF), utilizes following safeguards on recursive directory copy

  • utilizing parent directory file descriptor and openat() operations against concurrent mutation
  • for each entered directory
    • new destination directory is create with '.<random_number>' and user-rwx permissions only
    • its file descriptor is being opened
    • its user-read permission is dropped, remains user-wx permissions only
    • its renamed to destination path
    • all copy operations are performed inside
    • at exit, its permissions are restored, etc.

See copy_options for details.

Parameters
source_path
dest_path
copts
Returns
true if successful, otherwise false

Definition at line 1720 of file file_util.cpp.

Here is the caller graph for this function:

◆ rename()

bool jau::fs::rename ( const std::string &  oldpath,
const std::string &  newpath 
)
noexcept

Rename oldpath to newpath using POSIX rename(), with the following combinations.

  • oldpath and newpath refer to the same file, a successful no-operation.
  • oldpath file
    • newpath not-existing file
    • newpath existing file to be atomically replaced
  • oldpath directory
    • newpath not-existing directory
    • newpath existing empty directory
  • oldpath symlink will be renamed
  • newpath symlink will be overwritten
Parameters
oldpathprevious path
newpathnew path
Returns
true only if the rename operation was successful, otherwise false

Definition at line 1916 of file file_util.cpp.

Here is the caller graph for this function:

◆ sync()

void jau::fs::sync ( )
noexcept

Synchronizes filesystems, i.e.

all pending modifications to filesystem metadata and cached file data will be written to the underlying filesystems.

Definition at line 1932 of file file_util.cpp.

Here is the caller graph for this function:

◆ number() [6/7]

constexpr mountflags_t jau::fs::number ( const mountflags_linux  rhs)
constexprnoexcept

Definition at line 1227 of file file_util.hpp.

◆ operator~() [6/7]

constexpr mountflags_linux jau::fs::operator~ ( const mountflags_linux  rhs)
constexprnoexcept

Definition at line 1230 of file file_util.hpp.

◆ operator^() [6/7]

constexpr mountflags_linux jau::fs::operator^ ( const mountflags_linux  lhs,
const mountflags_linux  rhs 
)
constexprnoexcept

Definition at line 1233 of file file_util.hpp.

◆ operator|() [6/7]

constexpr mountflags_linux jau::fs::operator| ( const mountflags_linux  lhs,
const mountflags_linux  rhs 
)
constexprnoexcept

Definition at line 1236 of file file_util.hpp.

◆ operator&() [6/7]

constexpr mountflags_linux jau::fs::operator& ( const mountflags_linux  lhs,
const mountflags_linux  rhs 
)
constexprnoexcept

Definition at line 1239 of file file_util.hpp.

◆ operator|=() [6/9]

constexpr mountflags_linux & jau::fs::operator|= ( mountflags_linux lhs,
const mountflags_linux  rhs 
)
constexprnoexcept

Definition at line 1242 of file file_util.hpp.

◆ operator&=() [6/9]

constexpr mountflags_linux & jau::fs::operator&= ( mountflags_linux lhs,
const mountflags_linux  rhs 
)
constexprnoexcept

Definition at line 1246 of file file_util.hpp.

◆ operator^=() [6/9]

constexpr mountflags_linux & jau::fs::operator^= ( mountflags_linux lhs,
const mountflags_linux  rhs 
)
constexprnoexcept

Definition at line 1250 of file file_util.hpp.

◆ operator==() [6/7]

constexpr bool jau::fs::operator== ( const mountflags_linux  lhs,
const mountflags_linux  rhs 
)
constexprnoexcept

Definition at line 1254 of file file_util.hpp.

◆ operator!=() [6/7]

constexpr bool jau::fs::operator!= ( const mountflags_linux  lhs,
const mountflags_linux  rhs 
)
constexprnoexcept

Definition at line 1257 of file file_util.hpp.

◆ is_set() [6/7]

constexpr bool jau::fs::is_set ( const mountflags_linux  mask,
const mountflags_linux  bit 
)
constexprnoexcept

Definition at line 1260 of file file_util.hpp.

◆ operator|=() [7/9]

constexpr mountflags_t & jau::fs::operator|= ( mountflags_t lhs,
const mountflags_linux  rhs 
)
constexprnoexcept

Definition at line 1263 of file file_util.hpp.

◆ operator&=() [7/9]

constexpr mountflags_t & jau::fs::operator&= ( mountflags_t lhs,
const mountflags_linux  rhs 
)
constexprnoexcept

Definition at line 1267 of file file_util.hpp.

◆ operator^=() [7/9]

constexpr mountflags_t & jau::fs::operator^= ( mountflags_t lhs,
const mountflags_linux  rhs 
)
constexprnoexcept

Definition at line 1271 of file file_util.hpp.

◆ mount_image()

jau::fs::mount_ctx jau::fs::mount_image ( const std::string &  image_path,
const std::string &  target,
const std::string &  fs_type,
const mountflags_t  flags,
const std::string &  fs_options = "" 
)

Attach the filesystem image named in image_path to target using an intermediate platform specific filesystem image loop-device.

This method either requires root permissions
or the following capabilities: cap_sys_admin,cap_setuid, cap_setgid.

Unmounting shall be done via umount() with mount_ctx argument to ensure all intermediate resources are released.

Parameters
image_pathpath of image source file
targetdirectory where image_path filesystem shall be attached to
fs_typetype of filesystem, e.g. squashfs, tmpfs, iso9660, etc.
flagsfilesystem agnostic mount flags, see mountflags_linux.
fs_optionscomma separated options for the filesystem fs_type, see mount(8) for available options for the used filesystem.
Returns
mount_ctx structure containing mounted status etc
See also
mountflags_t
mountflags_linux
mount()
umount()

Definition at line 1944 of file file_util.cpp.

Here is the caller graph for this function:

◆ mount()

mount_ctx jau::fs::mount ( const std::string &  source,
const std::string &  target,
const std::string &  fs_type,
const mountflags_t  flags,
const std::string &  fs_options = "" 
)

Attach the filesystem named in source to target using the given filesystem source directly.

This method either requires root permissions
or the following capabilities: cap_sys_admin,cap_setuid, cap_setgid.

Parameters
sourcefilesystem path for device, directory, file or dummy-string which shall be attached
targetdirectory where source filesystem shall be attached to
fs_typetype of filesystem, e.g. squashfs, tmpfs, iso9660, etc.
flagsfilesystem agnostic mount flags, see mountflags_linux.
fs_optionscomma separated options for the filesystem fs_type, see mount(8) for available options for the used filesystem.
Returns
mount_ctx structure containing mounted status etc
See also
mountflags_t
mountflags_linux
mount_image()
umount()

Definition at line 2071 of file file_util.cpp.

Here is the caller graph for this function:

◆ number() [7/7]

constexpr umountflags_t jau::fs::number ( const umountflags_linux  rhs)
constexprnoexcept

Definition at line 1341 of file file_util.hpp.

◆ operator~() [7/7]

constexpr umountflags_linux jau::fs::operator~ ( const umountflags_linux  rhs)
constexprnoexcept

Definition at line 1344 of file file_util.hpp.

◆ operator^() [7/7]

constexpr umountflags_linux jau::fs::operator^ ( const umountflags_linux  lhs,
const umountflags_linux  rhs 
)
constexprnoexcept

Definition at line 1347 of file file_util.hpp.

◆ operator|() [7/7]

constexpr umountflags_linux jau::fs::operator| ( const umountflags_linux  lhs,
const umountflags_linux  rhs 
)
constexprnoexcept

Definition at line 1350 of file file_util.hpp.

◆ operator&() [7/7]

constexpr umountflags_linux jau::fs::operator& ( const umountflags_linux  lhs,
const umountflags_linux  rhs 
)
constexprnoexcept

Definition at line 1353 of file file_util.hpp.

◆ operator|=() [8/9]

constexpr umountflags_linux & jau::fs::operator|= ( umountflags_linux lhs,
const umountflags_linux  rhs 
)
constexprnoexcept

Definition at line 1356 of file file_util.hpp.

◆ operator&=() [8/9]

constexpr umountflags_linux & jau::fs::operator&= ( umountflags_linux lhs,
const umountflags_linux  rhs 
)
constexprnoexcept

Definition at line 1360 of file file_util.hpp.

◆ operator^=() [8/9]

constexpr umountflags_linux & jau::fs::operator^= ( umountflags_linux lhs,
const umountflags_linux  rhs 
)
constexprnoexcept

Definition at line 1364 of file file_util.hpp.

◆ operator==() [7/7]

constexpr bool jau::fs::operator== ( const umountflags_linux  lhs,
const umountflags_linux  rhs 
)
constexprnoexcept

Definition at line 1368 of file file_util.hpp.

◆ operator!=() [7/7]

constexpr bool jau::fs::operator!= ( const umountflags_linux  lhs,
const umountflags_linux  rhs 
)
constexprnoexcept

Definition at line 1371 of file file_util.hpp.

◆ is_set() [7/7]

constexpr bool jau::fs::is_set ( const umountflags_linux  mask,
const umountflags_linux  bit 
)
constexprnoexcept

Definition at line 1374 of file file_util.hpp.

◆ operator|=() [9/9]

constexpr umountflags_t & jau::fs::operator|= ( umountflags_t lhs,
const umountflags_linux  rhs 
)
constexprnoexcept

Definition at line 1377 of file file_util.hpp.

◆ operator&=() [9/9]

constexpr umountflags_t & jau::fs::operator&= ( umountflags_t lhs,
const umountflags_linux  rhs 
)
constexprnoexcept

Definition at line 1381 of file file_util.hpp.

◆ operator^=() [9/9]

constexpr umountflags_t & jau::fs::operator^= ( umountflags_t lhs,
const umountflags_linux  rhs 
)
constexprnoexcept

Definition at line 1385 of file file_util.hpp.

◆ umount() [1/2]

bool jau::fs::umount ( const mount_ctx context,
const umountflags_t  flags 
)

Detach the given mount_ctx context

This method either requires root permissions
or the following capabilities: cap_sys_admin,cap_setuid, cap_setgid.

Parameters
contextmount_ctx previously attached via mount_image() or mount()
flagsoptional umount options, if supported by the system. See umount_options_linux.
Returns
true if successful, otherwise false
See also
umountflags_t
umountflags_linux
mount()
mount_image()

Definition at line 2147 of file file_util.cpp.

Here is the caller graph for this function:

◆ umount() [2/2]

bool jau::fs::umount ( const std::string &  target,
const umountflags_t  flags 
)

Detach the topmost filesystem mounted on target optionally using given umountflags options if supported.

This method either requires root permissions
or the following capabilities: cap_sys_admin,cap_setuid, cap_setgid.

Parameters
targetdirectory of previously attached filesystem
flagsoptional umount options, if supported by the system. See umount_options_linux.
Returns
true if successful, otherwise false
See also
umountflags_t
umountflags_linux
mount()
mount_image()

Definition at line 2233 of file file_util.cpp.