12#ifndef ZYPP_CORE_FS_PATHINFO_H
13#define ZYPP_CORE_FS_PATHINFO_H
157 mode_t
perm()
const {
return (
_mode & (S_IRWXU|S_IRWXG|S_IRWXO|S_ISUID|S_ISGID|S_ISVTX)); }
202 bool insert(
const dev_t & dev_r,
const ino_t & ino_r ) {
203 return _devino[dev_r].insert( ino_r ).second;
238 PathInfo(
const std::string & path, Mode initial = STAT );
240 PathInfo(
const char * path, Mode initial = STAT );
249 const std::string &
asString()
const {
return path_t.asString(); }
251 const char *
c_str()
const {
return path_t.asString().c_str(); }
255 int error()
const {
return error_i; }
258 void setPath(
const Pathname & path ) {
if ( path != path_t ) error_i = -1; path_t = path; }
260 void setMode(
Mode mode ) {
if ( mode != mode_e ) error_i = -1; mode_e = mode; }
263 bool stat (
const Pathname & path ) { setPath( path ); setMode( STAT );
return operator()(); }
265 bool lstat (
const Pathname & path ) { setPath( path ); setMode( LSTAT );
return operator()(); }
270 bool stat() { setMode( STAT );
return operator()(); }
272 bool lstat() { setMode( LSTAT );
return operator()(); }
290 bool isFile()
const {
return isExist() && S_ISREG( statbuf_C.st_mode ); }
291 bool isDir ()
const {
return isExist() && S_ISDIR( statbuf_C.st_mode ); }
292 bool isLink()
const {
return isExist() && S_ISLNK( statbuf_C.st_mode ); }
293 bool isChr()
const {
return isExist() && S_ISCHR( statbuf_C.st_mode ); }
294 bool isBlk()
const {
return isExist() && S_ISBLK( statbuf_C.st_mode ); }
295 bool isFifo()
const {
return isExist() && S_ISFIFO( statbuf_C.st_mode ); }
296 bool isSock()
const {
return isExist() && S_ISSOCK( statbuf_C.st_mode ); }
299 bool isRUsr()
const {
return isExist() && (statbuf_C.st_mode & S_IRUSR); }
300 bool isWUsr()
const {
return isExist() && (statbuf_C.st_mode & S_IWUSR); }
301 bool isXUsr()
const {
return isExist() && (statbuf_C.st_mode & S_IXUSR); }
303 bool isR()
const {
return isRUsr(); }
304 bool isW()
const {
return isWUsr(); }
305 bool isX()
const {
return isXUsr(); }
307 bool isRGrp()
const {
return isExist() && (statbuf_C.st_mode & S_IRGRP); }
308 bool isWGrp()
const {
return isExist() && (statbuf_C.st_mode & S_IWGRP); }
309 bool isXGrp()
const {
return isExist() && (statbuf_C.st_mode & S_IXGRP); }
311 bool isROth()
const {
return isExist() && (statbuf_C.st_mode & S_IROTH); }
312 bool isWOth()
const {
return isExist() && (statbuf_C.st_mode & S_IWOTH); }
313 bool isXOth()
const {
return isExist() && (statbuf_C.st_mode & S_IXOTH); }
315 bool isUid()
const {
return isExist() && (statbuf_C.st_mode & S_ISUID); }
316 bool isGid()
const {
return isExist() && (statbuf_C.st_mode & S_ISGID); }
317 bool isVtx()
const {
return isExist() && (statbuf_C.st_mode & S_ISVTX); }
319 bool isPerm ( mode_t m )
const {
return isExist() && (m == perm()); }
320 bool hasPerm( mode_t m )
const {
return isExist() && (m == (m & perm())); }
322 mode_t
uperm()
const {
return isExist() ? (statbuf_C.st_mode & S_IRWXU) : 0; }
323 mode_t
gperm()
const {
return isExist() ? (statbuf_C.st_mode & S_IRWXG) : 0; }
324 mode_t
operm()
const {
return isExist() ? (statbuf_C.st_mode & S_IRWXO) : 0; }
325 mode_t
perm()
const {
return isExist() ? (statbuf_C.st_mode & (S_IRWXU|S_IRWXG|S_IRWXO|S_ISUID|S_ISGID|S_ISVTX)) : 0; }
327 mode_t
st_mode()
const {
return isExist() ? statbuf_C.st_mode : 0; }
333 nlink_t
nlink()
const {
return isExist() ? statbuf_C.st_nlink : 0; }
337 uid_t
owner()
const {
return isExist() ? statbuf_C.st_uid : 0; }
338 gid_t
group()
const {
return isExist() ? statbuf_C.st_gid : 0; }
344 mode_t userMay()
const;
346 bool userMayR()
const {
return( userMay() & 04 ); }
347 bool userMayW()
const {
return( userMay() & 02 ); }
348 bool userMayX()
const {
return( userMay() & 01 ); }
350 bool userMayRW()
const {
return( (userMay() & 06) == 06 ); }
351 bool userMayRX()
const {
return( (userMay() & 05) == 05 ); }
352 bool userMayWX()
const {
return( (userMay() & 03) == 03 ); }
359 ino_t
ino()
const {
return isExist() ? statbuf_C.st_ino : 0; }
360 dev_t
dev()
const {
return isExist() ? statbuf_C.st_dev : 0; }
361 dev_t
rdev()
const {
return isExist() ? statbuf_C.st_rdev : 0; }
363 unsigned int devMajor()
const;
364 unsigned int devMinor()
const;
369 off_t
size()
const {
return isExist() ? statbuf_C.st_size : 0; }
370 unsigned long blksize()
const {
return isExist() ? statbuf_C.st_blksize : 0; }
371 unsigned long blocks()
const {
return isExist() ? statbuf_C.st_blocks : 0; }
376 time_t
atime()
const {
return isExist() ? statbuf_C.st_atime : 0; }
377 time_t
mtime()
const {
return isExist() ? statbuf_C.st_mtime : 0; }
378 time_t
ctime()
const {
return isExist() ? statbuf_C.st_ctime : 0; }
383 struct stat statbuf_C;
506 : name(
std::move( name_r ))
516 {
return str <<
'[' << obj.
type <<
"] " << obj.
name; }
714 std::string
checksum(
const Pathname & file,
const std::string &algorithm );
775 int erase(
const Pathname & path );
784 ByteCount
df(
const Pathname & path );
800 {
return mode_r & ~getUmask(); }
808 using filesystem::PathInfo;
std::ostream & operator<<(std::ostream &str, const zypp::sat::detail::CDataiterator *obj)
Simple cache remembering device/inode to detect hardlinks.
bool insert(const dev_t &dev_r, const ino_t &ino_r)
Remember dev/ino.
std::map< dev_t, std::set< ino_t > > _devino
Wrapper class for stat/lstat.
bool lstat(const Pathname &path)
LSTAT path.
StatMode asStatMode() const
Return st_mode() as filesystem::StatMode.
unsigned long blksize() const
Mode mode() const
Return current stat Mode.
bool stat()
STAT current path.
bool isPerm(mode_t m) const
const Pathname & path() const
Return current Pathname.
void setPath(const Pathname &path)
Set a new Pathname.
void setMode(Mode mode)
Set a new Mode .
bool lstat()
LSTAT current path.
unsigned long blocks() const
bool isExist() const
Return whether valid stat info exists.
const char * c_str() const
Return current Pathname as C-string.
const std::string & asString() const
Return current Pathname as String.
bool hasPerm(mode_t m) const
bool operator()(const Pathname &path)
Restat path using current mode.
int error() const
Return error returned from last stat/lstat call.
bool stat(const Pathname &path)
STAT path.
Wrapper class for mode_t values as derived from stat.
bool isR() const
Short for isRUsr().
bool isW() const
Short for isWUsr().
mode_t st_mode() const
Return the mode_t value.
bool isVtx() const
Sticky bit.
bool hasPerm(mode_t m) const
Test for set permission bits.
bool isUid() const
Set UID bit.
bool isX() const
Short for isXUsr().
FileType fileType() const
bool isPerm(mode_t m) const
Test for equal permission bits.
StatMode(const mode_t &mode_r=0)
Ctor taking mode_t value from stat.
bool isGid() const
Set GID bit.
friend std::ostream & operator<<(std::ostream &str, const StatMode &obj)
String related utilities and Regular expression matching.
int chmod(const Pathname &path, mode_t mode)
Like 'chmod'.
int symlink(const Pathname &oldpath, const Pathname &newpath)
Like 'symlink'.
std::ostream & operator<<(std::ostream &str, const Glob &obj)
std::string checksum(const Pathname &file, const std::string &algorithm)
Compute a files checksum.
int delmod(const Pathname &path, mode_t mode)
Remove the mode bits from the file given by path.
int rmdir(const Pathname &path)
Like 'rmdir'.
int mkdir(const Pathname &path, unsigned mode)
Like 'mkdir'.
FileType
File type information.
int assert_file(const Pathname &path, unsigned mode)
Create an empty file if it does not yet exist.
int copy_dir(const Pathname &srcpath, const Pathname &destpath)
Like 'cp -a srcpath destpath'.
mode_t applyUmaskTo(mode_t mode_r)
Modify mode_r according to the current umask ( mode_r & ~getUmask() ).
int recursive_rmdir(const Pathname &path)
Like 'rm -r DIR'.
ByteCount df(const Pathname &path_r)
Report free disk space on a mounted file system.
std::list< DirEntry > DirContent
Returned by readdir.
int hardlinkCopy(const Pathname &oldpath, const Pathname &newpath)
Create newpath as hardlink or copy of oldpath.
int assert_file_mode(const Pathname &path, unsigned mode)
Like assert_file but enforce mode even if the file already exists.
int copy(const Pathname &file, const Pathname &dest)
Like 'cp file dest'.
int clean_dir(const Pathname &path)
Like 'rm -r DIR/ *'.
bool is_checksum(const Pathname &file, const CheckSum &checksum)
check files checksum
Pathname expandlink(const Pathname &path_r)
Recursively follows the symlink pointed to by path_r and returns the Pathname to the real file or dir...
int unlink(const Pathname &path)
Like 'unlink'.
int readdir(std::list< std::string > &retlist_r, const Pathname &path_r, bool dots_r)
Return content of directory via retlist.
int dirForEach(const Pathname &dir_r, const StrMatcher &matcher_r, function< bool(const Pathname &, const char *const)> fnc_r)
int erase(const Pathname &path)
Erase whatever happens to be located at path (file or directory).
int addmod(const Pathname &path, mode_t mode)
Add the mode bits to the file given by path.
int assert_dir(const Pathname &path, unsigned mode)
Like 'mkdir -p'.
int readlink(const Pathname &symlink_r, Pathname &target_r)
Like 'readlink'.
int copy_file2dir(const Pathname &file, const Pathname &dest)
Like 'cp file dest'.
mode_t getUmask()
Get the current umask (file mode creation mask)
int copy_dir_content(const Pathname &srcpath, const Pathname &destpath)
Like 'cp -a srcpath/.
int dirForEachExt(const Pathname &dir_r, const function< bool(const Pathname &, const DirEntry &)> &fnc_r)
Simiar to.
int is_empty_dir(const Pathname &path_r)
Check if the specified directory is empty.
std::string md5sum(const Pathname &file)
Compute a files md5sum.
int hardlink(const Pathname &oldpath, const Pathname &newpath)
Like 'link'.
int exchange(const Pathname &lpath, const Pathname &rpath)
Exchanges two files or directories.
std::string sha1sum(const Pathname &file)
Compute a files sha1sum.
ZIP_TYPE zipType(const Pathname &file)
ZIP_TYPE
Test whether a file is compressed (gzip/bzip2).
int rename(const Pathname &oldpath, const Pathname &newpath)
Like 'rename'.
int chmodApplyUmask(const Pathname &path, mode_t mode)
Similar to 'chmod', but mode is modified by the process's umask in the usual way.
int touch(const Pathname &path)
Change file's modification and access times.
Easy-to use interface to the ZYPP dependency resolver.
bool operator==(const SetRelation::Enum &lhs, const SetCompare &rhs)
This is an overloaded member function, provided for convenience. It differs from the above function o...
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Listentry returned by readdir.
DirEntry(std::string name_r=std::string(), FileType type_r=FT_NOT_AVAIL)