14#include <sys/statvfs.h>
15#include <sys/sysmacros.h>
51#define EMUMOUT(T) case T: return str << #T; break
103 else if (
obj.isDir() )
105 else if (
obj.isLink() )
107 else if (
obj.isChr() )
109 else if (
obj.isBlk() )
111 else if (
obj.isFifo() )
113 else if (
obj.isSock() )
116 str <<
t <<
" " << std::setfill(
'0' ) << std::setw( 4 ) << std::oct <<
obj.perm();
142 : path_t(
std::move( path ))
230 return(
uperm()/0100 );
232 return(
gperm()/010 );
266 str <<
obj.asString() <<
"{";
267 if ( !
obj.isExist() ) {
270 str <<
obj.asStatMode() <<
" " << std::dec <<
obj.owner() <<
"/" <<
obj.group();
273 str <<
" size " <<
obj.size();
285#define logResult( ... ) doLogResult( __FUNCTION__, __LINE__, __VA_ARGS__ )
288 inline int doLogResult(
const char *function,
const int line,
const int res,
const char * rclass = 0 )
297 WAR <<
" FAILED: " << rclass <<
" " << res << endl;
339 std::string::size_type pos = std::string::npos;
342 while ( (pos =
spath.find(
'/',
lastpos)) != std::string::npos )
344 string dir(
spath.substr(0,pos) );
373 MIL <<
"rmdir " << path;
419 MIL <<
"recursive_rmdir " << path <<
' ';
422 if ( !
p.isExist() ) {
432 MIL <<
"unlink symlink ";
449 MIL <<
"clean_dir " << path <<
' ';
452 if ( !
p.isExist() ) {
483 if (
tp.isExist() ) {
488 const char *
const argv[] = {
527 std::string src(
srcpath.asString());
529 const char *
const argv[] = {
548 template <
class... T>
551 template <
typename F>
555 [](
DIR *
dir_r ) { if ( dir_r ) ::closedir( dir_r ); } );
565 if (
entry->d_name[0] ==
'.' && (
entry->d_name[1] ==
'\0' || (
entry->d_name[1] ==
'.' &&
entry->d_name[2] ==
'\0' ) ) )
569 static_assert( !std::is_invocable_v< function<
bool(
const Pathname &,
const char *
const)>,
const Pathname &,
const DirEntry &> ,
"Invoke detection broken" );
570 static_assert( !std::is_invocable_v< function<
bool(
const Pathname &,
const DirEntry& )>,
const Pathname &,
const char *> ,
"Invoke detection broken" );
572 if constexpr ( std::is_invocable_v<F, const Pathname &, const char *const> ) {
577 }
else if constexpr ( std::is_invocable_v<F, const Pathname &, const DirEntry&> ) {
638 switch(
entry->d_type ) {
707 MIL <<
"unlink " << path;
724 const char *
const argv[] = {
731 for (
string output( prog.receiveLine() ); output.length(); output = prog.receiveLine() ) {
732 MIL <<
" " << output;
770 if ( !
linfo.isExist() )
772 if ( !
rinfo.isExist() )
786 if ( !
rinfo.isExist() )
827 MIL <<
"copy " << file <<
" -> " <<
dest <<
' ';
830 if ( !
sp.isFile() ) {
839 const char *
const argv[] = {
841 "--remove-destination",
844 dest.asString().c_str(),
877 if ( ::link(
oldpath.asString().c_str(),
newpath.asString().c_str() ) == -1 ) {
896 MIL <<
" => copy" << endl;
909 if ( ::link(
oldpath.asString().c_str(),
newpath.asString().c_str() ) == -1 )
915 MIL <<
" => copy" << endl;
953 static unsigned int count;
959 DBG <<
"following symlink " << path;
961 DBG <<
"->" << path << std::endl;
968 ERR <<
"Expand level limit reached. Probably a cyclic symbolic link." << endl;
980 ERR << path <<
" is broken (expanded from " <<
path_r <<
")" << endl;
986 DBG <<
"not a symlink" << endl;
997 MIL <<
"copy_file2dir " << file <<
" -> " <<
dest <<
' ';
1000 if ( !
sp.isFile() ) {
1005 if ( !
dp.isDir() ) {
1009 const char *
const argv[] = {
1013 dest.asString().c_str(),
1031 if ( !
PathInfo( file ).isFile() ) {
1058 if ( !
PathInfo( file ).isFile() ) {
1113 if (
omode != mode )
1122 if (
omode != mode )
1143 if (
magic[0] == 0037 &&
magic[1] == 0213 ) {
1169 ret =
sb.f_bfree *
sb.f_bsize;
1181 mode_t
mask = ::umask( 0022 );
1202 int fd = ::creat( path.
c_str(), mode );
1220 if ( !
pi.isFile() )
1224 if (
pi.st_mode() != mode )
1225 return chmod( path, mode );
1230 int fd = ::creat( path.
c_str(), mode );
1244 MIL <<
"touch " << path;
1245 struct ::utimbuf
times;
1246 times.actime = ::time( 0 );
1247 times.modtime = ::time( 0 );
#define ZYPP_BASE_LOGGER_LOGGROUP
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
Store and operate with byte count.
std::string digest()
get hex string representation of the digest
Convenience errno wrapper.
Execute a program and give access to its io An object of this class encapsulates the execution of an ...
Wrapper class for stat/lstat.
StatMode asStatMode() const
Return st_mode() as filesystem::StatMode.
bool stat()
STAT current path.
bool operator()()
Restat current path using current mode.
unsigned int devMinor() const
FileType fileType() const
bool lstat()
LSTAT current path.
mode_t userMay() const
Returns current users permission ([0-7])
bool isExist() const
Return whether valid stat info exists.
unsigned int devMajor() const
Pathname dirname() const
Return all but the last component od this path.
const char * c_str() const
String representation.
const std::string & asString() const
String representation.
bool empty() const
Test for an empty path.
bool relative() const
Test for a relative path.
Wrapper class for mode_t values as derived from ::stat.
FileType fileType() const
Provide a new empty temporary file and delete it when no longer needed.
static TmpFile makeSibling(const Pathname &sibling_r)
Provide a new empty temporary directory as sibling.
String related utilities and Regular expression matching.
std::ostream & getStream(const char *group_r, LogLevel level_r, const char *file_r, const char *func_r, const int line_r)
Return a log stream to write on.
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 dirForEachImpl(const Pathname &dir_r, F &&fnc_r)
int rmdir(const Pathname &path)
Like 'rmdir'.
int mkdir(const Pathname &path, unsigned mode)
Like 'mkdir'.
static int recursive_rmdir_1(const Pathname &dir, bool removeDir=true)
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.
constexpr bool always_false
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.
boost::io::ios_base_all_saver IosFmtFlagsSaver
Save and restore streams width, precision and fmtflags.
std::string octstring(char n, int w=4)
std::string strerror(int errno_r)
Return string describing the error_r code.
Easy-to use interface to the ZYPP dependency resolver.
std::ostream & dumpRange(std::ostream &str, TIterator begin, TIterator end, const std::string &intro="{", const std::string &pfx="\n ", const std::string &sep="\n ", const std::string &sfx="\n", const std::string &extro="}")
Print range defined by iterators (multiline style).
Listentry returned by readdir.
bool operator==(const DirEntry &rhs) const
DirEntry(std::string name_r=std::string(), FileType type_r=FT_NOT_AVAIL)