14#include <sys/statvfs.h>
15#include <sys/sysmacros.h>
21#include <zypp-core/fs/PathInfo.h>
22#include <zypp-core/base/LogTools.h>
23#include <zypp-core/base/String.h>
24#include <zypp-core/base/IOStream.h>
25#include <zypp-core/base/Errno.h>
27#include <zypp-core/AutoDispose.h>
28#include <zypp-core/ExternalProgram.h>
29#include <zypp-core/Digest.h>
30#include <zypp-core/fs/TmpPath.h>
50#define EMUMOUT(T) case T: return str << #T; break
102 else if (
obj.isDir() )
104 else if (
obj.isLink() )
106 else if (
obj.isChr() )
108 else if (
obj.isBlk() )
110 else if (
obj.isFifo() )
112 else if (
obj.isSock() )
115 str <<
t <<
" " << std::setfill(
'0' ) << std::setw( 4 ) << std::oct <<
obj.perm();
229 return(
uperm()/0100 );
231 return(
gperm()/010 );
265 str <<
obj.asString() <<
"{";
266 if ( !
obj.isExist() ) {
269 str <<
obj.asStatMode() <<
" " << std::dec <<
obj.owner() <<
"/" <<
obj.group();
272 str <<
" size " <<
obj.size();
284#define logResult MIL << endl, doLogResult
287 inline int doLogResult(
const int res,
const char * rclass = 0 )
292 WAR <<
" FAILED: " << rclass <<
" " << res << endl;
334 std::string::size_type
pos = std::string::npos;
368 MIL <<
"rmdir " << path;
414 MIL <<
"recursive_rmdir " << path <<
' ';
417 if ( !
p.isExist() ) {
427 MIL <<
"unlink symlink ";
444 MIL <<
"clean_dir " << path <<
' ';
447 if ( !
p.isExist() ) {
478 if (
tp.isExist() ) {
483 const char *
const argv[] = {
522 std::string src(
srcpath.asString());
524 const char *
const argv[] = {
543 template <
class... T>
546 template <
typename F>
550 [](
DIR *
dir_r ) { if ( dir_r ) ::closedir( dir_r ); } );
560 if (
entry->d_name[0] ==
'.' && (
entry->d_name[1] ==
'\0' || (
entry->d_name[1] ==
'.' &&
entry->d_name[2] ==
'\0' ) ) )
564 static_assert( !std::is_invocable_v< function<
bool(
const Pathname &,
const char *
const)>,
const Pathname &,
const DirEntry &> ,
"Invoke detection broken" );
565 static_assert( !std::is_invocable_v< function<
bool(
const Pathname &,
const DirEntry& )>,
const Pathname &,
const char *> ,
"Invoke detection broken" );
567 if constexpr ( std::is_invocable_v<F, const Pathname &, const char *const> ) {
572 }
else if constexpr ( std::is_invocable_v<F, const Pathname &, const DirEntry&> ) {
633 switch(
entry->d_type ) {
702 MIL <<
"unlink " << path;
719 const char *
const argv[] = {
726 for (
string output( prog.receiveLine() ); output.length(); output = prog.receiveLine() ) {
727 MIL <<
" " << output;
765 if ( !
linfo.isExist() )
767 if ( !
rinfo.isExist() )
781 if ( !
rinfo.isExist() )
822 MIL <<
"copy " << file <<
" -> " <<
dest <<
' ';
825 if ( !
sp.isFile() ) {
834 const char *
const argv[] = {
836 "--remove-destination",
839 dest.asString().c_str(),
872 if ( ::link(
oldpath.asString().c_str(),
newpath.asString().c_str() ) == -1 ) {
891 MIL <<
" => copy" << endl;
904 if ( ::link(
oldpath.asString().c_str(),
newpath.asString().c_str() ) == -1 )
910 MIL <<
" => copy" << endl;
948 static unsigned int count;
954 DBG <<
"following symlink " << path;
956 DBG <<
"->" << path << std::endl;
963 ERR <<
"Expand level limit reached. Probably a cyclic symbolic link." << endl;
975 ERR << path <<
" is broken (expanded from " <<
path_r <<
")" << endl;
981 DBG <<
"not a symlink" << endl;
992 MIL <<
"copy_file2dir " << file <<
" -> " <<
dest <<
' ';
995 if ( !
sp.isFile() ) {
1000 if ( !
dp.isDir() ) {
1004 const char *
const argv[] = {
1008 dest.asString().c_str(),
1026 if ( !
PathInfo( file ).isFile() ) {
1053 if ( !
PathInfo( file ).isFile() ) {
1105 if (
omode != mode )
1114 if (
omode != mode )
1135 if (
magic[0] == 0037 &&
magic[1] == 0213 ) {
1161 ret =
sb.f_bfree *
sb.f_bsize;
1173 mode_t
mask = ::umask( 0022 );
1194 int fd = ::creat( path.
c_str(), mode );
1212 if ( !
pi.isFile() )
1216 if (
pi.st_mode() != mode )
1217 return chmod( path, mode );
1222 int fd = ::creat( path.
c_str(), mode );
1236 MIL <<
"touch " << path;
1237 struct ::utimbuf
times;
1238 times.actime = ::time( 0 );
1239 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'.
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::list< DirEntry > DirContent
Returned by readdir.
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(const std::string &name_r=std::string(), FileType type_r=FT_NOT_AVAIL)