libzypp
17.32.4
|
Types and functions for filesystem operations. More...
Classes | |
class | DevInoCache |
Simple cache remembering device/inode to detect hardlinks. More... | |
struct | DirEntry |
Listentry returned by readdir. More... | |
class | Glob |
Find pathnames matching a pattern. More... | |
class | PathInfo |
Wrapper class for ::stat/::lstat. More... | |
class | Pathname |
Pathname. More... | |
class | StatMode |
Wrapper class for mode_t values as derived from ::stat. More... | |
class | TmpDir |
Provide a new empty temporary directory and recursively delete it when no longer needed. More... | |
class | TmpFile |
Provide a new empty temporary file and delete it when no longer needed. More... | |
class | TmpPath |
Automaticaly deletes files or directories when no longer needed. More... | |
Enumerations | |
enum | FileType { FT_NOT_AVAIL = 0x00, FT_NOT_EXIST = 0x01, FT_FILE = 0x02, FT_DIR = 0x04, FT_CHARDEV = 0x08, FT_BLOCKDEV = 0x10, FT_FIFO = 0x20, FT_LINK = 0x40, FT_SOCKET = 0x80 } |
File type information. More... | |
Functions | |
std::ostream & | operator<< (std::ostream &str, const Glob &obj) |
ZYPP_DECLARE_OPERATORS_FOR_FLAGS (Glob::Flags) | |
const StrMatcher & | matchNoDots () |
Convenience returning StrMatcher( "[^.]*", Match::GLOB ) More... | |
int | dirForEach (const Pathname &dir_r, const StrMatcher &matcher_r, function< bool(const Pathname &, const char *const)> fnc_r) |
std::ostream & | operator<< (std::ostream &str, FileType obj) |
std::ostream & | operator<< (std::ostream &str, const StatMode &obj) |
std::ostream & | operator<< (std::ostream &str, const PathInfo &obj) |
static int | recursive_rmdir_1 (const Pathname &dir, bool removeDir=true) |
template<typename F > | |
int | dirForEachImpl (const Pathname &dir_r, F &&fnc_r) |
std::string | checksum (const Pathname &file, const std::string &algorithm) |
Compute a files checksum. More... | |
bool | is_checksum (const Pathname &file, const CheckSum &checksum) |
check files checksum More... | |
std::ostream & | operator<< (std::ostream &str, const TmpPath &obj) |
Stream output as pathname. More... | |
File related functions. | |
int | unlink (const Pathname &path) |
Like 'unlink'. More... | |
int | rename (const Pathname &oldpath, const Pathname &newpath) |
Like 'rename'. More... | |
int | exchange (const Pathname &lpath, const Pathname &rpath) |
Exchanges two files or directories. More... | |
int | copy (const Pathname &file, const Pathname &dest) |
Like 'cp file dest'. More... | |
int | symlink (const Pathname &oldpath, const Pathname &newpath) |
Like 'symlink'. More... | |
int | hardlink (const Pathname &oldpath, const Pathname &newpath) |
Like '::link'. More... | |
int | hardlinkCopy (const Pathname &oldpath, const Pathname &newpath) |
Create newpath as hardlink or copy of oldpath. More... | |
int | readlink (const Pathname &symlink_r, Pathname &target_r) |
Like 'readlink'. More... | |
Pathname | expandlink (const Pathname &path_r) |
Recursively follows the symlink pointed to by path_r and returns the Pathname to the real file or directory pointed to by the link. More... | |
int | copy_file2dir (const Pathname &file, const Pathname &dest) |
Like 'cp file dest'. More... | |
int | assert_file (const Pathname &path, unsigned mode=0644) |
Create an empty file if it does not yet exist. More... | |
int | assert_file_mode (const Pathname &path, unsigned mode=0644) |
Like assert_file but enforce mode even if the file already exists. More... | |
int | touch (const Pathname &path) |
Change file's modification and access times. More... | |
Pathname | readlink (const Pathname &symlink_r) |
Digest computaion. | |
| |
std::string | md5sum (const Pathname &file) |
Compute a files md5sum. More... | |
std::string | sha1sum (const Pathname &file) |
Compute a files sha1sum. More... | |
Changing permissions. | |
int | chmod (const Pathname &path, mode_t mode) |
Like 'chmod'. More... | |
int | chmodApplyUmask (const Pathname &path, mode_t mode) |
Similar to 'chmod', but mode is modified by the process's umask in the usual way. More... | |
int | addmod (const Pathname &path, mode_t mode) |
Add the mode bits to the file given by path. More... | |
int | delmod (const Pathname &path, mode_t mode) |
Remove the mode bits from the file given by path. More... | |
Variables | |
template<class... T> | |
constexpr bool | always_false = false |
Directory related functions. | |
using | DirContent = std::list< DirEntry > |
Returned by readdir. More... | |
int | mkdir (const Pathname &path, unsigned mode=0755) |
Like 'mkdir'. More... | |
int | assert_dir (const Pathname &path, unsigned mode=0755) |
Like 'mkdir -p'. More... | |
int | rmdir (const Pathname &path) |
Like 'rmdir'. More... | |
int | recursive_rmdir (const Pathname &path) |
Like 'rm -r DIR'. More... | |
int | clean_dir (const Pathname &path) |
Like 'rm -r DIR/ *'. More... | |
int | copy_dir (const Pathname &srcpath, const Pathname &destpath) |
Like 'cp -a srcpath destpath'. More... | |
int | copy_dir_content (const Pathname &srcpath, const Pathname &destpath) |
Like 'cp -a srcpath/. More... | |
int | dirForEach (const Pathname &dir_r, const function< bool(const Pathname &, const char *const)> &fnc_r) |
Invoke callback function fnc_r for each entry in directory dir_r. More... | |
int | dirForEachExt (const Pathname &dir_r, const function< bool(const Pathname &, const DirEntry &)> &fnc_r) |
Simiar to. More... | |
int | readdir (std::list< std::string > &retlist, const Pathname &path, bool dots=true) |
Return content of directory via retlist. More... | |
int | readdir (std::list< Pathname > &retlist, const Pathname &path, bool dots=true) |
Return content of directory via retlist. More... | |
int | readdir (DirContent &retlist, const Pathname &path, bool dots=true, PathInfo::Mode statmode=PathInfo::STAT) |
Return content of directory via retlist. More... | |
std::ostream & | operator<< (std::ostream &str, const DirContent &obj) |
int | is_empty_dir (const Pathname &path) |
Check if the specified directory is empty. More... | |
std::ostream & | operator<< (std::ostream &str, const DirEntry &obj) |
Misc. | |
enum | ZIP_TYPE { ZT_NONE, ZT_GZ, ZT_BZ2, ZT_ZCHNK } |
Test whether a file is compressed (gzip/bzip2). More... | |
int | erase (const Pathname &path) |
Erase whatever happens to be located at path (file or directory). More... | |
ZIP_TYPE | zipType (const Pathname &file) |
ByteCount | df (const Pathname &path) |
Report free disk space on a mounted file system. More... | |
mode_t | getUmask () |
Get the current umask (file mode creation mask) More... | |
mode_t | applyUmaskTo (mode_t mode_r) |
Modify mode_r according to the current umask ( mode_r & ~getUmask() ) . More... | |
Types and functions for filesystem operations.
move zypp::filesystem stuff into separate header
Add tmpfile and tmpdir handling.
think about using Exceptions in zypp::filesystem
provide a readdir iterator; at least provide an interface using an insert_iterator to be independent from std::container.
move zypp::filesystem stuff into separate header
Add tmpfile and tmpdir handling.
think about using Exceptions in zypp::filesystem
provide a readdir iterator; at least provide an interface using an insert_iterator to be independent from std::container.
using zypp::filesystem::DirContent = typedef std::list<DirEntry> |
Returned by readdir.
Definition at line 519 of file PathInfo.h.
File type information.
Enumerator | |
---|---|
FT_NOT_AVAIL | |
FT_NOT_EXIST | |
FT_FILE | |
FT_DIR | |
FT_CHARDEV | |
FT_BLOCKDEV | |
FT_FIFO | |
FT_LINK | |
FT_SOCKET |
Definition at line 56 of file PathInfo.h.
Test whether a file is compressed (gzip/bzip2).
Enumerator | |
---|---|
ZT_NONE | |
ZT_GZ | |
ZT_BZ2 | |
ZT_ZCHNK |
Definition at line 763 of file PathInfo.h.
|
related |
zypp::filesystem::ZYPP_DECLARE_OPERATORS_FOR_FLAGS | ( | Glob::Flags | ) |
const StrMatcher & zypp::filesystem::matchNoDots | ( | ) |
Convenience returning StrMatcher( "[^.]*", Match::GLOB )
Definition at line 26 of file PathInfo.cc.
int zypp::filesystem::dirForEach | ( | const Pathname & | dir_r, |
const StrMatcher & | matcher_r, | ||
function< bool(const Pathname &, const char *const)> | fnc_r | ||
) |
Definition at line 32 of file PathInfo.cc.
std::ostream& zypp::filesystem::operator<< | ( | std::ostream & | str, |
FileType | obj | ||
) |
Definition at line 48 of file PathInfo.cc.
|
related |
Definition at line 96 of file PathInfo.cc.
|
related |
Definition at line 262 of file PathInfo.cc.
int zypp::filesystem::mkdir | ( | const Pathname & | path, |
unsigned | mode = 0755 |
||
) |
Like 'mkdir'.
Attempt to create a new directory named path. mode specifies the permissions to use. It is modified by the process's umask in the usual way.
Definition at line 306 of file PathInfo.cc.
int zypp::filesystem::assert_dir | ( | const Pathname & | path, |
unsigned | mode = 0755 |
||
) |
Like 'mkdir -p'.
No error if directory exists. Make parent directories as needed. mode specifies the permissions to use, if directories have to be created. It is modified by the process's umask in the usual way.
Definition at line 320 of file PathInfo.cc.
int zypp::filesystem::rmdir | ( | const Pathname & | path | ) |
Like 'rmdir'.
Delete a directory, which must be empty.
Definition at line 367 of file PathInfo.cc.
|
static |
Definition at line 381 of file PathInfo.cc.
int zypp::filesystem::recursive_rmdir | ( | const Pathname & | path | ) |
Like 'rm -r DIR'.
Delete a directory, recursively removing its contents.
Definition at line 413 of file PathInfo.cc.
int zypp::filesystem::clean_dir | ( | const Pathname & | path | ) |
Like 'rm -r DIR/ *'.
Delete directory contents, but keep the directory itself.
Definition at line 443 of file PathInfo.cc.
Like 'cp -a srcpath destpath'.
Copy directory tree. srcpath/destpath must be directories. 'basename srcpath' must not exist in destpath.
Definition at line 464 of file PathInfo.cc.
Like 'cp -a srcpath/.
destpath'. Copy the content of srcpath recursively into destpath. Both srcpath
and destpath
has to exists.
Definition at line 505 of file PathInfo.cc.
int zypp::filesystem::dirForEachImpl | ( | const Pathname & | dir_r, |
F && | fnc_r | ||
) |
Definition at line 548 of file PathInfo.cc.
int zypp::filesystem::dirForEach | ( | const Pathname & | dir_r, |
const function< bool(const Pathname &, const char *const)> & | fnc_r | ||
) |
Invoke callback function fnc_r for each entry in directory dir_r.
If fnc_r is a NULL
function 0
is returned immediately without even testing or accessing dir_r.
Otherwise readdir
is used to read the name of every entry in dir_r, omitting '
.' and '
..'. dir_r and the current entries name are passed as arguments to fnc_r. If fnc_r returns false
processing is aborted.
Definition at line 585 of file PathInfo.cc.
int zypp::filesystem::dirForEachExt | ( | const Pathname & | dir_r, |
const function< bool(const Pathname &, const DirEntry &)> & | fnc_r | ||
) |
Simiar to.
Definition at line 594 of file PathInfo.cc.
int zypp::filesystem::readdir | ( | std::list< std::string > & | retlist, |
const Pathname & | path, | ||
bool | dots = true |
||
) |
Return content of directory via retlist.
If dots is false entries starting with '.' are not reported. "." and ".." are never reported.
Returns just the directory entries as string.
Definition at line 606 of file PathInfo.cc.
int zypp::filesystem::readdir | ( | std::list< Pathname > & | retlist, |
const Pathname & | path, | ||
bool | dots = true |
||
) |
Return content of directory via retlist.
If dots is false entries starting with '.' are not reported. "." and ".." are never reported.
Returns the directory entries prefixed with path.
Definition at line 619 of file PathInfo.cc.
int zypp::filesystem::readdir | ( | DirContent & | retlist, |
const Pathname & | path, | ||
bool | dots = true , |
||
PathInfo::Mode | statmode = PathInfo::STAT |
||
) |
Return content of directory via retlist.
If dots is false entries starting with '.' are not reported. "." and ".." are never reported.
The type of individual directory entries is determined accoding to statmode (i.e. via stat or lstat).
Definition at line 670 of file PathInfo.cc.
std::ostream & zypp::filesystem::operator<< | ( | std::ostream & | str, |
const DirContent & | obj | ||
) |
Definition at line 682 of file PathInfo.cc.
int zypp::filesystem::is_empty_dir | ( | const Pathname & | path | ) |
Check if the specified directory is empty.
path | The path of the directory to check. |
Definition at line 689 of file PathInfo.cc.
int zypp::filesystem::unlink | ( | const Pathname & | path | ) |
Like 'unlink'.
Delete a file (symbolic link, socket, fifo or device).
Definition at line 701 of file PathInfo.cc.
Like 'rename'.
Renames a file, moving it between directories if required. It falls back to using mv(1) in case errno is set to EXDEV, indicating a cross-device rename, which is likely to happen when oldpath and newpath are not on the same OverlayFS layer.
Definition at line 743 of file PathInfo.cc.
Exchanges two files or directories.
Most common use is when building a new config file (or dir) in a tempfile. After the job is done, configfile and tempfile are exchanged. This includes moving away the configfile in case the tempfile does not exist. Parent directories are created as needed.
rename
, so take care both paths are located on the same filesystem.Definition at line 757 of file PathInfo.cc.
Like 'cp file dest'.
Copy file to destination file.
Definition at line 821 of file PathInfo.cc.
Like 'symlink'.
Creates a symbolic link named newpath which contains the string oldpath. If newpath exists it will not be overwritten.
Definition at line 856 of file PathInfo.cc.
Like '::link'.
Creates a hard link named newpath to an existing file oldpath. If newpath exists it will not be overwritten.
Definition at line 870 of file PathInfo.cc.
Create newpath as hardlink or copy of oldpath.
Definition at line 884 of file PathInfo.cc.
Like 'readlink'.
Return the contents of the symbolic link symlink_r via target_r.
Definition at line 925 of file PathInfo.cc.
Recursively follows the symlink pointed to by path_r and returns the Pathname to the real file or directory pointed to by the link.
There is a recursion limit of 256 iterations to protect against a cyclic link.
Definition at line 946 of file PathInfo.cc.
Like 'cp file dest'.
Copy file to dest dir.
Definition at line 991 of file PathInfo.cc.
std::string zypp::filesystem::md5sum | ( | const Pathname & | file | ) |
Compute a files md5sum.
Definition at line 1025 of file PathInfo.cc.
std::string zypp::filesystem::sha1sum | ( | const Pathname & | file | ) |
Compute a files sha1sum.
Definition at line 1042 of file PathInfo.cc.
std::string zypp::filesystem::checksum | ( | const Pathname & | file, |
const std::string & | algorithm | ||
) |
Compute a files checksum.
Definition at line 1052 of file PathInfo.cc.
check files checksum
Definition at line 1064 of file PathInfo.cc.
int zypp::filesystem::erase | ( | const Pathname & | path | ) |
Erase whatever happens to be located at path (file or directory).
Definition at line 1074 of file PathInfo.cc.
int zypp::filesystem::chmod | ( | const Pathname & | path, |
mode_t | mode | ||
) |
Like 'chmod'.
The mode of the file given by path is changed.
Definition at line 1093 of file PathInfo.cc.
int zypp::filesystem::chmodApplyUmask | ( | const Pathname & | path, |
mode_t | mode | ||
) |
Similar to 'chmod', but mode
is modified by the process's umask in the usual way.
Definition at line 1102 of file PathInfo.cc.
int zypp::filesystem::addmod | ( | const Pathname & | path, |
mode_t | mode | ||
) |
Add the mode
bits to the file given by path.
Definition at line 1105 of file PathInfo.cc.
int zypp::filesystem::delmod | ( | const Pathname & | path, |
mode_t | mode | ||
) |
Remove the mode
bits from the file given by path.
Definition at line 1114 of file PathInfo.cc.
Definition at line 1128 of file PathInfo.cc.
Report free disk space on a mounted file system.
path is the path name of any file within the mounted filesystem.
Definition at line 1159 of file PathInfo.cc.
mode_t zypp::filesystem::getUmask | ( | ) |
Get the current umask (file mode creation mask)
Definition at line 1175 of file PathInfo.cc.
int zypp::filesystem::assert_file | ( | const Pathname & | path, |
unsigned | mode = 0644 |
||
) |
Create an empty file if it does not yet exist.
Make parent directories as needed. mode specifies the permissions to use. It is modified by the process's umask in the usual way.
Definition at line 1187 of file PathInfo.cc.
int zypp::filesystem::assert_file_mode | ( | const Pathname & | path, |
unsigned | mode | ||
) |
Like assert_file but enforce mode even if the file already exists.
Definition at line 1206 of file PathInfo.cc.
int zypp::filesystem::touch | ( | const Pathname & | path | ) |
Change file's modification and access times.
Definition at line 1238 of file PathInfo.cc.
|
inline |
Definition at line 515 of file PathInfo.h.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 658 of file PathInfo.h.
|
inline |
Modify mode_r
according to the current umask ( mode_r & ~getUmask() )
.
Definition at line 798 of file PathInfo.h.
|
inline |
constexpr bool zypp::filesystem::always_false = false |
Definition at line 545 of file PathInfo.cc.