14#include <sys/statvfs.h>
15#include <sys/sysmacros.h>
22#include <zypp-core/fs/PathInfo.h>
23#include <zypp-core/base/LogTools.h>
24#include <zypp-core/base/String.h>
25#include <zypp-core/base/IOStream.h>
26#include <zypp-core/base/Errno.h>
28#include <zypp-core/AutoDispose.h>
29#include <zypp-core/ExternalProgram.h>
30#include <zypp-core/Digest.h>
31#include <zypp-core/fs/TmpPath.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 MIL << endl, doLogResult
288 inline int doLogResult(
const int res,
const char * rclass = 0 )
293 WAR <<
" FAILED: " << rclass <<
" " << res << endl;
335 std::string::size_type
pos = std::string::npos;
369 MIL <<
"rmdir " << path;
415 MIL <<
"recursive_rmdir " << path <<
' ';
418 if ( !
p.isExist() ) {
428 MIL <<
"unlink symlink ";
445 MIL <<
"clean_dir " << path <<
' ';
448 if ( !
p.isExist() ) {
479 if (
tp.isExist() ) {
484 const char *
const argv[] = {
523 std::string src(
srcpath.asString());
525 const char *
const argv[] = {
544 template <
class... T>
547 template <
typename F>
551 [](
DIR *
dir_r ) { if ( dir_r ) ::closedir( dir_r ); } );
561 if (
entry->d_name[0] ==
'.' && (
entry->d_name[1] ==
'\0' || (
entry->d_name[1] ==
'.' &&
entry->d_name[2] ==
'\0' ) ) )
565 static_assert( !std::is_invocable_v< function<
bool(
const Pathname &,
const char *
const)>,
const Pathname &,
const DirEntry &> ,
"Invoke detection broken" );
566 static_assert( !std::is_invocable_v< function<
bool(
const Pathname &,
const DirEntry& )>,
const Pathname &,
const char *> ,
"Invoke detection broken" );
568 if constexpr ( std::is_invocable_v<F, const Pathname &, const char *const> ) {
573 }
else if constexpr ( std::is_invocable_v<F, const Pathname &, const DirEntry&> ) {
634 switch(
entry->d_type ) {
703 MIL <<
"unlink " << path;
720 const char *
const argv[] = {
727 for (
string output( prog.receiveLine() ); output.length(); output = prog.receiveLine() ) {
728 MIL <<
" " << output;
766 if ( !
linfo.isExist() )
768 if ( !
rinfo.isExist() )
782 if ( !
rinfo.isExist() )
823 MIL <<
"copy " << file <<
" -> " <<
dest <<
' ';
826 if ( !
sp.isFile() ) {
835 const char *
const argv[] = {
837 "--remove-destination",
840 dest.asString().c_str(),
873 if ( ::link(
oldpath.asString().c_str(),
newpath.asString().c_str() ) == -1 ) {
892 MIL <<
" => copy" << endl;
905 if ( ::link(
oldpath.asString().c_str(),
newpath.asString().c_str() ) == -1 )
911 MIL <<
" => copy" << endl;
949 static unsigned int count;
955 DBG <<
"following symlink " << path;
957 DBG <<
"->" << path << std::endl;
964 ERR <<
"Expand level limit reached. Probably a cyclic symbolic link." << endl;
976 ERR << path <<
" is broken (expanded from " <<
path_r <<
")" << endl;
982 DBG <<
"not a symlink" << endl;
993 MIL <<
"copy_file2dir " << file <<
" -> " <<
dest <<
' ';
996 if ( !
sp.isFile() ) {
1001 if ( !
dp.isDir() ) {
1005 const char *
const argv[] = {
1009 dest.asString().c_str(),
1027 if ( !
PathInfo( file ).isFile() ) {
1054 if ( !
PathInfo( file ).isFile() ) {
1106 if (
omode != mode )
1115 if (
omode != mode )
1136 if (
magic[0] == 0037 &&
magic[1] == 0213 ) {
1162 ret =
sb.f_bfree *
sb.f_bsize;
1174 mode_t
mask = ::umask( 0022 );
1195 int fd = ::creat( path.
c_str(), mode );
1213 if ( !
pi.isFile() )
1217 if (
pi.st_mode() != mode )
1218 return chmod( path, mode );
1223 int fd = ::creat( path.
c_str(), mode );
1237 MIL <<
"touch " << path;
1238 struct ::utimbuf
times;
1239 times.actime = ::time( 0 );
1240 times.modtime = ::time( 0 );
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.
int chmod(const Pathname &path, mode_t mode)
Like 'chmod'.
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)
static int recursive_rmdir_1(const Pathname &dir, bool removeDir=true)
FileType
File type information.
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 is_empty_dir(const Pathname &path_r)
Check if the specified directory is empty.
mode_t applyUmaskTo(mode_t mode_r)
Modify mode_r according to the current umask ( mode_r & ~getUmask() ).
int readdir(std::list< std::string > &retlist_r, const Pathname &path_r, bool dots_r)
Return content of directory via retlist.
ByteCount df(const Pathname &path_r)
Report free disk space on a mounted file system.
int unlink(const Pathname &path)
Like 'unlink'.
std::list< DirEntry > DirContent
Returned by readdir.
int rename(const Pathname &oldpath, const Pathname &newpath)
Like 'rename'.
int mkdir(const Pathname &path, unsigned mode)
Like 'mkdir'.
int rmdir(const Pathname &path)
Like 'rmdir'.
bool is_checksum(const Pathname &file, const CheckSum &checksum)
check files checksum
int assert_file(const Pathname &path, unsigned mode)
Create an empty file if it does not yet exist.
int recursive_rmdir(const Pathname &path)
Like 'rm -r DIR'.
int copy_dir(const Pathname &srcpath, const Pathname &destpath)
Like 'cp -a srcpath destpath'.
int copy_dir_content(const Pathname &srcpath, const Pathname &destpath)
Like 'cp -a srcpath/.
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 hardlink(const Pathname &oldpath, const Pathname &newpath)
Like '::link'.
int readlink(const Pathname &symlink_r, Pathname &target_r)
Like 'readlink'.
int assert_dir(const Pathname &path, unsigned mode)
Like 'mkdir -p'.
int copy_file2dir(const Pathname &file, const Pathname &dest)
Like 'cp file dest'.
int assert_file_mode(const Pathname &path, unsigned mode)
Like assert_file but enforce mode even if the file already exists.
mode_t getUmask()
Get the current umask (file mode creation mask)
int touch(const Pathname &path)
Change file's modification and access times.
int hardlinkCopy(const Pathname &oldpath, const Pathname &newpath)
Create newpath as hardlink or copy of oldpath.
constexpr bool always_false
std::string md5sum(const Pathname &file)
Compute a files md5sum.
int exchange(const Pathname &lpath, const Pathname &rpath)
Exchanges two files or directories.
int dirForEachExt(const Pathname &dir_r, const function< bool(const Pathname &, const DirEntry &)> &fnc_r)
Simiar to.
std::string sha1sum(const Pathname &file)
Compute a files sha1sum.
ZIP_TYPE zipType(const Pathname &file)
int copy(const Pathname &file, const Pathname &dest)
Like 'cp file dest'.
ZIP_TYPE
Test whether a file is compressed (gzip/bzip2).
int symlink(const Pathname &oldpath, const Pathname &newpath)
Like 'symlink'.
int clean_dir(const Pathname &path)
Like 'rm -r DIR/ *'.
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)