12 #ifndef ZYPP_PATHINFO_H 13 #define ZYPP_PATHINFO_H 17 #include <sys/types.h> 156 mode_t
perm()
const {
return (
_mode & (S_IRWXU|S_IRWXG|S_IRWXO|S_ISUID|S_ISGID|S_ISVTX)); }
201 bool insert(
const dev_t & dev_r,
const ino_t & ino_r ) {
202 return _devino[dev_r].insert( ino_r ).second;
237 PathInfo(
const std::string & path,
Mode initial = STAT );
248 const std::string &
asString()
const {
return path_t.asString(); }
250 const char *
c_str()
const {
return path_t.asString().c_str(); }
254 int error()
const {
return error_i; }
257 void setPath(
const Pathname & path ) {
if ( path != path_t ) error_i = -1; path_t = path; }
259 void setMode(
Mode mode ) {
if ( mode != mode_e ) error_i = -1; mode_e = mode; }
262 bool stat (
const Pathname & path ) { setPath( path ); setMode( STAT );
return operator()(); }
264 bool lstat (
const Pathname & path ) { setPath( path ); setMode( LSTAT );
return operator()(); }
269 bool stat() { setMode( STAT );
return operator()(); }
271 bool lstat() { setMode( LSTAT );
return operator()(); }
289 bool isFile()
const {
return isExist() && S_ISREG( statbuf_C.st_mode ); }
290 bool isDir ()
const {
return isExist() && S_ISDIR( statbuf_C.st_mode ); }
291 bool isLink()
const {
return isExist() && S_ISLNK( statbuf_C.st_mode ); }
292 bool isChr()
const {
return isExist() && S_ISCHR( statbuf_C.st_mode ); }
293 bool isBlk()
const {
return isExist() && S_ISBLK( statbuf_C.st_mode ); }
294 bool isFifo()
const {
return isExist() && S_ISFIFO( statbuf_C.st_mode ); }
295 bool isSock()
const {
return isExist() && S_ISSOCK( statbuf_C.st_mode ); }
298 bool isRUsr()
const {
return isExist() && (statbuf_C.st_mode & S_IRUSR); }
299 bool isWUsr()
const {
return isExist() && (statbuf_C.st_mode & S_IWUSR); }
300 bool isXUsr()
const {
return isExist() && (statbuf_C.st_mode & S_IXUSR); }
306 bool isRGrp()
const {
return isExist() && (statbuf_C.st_mode & S_IRGRP); }
307 bool isWGrp()
const {
return isExist() && (statbuf_C.st_mode & S_IWGRP); }
308 bool isXGrp()
const {
return isExist() && (statbuf_C.st_mode & S_IXGRP); }
310 bool isROth()
const {
return isExist() && (statbuf_C.st_mode & S_IROTH); }
311 bool isWOth()
const {
return isExist() && (statbuf_C.st_mode & S_IWOTH); }
312 bool isXOth()
const {
return isExist() && (statbuf_C.st_mode & S_IXOTH); }
314 bool isUid()
const {
return isExist() && (statbuf_C.st_mode & S_ISUID); }
315 bool isGid()
const {
return isExist() && (statbuf_C.st_mode & S_ISGID); }
316 bool isVtx()
const {
return isExist() && (statbuf_C.st_mode & S_ISVTX); }
318 bool isPerm ( mode_t m )
const {
return isExist() && (m ==
perm()); }
319 bool hasPerm( mode_t m )
const {
return isExist() && (m == (m &
perm())); }
321 mode_t
uperm()
const {
return isExist() ? (statbuf_C.st_mode & S_IRWXU) : 0; }
322 mode_t
gperm()
const {
return isExist() ? (statbuf_C.st_mode & S_IRWXG) : 0; }
323 mode_t
operm()
const {
return isExist() ? (statbuf_C.st_mode & S_IRWXO) : 0; }
324 mode_t
perm()
const {
return isExist() ? (statbuf_C.st_mode & (S_IRWXU|S_IRWXG|S_IRWXO|S_ISUID|S_ISGID|S_ISVTX)) : 0; }
326 mode_t
st_mode()
const {
return isExist() ? statbuf_C.st_mode : 0; }
332 nlink_t
nlink()
const {
return isExist() ? statbuf_C.st_nlink : 0; }
336 uid_t
owner()
const {
return isExist() ? statbuf_C.st_uid : 0; }
337 gid_t
group()
const {
return isExist() ? statbuf_C.st_gid : 0; }
343 mode_t userMay()
const;
345 bool userMayR()
const {
return( userMay() & 04 ); }
346 bool userMayW()
const {
return( userMay() & 02 ); }
347 bool userMayX()
const {
return( userMay() & 01 ); }
349 bool userMayRW()
const {
return( (userMay() & 06) == 06 ); }
350 bool userMayRX()
const {
return( (userMay() & 05) == 05 ); }
351 bool userMayWX()
const {
return( (userMay() & 03) == 03 ); }
358 ino_t
ino()
const {
return isExist() ? statbuf_C.st_ino : 0; }
359 dev_t
dev()
const {
return isExist() ? statbuf_C.st_dev : 0; }
360 dev_t
rdev()
const {
return isExist() ? statbuf_C.st_rdev : 0; }
362 unsigned int devMajor()
const;
363 unsigned int devMinor()
const;
368 off_t
size()
const {
return isExist() ? statbuf_C.st_size : 0; }
369 unsigned long blksize()
const {
return isExist() ? statbuf_C.st_blksize : 0; }
370 unsigned long blocks()
const {
return isExist() ? statbuf_C.st_blocks : 0; }
375 time_t
atime()
const {
return isExist() ? statbuf_C.st_atime : 0; }
376 time_t
mtime()
const {
return isExist() ? statbuf_C.st_mtime : 0; }
377 time_t
ctime()
const {
return isExist() ? statbuf_C.st_ctime : 0; }
382 struct stat statbuf_C;
513 int readdir( std::list<std::string> & retlist,
514 const Pathname & path,
bool dots =
true );
528 int readdir( std::list<Pathname> & retlist,
529 const Pathname & path,
bool dots =
true );
544 {
return str <<
'[' << obj.
type <<
"] " << obj.
name; }
549 std::ostream &
operator<<( std::ostream &
str,
const DirContent & obj );
732 std::string
checksum(
const Pathname & file,
const std::string &algorithm );
810 {
return mode_r & ~getUmask(); }
823 #endif // ZYPP_PATHINFO_H
bool isW() const
Short for isWUsr().
int assert_dir(const Pathname &path, unsigned mode)
Like 'mkdir -p'.
const Pathname & path() const
Return current Pathname.
int exchange(const Pathname &lpath, const Pathname &rpath)
Exchanges two files or directories.
ZIP_TYPE
Test whether a file is compressed (gzip/bzip2).
Listentry returned by readdir.
int assert_file(const Pathname &path, unsigned mode)
Create an empty file if it does not yet exist.
std::string sha1sum(const Pathname &file)
Compute a files sha1sum.
std::string md5sum(const Pathname &file)
Compute a files md5sum.
int error() const
Return error returned from last stat/lstat call.
int readlink(const Pathname &symlink_r, Pathname &target_r)
Like 'readlink'.
bool lstat()
LSTAT current path.
bool isUid() const
Set UID bit.
bool isExist() const
Return whether valid stat info exists.
StatMode asStatMode() const
Return st_mode() as filesystem::StatMode.
String matching (STRING|SUBSTRING|GLOB|REGEX).
Store and operate with byte count.
int mkdir(const Pathname &path, unsigned mode)
Like 'mkdir'.
int hardlink(const Pathname &oldpath, const Pathname &newpath)
Like '::link'.
friend std::ostream & operator<<(std::ostream &str, const StatMode &obj)
int chmod(const Pathname &path, mode_t mode)
Like 'chmod'.
int clean_dir(const Pathname &path)
Like 'rm -r DIR/ *'.
bool isR() const
Short for isRUsr().
String related utilities and Regular expression matching.
bool stat()
STAT current path.
bool operator==(const SetRelation::Enum &lhs, const SetCompare &rhs)
const char * c_str() const
Return current Pathname as C-string.
int copy_file2dir(const Pathname &file, const Pathname &dest)
Like 'cp file dest'.
DirEntry(const std::string &name_r=std::string(), FileType type_r=FT_NOT_AVAIL)
mode_t st_mode() const
Return the mode_t value.
bool isVtx() const
Sticky bit.
FileType fileType() const
int is_empty_dir(const Pathname &path_r)
Check if the specified directory is empty.
ZIP_TYPE zipType(const Pathname &file)
int addmod(const Pathname &path, mode_t mode)
Add the mode bits to the file given by path.
const StrMatcher & matchNoDots()
Convenience returning StrMatcher( "[^.]*", Match::GLOB )
const std::string & asString() const
Return current Pathname as String.
int unlink(const Pathname &path)
Like 'unlink'.
void setMode(Mode mode)
Set a new Mode .
int rename(const Pathname &oldpath, const Pathname &newpath)
Like 'rename'.
Simple cache remembering device/inode to detect hardlinks.
int recursive_rmdir(const Pathname &path)
Like 'rm -r DIR'.
bool operator()(const Pathname &path)
Restat path using current mode.
std::list< DirEntry > DirContent
Returned by readdir.
int hardlinkCopy(const Pathname &oldpath, const Pathname &newpath)
Create newpath as hardlink or copy of oldpath.
bool insert(const dev_t &dev_r, const ino_t &ino_r)
Remember dev/ino.
StatMode(const mode_t &mode_r=0)
Ctor taking mode_t value from ::stat.
int symlink(const Pathname &oldpath, const Pathname &newpath)
Like 'symlink'.
bool isX() const
Short for isXUsr().
std::map< dev_t, std::set< ino_t > > _devino
int touch(const Pathname &path)
Change file's modification and access times.
int copy(const Pathname &file, const Pathname &dest)
Like 'cp file dest'.
int readdir(std::list< std::string > &retlist_r, const Pathname &path_r, bool dots_r)
Return content of directory via retlist.
int rmdir(const Pathname &path)
Like 'rmdir'.
mode_t getUmask()
Get the current umask (file mode creation mask)
int copy_dir(const Pathname &srcpath, const Pathname &destpath)
Like 'cp -a srcpath destpath'.
Wrapper class for mode_t values as derived from ::stat.
FileType
File type information.
std::string checksum(const Pathname &file, const std::string &algorithm)
Compute a files checksum.
int erase(const Pathname &path)
Erase whatever happens to be located at path (file or directory).
bool isPerm(mode_t m) const
unsigned long blksize() const
int copy_dir_content(const Pathname &srcpath, const Pathname &destpath)
Like 'cp -a srcpath/.
Wrapper class for ::stat/::lstat.
int dirForEach(const Pathname &dir_r, function< bool(const Pathname &, const char *const)> fnc_r)
Invoke callback function fnc_r for each entry in directory dir_r.
bool isGid() const
Set GID bit.
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...
mode_t applyUmaskTo(mode_t mode_r)
Modify mode_r according to the current umask ( mode_r & ~getUmask() ).
int delmod(const Pathname &path, mode_t mode)
Remove the mode bits from the file given by path.
unsigned long blocks() const
std::ostream & operator<<(std::ostream &str, const Glob &obj)
bool isPerm(mode_t m) const
Test for equal permission bits.
Easy-to use interface to the ZYPP dependency resolver.
bool lstat(const Pathname &path)
LSTAT path.
bool hasPerm(mode_t m) const
bool hasPerm(mode_t m) const
Test for set permission bits.
Mode mode() const
Return current stat Mode.
bool stat(const Pathname &path)
STAT path.
bool is_checksum(const Pathname &file, const CheckSum &checksum)
check files checksum
void setPath(const Pathname &path)
Set a new Pathname.
ByteCount df(const Pathname &path_r)
Report free disk space on a mounted file system.