Types and functions for filesystem operations. More...
Classes | |
class | Glob |
Find pathnames matching a pattern. More... | |
class | StatMode |
Wrapper class for mode_t values as derived from stat. More... | |
class | DevInoCache |
Simple cache remembering device/inode to detect hardlinks. More... | |
class | PathInfo |
Wrapper class for stat/lstat. More... | |
struct | DirEntry |
Listentry returned by readdir. More... | |
class | Pathname |
Pathname. More... | |
class | TmpPath |
Automaticaly deletes files or directories when no longer needed. More... | |
class | TmpFile |
Provide a new empty temporary file and delete it when no longer needed. More... | |
class | TmpDir |
Provide a new empty temporary directory and recursively delete it when no longer needed. More... | |
Enumerations | |
enum | FileType { FT_NOT_AVAIL = 0x00, FT_NOT_EXIST = 0x01, FT_FILE = 0x02, FT_DIR = 0x04, FT_CHARDEV = 0x08, FT_BLOCKDEV = 0x10, FT_FIFO = 0x20, FT_LINK = 0x40, FT_SOCKET = 0x80 } |
File type information. More... | |
Functions | |
std::ostream & | operator<< (std::ostream &str, const Glob &obj) |
ZYPP_DECLARE_OPERATORS_FOR_FLAGS (Glob::Flags) | |
std::ostream & | operator<< (std::ostream &str, FileType obj) |
std::ostream & | operator<< (std::ostream &str, const StatMode &obj) |
std::ostream & | operator<< (std::ostream &str, const PathInfo &obj) |
int | __Log_Result (const int res, const char *rclass=0) |
static int | recursive_rmdir_1 (const Pathname &dir) |
std::string | checksum (const Pathname &file, const std::string &algorithm) |
Compute a files checksum. | |
bool | is_checksum (const Pathname &file, const CheckSum &checksum) |
check files checksum | |
std::ostream & | operator<< (std::ostream &str, const TmpPath &obj) |
Stream output as pathname. | |
File related functions. | |
int | unlink (const Pathname &path) |
Like 'unlink'. | |
int | rename (const Pathname &oldpath, const Pathname &newpath) |
Like 'rename'. | |
int | exchange (const Pathname &lpath, const Pathname &rpath) |
Exchanges two files or directories. | |
int | copy (const Pathname &file, const Pathname &dest) |
Like 'cp file dest'. | |
int | symlink (const Pathname &oldpath, const Pathname &newpath) |
Like 'symlink'. | |
int | hardlink (const Pathname &oldpath, const Pathname &newpath) |
Like 'link'. | |
int | hardlinkCopy (const Pathname &oldpath, const Pathname &newpath) |
Create newpath as hardlink or copy of oldpath. | |
int | readlink (const Pathname &symlink_r, Pathname &target_r) |
Like 'readlink'. | |
Pathname | expandlink (const Pathname &path_r) |
Recursively follows the symlink pointed to by path_r and returns the Pathname to the real file or directory pointed to by the link. | |
int | copy_file2dir (const Pathname &file, const Pathname &dest) |
Like 'cp file dest'. | |
int | assert_file (const Pathname &path, unsigned mode=0644) |
Create an empty file if it does not yet exist. | |
int | touch (const Pathname &path) |
Change file's modification and access times. | |
Pathname | readlink (const Pathname &symlink_r) |
Digest computaion. | |
| |
std::string | md5sum (const Pathname &file) |
Compute a files md5sum. | |
std::string | sha1sum (const Pathname &file) |
Compute a files sha1sum. | |
Changing permissions. | |
int | chmod (const Pathname &path, mode_t mode) |
Like 'chmod'. | |
int | addmod (const Pathname &path, mode_t mode) |
Add the mode bits to the file given by path. | |
int | delmod (const Pathname &path, mode_t mode) |
Remove the mode bits from the file given by path. | |
Misc. | |
| |
enum | ZIP_TYPE { ZT_NONE, ZT_GZ, ZT_BZ2 } |
Test whether a file is compressed (gzip/bzip2). More... | |
int | erase (const Pathname &path) |
Erase whatever happens to be located at path (file or directory). | |
ZIP_TYPE | zipType (const Pathname &file) |
ByteCount | df (const Pathname &path) |
Report free disk space on a mounted file system. | |
mode_t | getUmask () |
Get the current umask (file mode creation mask). | |
mode_t | applyUmaskTo (mode_t mode_r) |
Modify mode_r according to the current umask ( mode_r & ~getUmask() ) . | |
Directory related functions. | |
| |
typedef std::list< DirEntry > | DirContent |
Returned by readdir. | |
int | mkdir (const Pathname &path, unsigned mode=0755) |
Like 'mkdir'. | |
int | assert_dir (const Pathname &path, unsigned mode=0755) |
Like 'mkdir -p'. | |
int | rmdir (const Pathname &path) |
Like 'rmdir'. | |
int | recursive_rmdir (const Pathname &path) |
Like 'rm -r DIR'. | |
int | clean_dir (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 | readdir (std::list< std::string > &retlist, const Pathname &path, bool dots=true) |
Return content of directory via retlist. | |
int | readdir (std::list< Pathname > &retlist, const Pathname &path, bool dots=true) |
Return content of directory via retlist. | |
int | readdir (DirContent &retlist, const Pathname &path, bool dots=true, PathInfo::Mode statmode=PathInfo::STAT) |
Return content of directory via retlist. | |
int | is_empty_dir (const Pathname &path) |
Check if the specified directory is empty. |
Types and functions for filesystem operations.
move zypp::filesystem stuff into separate header
Add tmpfile and tmpdir handling.
think about using Exceptions in zypp::filesystem
provide a readdir iterator; at least provide an interface using an insert_iterator to be independent from std::container.
typedef std::list<DirEntry> zypp::filesystem::DirContent |
Returned by readdir.
Definition at line 497 of file PathInfo.h.
File type information.
FT_NOT_AVAIL | |
FT_NOT_EXIST | |
FT_FILE | |
FT_DIR | |
FT_CHARDEV | |
FT_BLOCKDEV | |
FT_FIFO | |
FT_LINK | |
FT_SOCKET |
Definition at line 53 of file PathInfo.h.
Test whether a file is compressed (gzip/bzip2).
Definition at line 720 of file PathInfo.h.
std::ostream& zypp::filesystem::operator<< | ( | std::ostream & | str, | |
const Glob & | obj | |||
) | [related] |
Definition at line 53 of file Glob.cc.
References zypp::filesystem::Glob::begin(), zypp::dumpRange(), zypp::filesystem::Glob::end(), and zypp::filesystem::Glob::size().
zypp::filesystem::ZYPP_DECLARE_OPERATORS_FOR_FLAGS | ( | Glob::Flags | ) |
std::ostream& zypp::filesystem::operator<< | ( | std::ostream & | str, | |
FileType | obj | |||
) |
Definition at line 45 of file PathInfo.cc.
References EMUMOUT, FT_BLOCKDEV, FT_CHARDEV, FT_DIR, FT_FIFO, FT_FILE, FT_LINK, FT_NOT_AVAIL, FT_NOT_EXIST, and FT_SOCKET.
std::ostream& zypp::filesystem::operator<< | ( | std::ostream & | str, | |
const StatMode & | obj | |||
) |
Definition at line 93 of file PathInfo.cc.
References zypp::filesystem::StatMode::isBlk(), zypp::filesystem::StatMode::isChr(), zypp::filesystem::StatMode::isDir(), zypp::filesystem::StatMode::isFifo(), zypp::filesystem::StatMode::isFile(), zypp::filesystem::StatMode::isLink(), zypp::filesystem::StatMode::isSock(), and zypp::filesystem::StatMode::perm().
std::ostream& zypp::filesystem::operator<< | ( | std::ostream & | str, | |
const PathInfo & | obj | |||
) |
Definition at line 259 of file PathInfo.cc.
References zypp::filesystem::PathInfo::asStatMode(), zypp::filesystem::PathInfo::asString(), zypp::filesystem::PathInfo::group(), zypp::filesystem::PathInfo::isExist(), zypp::filesystem::PathInfo::isFile(), zypp::filesystem::PathInfo::owner(), and zypp::filesystem::PathInfo::size().
int zypp::filesystem::__Log_Result | ( | const int | res, | |
const char * | rclass = 0 | |||
) | [inline] |
Definition at line 292 of file PathInfo.cc.
References zypp::str::strerror(), and WAR.
int zypp::filesystem::mkdir | ( | const Pathname & | path, | |
unsigned | mode = 0755 | |||
) |
Like 'mkdir'.
Attempt to create a new directory named path. mode specifies the permissions to use. It is modified by the process's umask in the usual way.
Referenced by zypp::media::MediaHandler::createAttachPoint().
int zypp::filesystem::assert_dir | ( | const Pathname & | path, | |
unsigned | mode = 0755 | |||
) |
Like 'mkdir -p'.
No error if directory exists. Make parent directories as needed. mode specifies the permissions to use, if directories have to be created. It is modified by the process's umask in the usual way.
Referenced by zypp::RepoManager::addRepositories(), zypp::RepoManager::addRepository(), zypp::target::TargetImpl::buildCache(), zypp::RepoManager::buildCache(), zypp::RepoManager::checkIfToRefreshMetadata(), zypp::target::TargetImpl::commit(), zypp::solver::detail::Testcase::createTestcase(), zypp::media::MediaCurl::doGetFileCopy(), zypp::media::MediaCurl::getDir(), zypp::base::InterProcessMutex::lockFilePath(), zypp::RepoManager::modifyRepository(), zypp::RepoManager::modifyService(), zypp::Fetcher::Impl::provideFromCache(), zypp::Fetcher::Impl::provideToDest(), zypp::RepoManager::refreshMetadata(), zypp::RepoManager::removeRepository(), zypp::RepoManager::removeService(), zypp::media::save_creds_in_file(), zypp::RepoManager::Impl::saveService(), zypp::RepoManager::setCacheStatus(), zypp::HistoryLog::setRoot(), zypp::filesystem::TmpDir::TmpDir(), zypp::filesystem::TmpFile::TmpFile(), zypp::target::updateFileContent(), and zypp::ZYppGlobalLock::ZYppGlobalLock().
int zypp::filesystem::rmdir | ( | const Pathname & | path | ) |
Like 'rmdir'.
Delete a directory, which must be empty.
Referenced by zypp::media::MediaHandler::checkAttachPoint(), zypp::media::MediaHandler::createAttachPoint(), zypp::media::MediaCurl::MediaCurl(), and recursive_rmdir_1().
static int zypp::filesystem::recursive_rmdir_1 | ( | const Pathname & | dir | ) | [static] |
Definition at line 384 of file PathInfo.cc.
References _Log_Result, zypp::filesystem::Pathname::c_str(), readdir(), rmdir(), and unlink().
int zypp::filesystem::recursive_rmdir | ( | const Pathname & | path | ) |
Like 'rm -r DIR'.
Delete a directory, recursively removing its contents.
Referenced by zypp::target::TargetImpl::buildCache(), zypp::RepoManager::cleanCache(), zypp::RepoManager::cleanCacheDirGarbage(), zypp::RepoManager::cleanMetadata(), zypp::RepoManager::cleanPackages(), zypp::target::TargetImpl::clearCache(), zypp::target::rpm::RpmDb::doRebuildDatabase(), zypp::media::MediaHandler::releasePath(), zypp::media::MediaHandler::removeAttachPoint(), zypp::target::writeUpgradeTestcase(), and zypp::filesystem::TmpPath::Impl::~Impl().
int zypp::filesystem::clean_dir | ( | const Pathname & | path | ) |
Like 'rm -r DIR/ *'.
Delete directory contents, but keep the directory itself.
Referenced by zypp::solver::detail::Testcase::createTestcase(), zypp::media::MediaHandler::releasePath(), and zypp::filesystem::TmpPath::Impl::~Impl().
int zypp::filesystem::copy_dir | ( | const Pathname & | srcpath, | |
const Pathname & | destpath | |||
) |
Like 'cp -a srcpath destpath'.
Copy directory tree. srcpath/destpath must be directories. 'basename srcpath' must not exist in destpath.
int zypp::filesystem::copy_dir_content | ( | const Pathname & | srcpath, | |
const Pathname & | destpath | |||
) |
Like 'cp -a srcpath/.
destpath'. Copy the content of srcpath recursively into destpath. Both srcpath
and destpath
has to exists.
int zypp::filesystem::readdir | ( | std::list< std::string > & | retlist, | |
const Pathname & | path, | |||
bool | dots = true | |||
) |
Return content of directory via retlist.
If dots is false entries starting with '.' are not reported. "." and ".." are never reported.
Returns just the directory entries as string.
Referenced by zypp::VendorAttr::addVendorDirectory(), zypp::RepoManager::cleanCacheDirGarbage(), zypp::media::MediaHandler::getDirInfo(), zypp::RepoManager::Impl::init_knownServices(), recursive_rmdir_1(), zypp::parser::plaindir::recursive_timestamp(), zypp::repositories_in_dir(), zypp::parser::ProductFileReader::scanDir(), zypp::media::MediaDISK::verifyIfDiskVolume(), and zypp::target::writeUpgradeTestcase().
int zypp::filesystem::readdir | ( | std::list< Pathname > & | retlist, | |
const Pathname & | path, | |||
bool | dots = true | |||
) |
Return content of directory via retlist.
If dots is false entries starting with '.' are not reported. "." and ".." are never reported.
Returns the directory entries prefixed with path.
int zypp::filesystem::readdir | ( | DirContent & | retlist, | |
const Pathname & | path, | |||
bool | dots = true , |
|||
PathInfo::Mode | statmode = PathInfo::STAT | |||
) |
Return content of directory via retlist.
If dots is false entries starting with '.' are not reported. "." and ".." are never reported.
The type of individual directory entries is determined accoding to statmode (i.e. via stat or lstat).
int zypp::filesystem::is_empty_dir | ( | const Pathname & | path | ) |
Check if the specified directory is empty.
path | The path of the directory to check. |
Referenced by zypp::media::MediaHandler::checkAttachPoint().
int zypp::filesystem::unlink | ( | const Pathname & | path | ) |
Like 'unlink'.
Delete a file (symbolic link, socket, fifo or device).
Referenced by zypp::RepoManager::buildCache(), zypp::media::CredentialManager::clearAll(), zypp::target::TargetImpl::commit(), zypp::target::CommitPackageCacheReadAhead::doCacheLastInteractive(), zypp::media::MediaCurl::doGetFileCopy(), zypp::base::InterProcessMutex::InterProcessMutex(), zypp::repo::RepoMediaAccess::provideFile(), zypp::repo::PackageProvider::providePackage(), recursive_rmdir_1(), zypp::media::MediaHandler::releasePath(), zypp::RepoManager::removeRepository(), zypp::RepoManager::removeService(), zypp::target::rpm::RpmDb::removeV3(), zypp::target::rpm::RpmDb::removeV4(), zypp::repo::PackageProvider::tryDelta(), zypp::ZYppGlobalLock::zyppLocked(), zypp::filesystem::TmpPath::Impl::~Impl(), zypp::base::InterProcessMutex::~InterProcessMutex(), and zypp::ZYppGlobalLock::~ZYppGlobalLock().
int zypp::filesystem::rename | ( | const Pathname & | oldpath, | |
const Pathname & | newpath | |||
) |
Like 'rename'.
Renames a file, moving it between directories if required.
Referenced by zypp::target::TargetImpl::buildCache(), zypp::media::MediaCurl::doGetFileCopy(), zypp::target::rpm::RpmDb::removeV3(), zypp::target::SoftLocksFile::store(), zypp::target::RequestedLocalesFile::store(), and zypp::target::HardLocksFile::store().
int zypp::filesystem::exchange | ( | const Pathname & | lpath, | |
const Pathname & | rpath | |||
) |
Exchanges two files or directories.
Most common use is when building a new config file (or dir) in a tempfile. After the job is done, configfile and tempfile are exchanged. This includes moving away the configfile in case the tempfile does not exist. Parent directories are created as needed.
rename
, so take care both paths are located on the same filesystem.Pathname configfile( "/etc/myconfig" ); TmpFile newconfig( TmpFile::makeSibling( configfile ) ); // now write the new config: std::ofstream o( newconfig.path().c_str() ); o << "mew values << endl; o.close(); // If everything is fine, exchange the files: exchange( newconfig.path(), configfile ); // Now the old configfile is still available at newconfig.path() // until newconfig goes out of scope.
Referenced by zypp::RepoManager::refreshMetadata().
int zypp::filesystem::copy | ( | const Pathname & | file, | |
const Pathname & | dest | |||
) |
Like 'cp file dest'.
Copy file to destination file.
Referenced by zypp::target::CommitPackageCacheReadAhead::doCacheLastInteractive().
int zypp::filesystem::symlink | ( | const Pathname & | oldpath, | |
const Pathname & | newpath | |||
) |
Like 'symlink'.
Creates a symbolic link named newpath which contains the string oldpath. If newpath exists it will not be overwritten.
int zypp::filesystem::hardlink | ( | const Pathname & | oldpath, | |
const Pathname & | newpath | |||
) |
Like 'link'.
Creates a hard link named newpath to an existing file oldpath. If newpath exists it will not be overwritten.
int zypp::filesystem::hardlinkCopy | ( | const Pathname & | oldpath, | |
const Pathname & | newpath | |||
) |
Create newpath as hardlink or copy of oldpath.
Referenced by zypp::Fetcher::Impl::provideFromCache(), and zypp::Fetcher::Impl::provideToDest().
int zypp::filesystem::readlink | ( | const Pathname & | symlink_r, | |
Pathname & | target_r | |||
) |
Like 'readlink'.
Return the contents of the symbolic link symlink_r via target_r.
Referenced by zypp::CheckAccessDeleted::findService(), zypp::base::InterProcessMutex::isProcessRunning(), and readlink().
Pathname zypp::filesystem::expandlink | ( | const Pathname & | path_r | ) |
Recursively follows the symlink pointed to by path_r and returns the Pathname to the real file or directory pointed to by the link.
There is a recursion limit of 256 iterations to protect against a cyclic link.
Referenced by zypp::media::MediaISO::attachTo().
int zypp::filesystem::copy_file2dir | ( | const Pathname & | file, | |
const Pathname & | dest | |||
) |
Like 'cp file dest'.
Copy file to dest dir.
std::string zypp::filesystem::md5sum | ( | const Pathname & | file | ) |
Compute a files md5sum.
std::string zypp::filesystem::sha1sum | ( | const Pathname & | file | ) |
Compute a files sha1sum.
Referenced by zypp::RepoStatus::RepoStatus().
std::string zypp::filesystem::checksum | ( | const Pathname & | file, | |
const std::string & | algorithm | |||
) |
Compute a files checksum.
Referenced by zypp::PublicKey::Impl::Impl(), zypp::ChecksumFileChecker::operator()(), zypp::repo::PackageProvider::providePackage(), and zypp::PublicKey::Impl::readFromFile().
bool zypp::filesystem::is_checksum | ( | const Pathname & | file, | |
const CheckSum & | checksum | |||
) |
check files checksum
Referenced by zypp::Fetcher::Impl::provideFromCache().
int zypp::filesystem::erase | ( | const Pathname & | path | ) |
Erase whatever happens to be located at path (file or directory).
int zypp::filesystem::chmod | ( | const Pathname & | path, | |
mode_t | mode | |||
) |
Like 'chmod'.
The mode of the file given by path is changed.
Referenced by zypp::target::TargetImpl::buildCache(), zypp::log::FileLineWriter::FileLineWriter(), zypp::filesystem::TmpDir::makeSibling(), zypp::filesystem::TmpFile::makeSibling(), zypp::media::save_creds_in_file(), zypp::target::SoftLocksFile::store(), zypp::target::RequestedLocalesFile::store(), and zypp::target::HardLocksFile::store().
int zypp::filesystem::addmod | ( | const Pathname & | path, | |
mode_t | mode | |||
) |
Add the mode
bits to the file given by path.
int zypp::filesystem::delmod | ( | const Pathname & | path, | |
mode_t | mode | |||
) |
Remove the mode
bits from the file given by path.
ZIP_TYPE zypp::filesystem::zipType | ( | const Pathname & | file | ) |
ByteCount zypp::filesystem::df | ( | const Pathname & | path | ) |
Report free disk space on a mounted file system.
path is the path name of any file within the mounted filesystem.
Referenced by zypp::target::CommitPackageCacheReadAhead::doCacheLastInteractive().
mode_t zypp::filesystem::getUmask | ( | ) |
Get the current umask (file mode creation mask).
Referenced by applyUmaskTo().
int zypp::filesystem::assert_file | ( | const Pathname & | path, | |
unsigned | mode = 0644 | |||
) |
Create an empty file if it does not yet exist.
Make parent directories as needed. mode specifies the permissions to use. It is modified by the process's umask in the usual way.
int zypp::filesystem::touch | ( | const Pathname & | path | ) |
Change file's modification and access times.
Referenced by zypp::RepoManager::touchIndexFile().
Pathname zypp::filesystem::readlink | ( | const Pathname & | symlink_r | ) | [inline] |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 623 of file PathInfo.h.
References readlink().
mode_t zypp::filesystem::applyUmaskTo | ( | mode_t | mode_r | ) | [inline] |
Modify mode_r
according to the current umask ( mode_r & ~getUmask() )
.
Definition at line 755 of file PathInfo.h.
References getUmask().
Referenced by zypp::media::MediaCurl::doGetFileCopy().