jaulib v1.3.6
Jau Support Library (C++, Java, ..)
Loading...
Searching...
No Matches
file_util.hpp File Reference
#include <sys/mount.h>
#include <jau/fraction_type.hpp>
#include <jau/functional.hpp>
#include <jau/enum_util.hpp>
#include <memory>
#include <string>
#include <sys/types.h>
Include dependency graph for file_util.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

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
 

Namespaces

namespace  jau
 __pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.
 
namespace  jau::fs
 Author: Sven Gothel sgoth.nosp@m.el@j.nosp@m.ausof.nosp@m.t.co.nosp@m.m Copyright (c) 2022 Gothel Software e.K.
 

Typedefs

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

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 = 1U << 0 , jau::fs::traverse_options::follow_symlinks = 1U << 1 , jau::fs::traverse_options::lexicographical_order = 1U << 2 ,
  jau::fs::traverse_options::dir_check_entry = 1U << 7 , jau::fs::traverse_options::dir_entry = 1U << 8 , jau::fs::traverse_options::dir_exit = 1U << 9 , jau::fs::traverse_options::verbose = 1U << 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.
 
std::string jau::fs::basename (const std::string_view &path) noexcept
 Return stripped leading directory components from given path separated by /.
 
bool jau::fs::chdir (const std::string &path) noexcept
 Change working directory.
 
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.
 
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.
 
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.
 
std::string jau::fs::dirname (const std::string_view &path) noexcept
 Return stripped last component from given path separated by /, excluding the trailing separator /.
 
bool jau::fs::exists (const std::string &path, bool verbose_on_error=false) noexcept
 Returns true if path exists and is accessible.
 
int jau::fs::from_named_fd (const std::string &named_fd) noexcept
 Returns the file descriptor from the given named file descriptor.
 
std::string jau::fs::get_cwd () noexcept
 Return the current working directory or empty on failure.
 
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 .
 
bool jau::fs::get_dir_content (const std::string &path, const consume_dir_item &digest) noexcept
 Returns a list of directory elements excluding .
 
bool jau::fs::isAbsolute (const std::string_view &path) noexcept
 Returns true if first character is / or - in case of Windows - \\.
 
 jau::fs::JAU_MAKE_BITFIELD_ENUM_STRING (copy_options, recursive, follow_symlinks, into_existing_dir, ignore_symlink_errors, overwrite, preserve_all, sync)
 
 jau::fs::JAU_MAKE_BITFIELD_ENUM_STRING (fmode_t, sock, blk, chr, fifo, dir, file, link, no_access, not_existing)
 
 jau::fs::JAU_MAKE_BITFIELD_ENUM_STRING (mountflags_linux, 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)
 
 jau::fs::JAU_MAKE_BITFIELD_ENUM_STRING (traverse_event, symlink, file, dir_check_entry, dir_entry, dir_exit, dir_symlink)
 
 jau::fs::JAU_MAKE_BITFIELD_ENUM_STRING (traverse_options, recursive, follow_symlinks, lexicographical_order, dir_check_entry, dir_entry, dir_exit)
 
 jau::fs::JAU_MAKE_BITFIELD_ENUM_STRING (umountflags_linux, force, detach, expire, nofollow)
 
 jau::fs::JAU_MAKE_BITFIELD_ENUM_STRING2 (file_stats::field_t, field_t, type, mode, nlink, uid, gid, atime, mtime, ctime, ino, size, blocks, btime)
 
std::string jau::fs::lookup_asset_dir (const char *exe_path, const char *asset_file, const char *asset_install_subdir) noexcept
 Returns located asset directory if found, otherwise an empty string.
 
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.
 
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.
 
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.
 
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.
 
bool jau::fs::remove (const std::string &path, const traverse_options topts=traverse_options::none) noexcept
 Remove the given path.
 
bool jau::fs::rename (const std::string &oldpath, const std::string &newpath) noexcept
 Rename oldpath to newpath using POSIX rename(), with the following combinations.
 
void jau::fs::sync () noexcept
 Synchronizes filesystems, i.e.
 
std::string jau::fs::to_named_fd (const int fd) noexcept
 Returns platform dependent named file descriptor of given file descriptor, if supported.
 
std::string jau::fs::to_string (const fmode_t mask, const bool show_rwx) noexcept
 Return the string representation of fmode_t.
 
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.
 
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.
 
bool jau::fs::umount (const mount_ctx &context, const umountflags_t flags)
 Detach the given mount_ctx context
 
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.
 
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.
 
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.