#include <map>
#include "zypp/Pathname.h"
+#include "zypp/CheckSum.h"
+#include "zypp/ByteCount.h"
///////////////////////////////////////////////////////////////////
namespace zypp
const Pathname & path() const { return path_t; }
/** Return current Pathname as String. */
const std::string & asString() const { return path_t.asString(); }
+ /** Return current Pathname as C-string. */
+ const char * c_str() const { return path_t.asString().c_str(); }
/** Return current stat Mode. */
Mode mode() const { return mode_e; }
/** Return error returned from last stat/lstat call. */
int copy_dir( const Pathname & srcpath, const Pathname & destpath );
/**
+ * Like 'cp -a srcpath/. destpath'. Copy the content of srcpath recursively
+ * into destpath. Both \p srcpath and \p destpath has to exists.
+ *
+ * @return 0 on success, ENOTDIR if srcpath/destpath is not a directory,
+ * EEXIST if srcpath and destpath are equal, otherwise the commands
+ * return value.
+ */
+ int copy_dir_content( const Pathname & srcpath, const Pathname & destpath);
+
+ /**
* Return content of directory via retlist. If dots is false
* entries starting with '.' are not reported. "." and ".."
* are never reported.
: name( name_r )
, type( type_r )
{}
+
+ bool operator==( const DirEntry &rhs ) const;
};
/** Returned by readdir. */
**/
int readdir( DirContent & retlist, const Pathname & path,
bool dots = true, PathInfo::Mode statmode = PathInfo::STAT );
+
+
+ /**
+ * Check if the specified directory is empty.
+ * \param path The path of the directory to check.
+ * \return 0 if directory is empty, -1 if not, errno > 0 on failure.
+ */
+ int is_empty_dir(const Pathname & path);
+
//@}
///////////////////////////////////////////////////////////////////
/** \name File related functions. */
//@{
/**
+ * 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.
+ *
+ * @return 0 on success, errno on failure
+ **/
+ int assert_file( const Pathname & path, unsigned mode = 0644 );
+
+ /**
+ * Change file's modification and access times.
+ *
+ * \return 0 on success, errno on failure
+ * \see man utime
+ */
+ int touch (const Pathname & path);
+
+ /**
* Like '::unlink'. Delete a file (symbolic link, socket, fifo or device).
*
* @return 0 on success, errno on failure
**/
int rename( const Pathname & oldpath, const Pathname & newpath );
+ /** 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.
+ *
+ * \note Paths are exchanged using \c ::rename, so take care both paths
+ * are located on the same filesystem.
+ *
+ * \code
+ * 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.
+ * \endcode
+ *
+ * @return 0 on success, errno on failure
+ */
+ int exchange( const Pathname & lpath, const Pathname & rpath );
+
/**
* Like 'cp file dest'. Copy file to destination file.
*
int hardlink( const Pathname & oldpath, const Pathname & newpath );
/**
+ * Create \a newpath as hardlink or copy of \a oldpath.
+ *
+ * @return 0 on success, errno on failure.
+ */
+ int hardlinkCopy( const Pathname & oldpath, const Pathname & newpath );
+
+ /**
+ * Like '::readlink'. Return the contents of the symbolic link
+ * \a symlink_r via \a target_r.
+ *
+ * @return 0 on success, errno on failure.
+ */
+ int readlink( const Pathname & symlink_r, Pathname & target_r );
+ /** \overload Return an empty Pathname on error. */
+ inline Pathname readlink( const Pathname & symlink_r )
+ {
+ Pathname target;
+ readlink( symlink_r, target );
+ return target;
+ }
+
+ /**
+ * Recursively follows the symlink pointed to by \a 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.
+ *
+ * @return Pathname of the file or directory pointed to by the given link
+ * if it is a valid link. If \a path_r is not a link, an exact copy of
+ * it is returned. If \a path_r is a broken or a cyclic link, an empty
+ * Pathname is returned and the event logged.
+ */
+ Pathname expandlink( const Pathname & path_r );
+
+ /**
* Like 'cp file dest'. Copy file to dest dir.
*
* @return 0 on success, EINVAL if file is not a file, ENOTDIR if dest
std::string sha1sum( const Pathname & file );
//@}
+ /**
+ * Compute a files checksum
+ *
+ * @return the files checksum on success, otherwise an empty string..
+ **/
+ std::string checksum( const Pathname & file, const std::string &algorithm );
+
+ /**
+ * check files checksum
+ *
+ * @return true if the checksum matchs
+ **/
+ bool is_checksum( const Pathname & file, const CheckSum &checksum );
+
///////////////////////////////////////////////////////////////////
/** \name Changing permissions. */
//@{
* @return 0 on success, errno on failure
**/
int chmod( const Pathname & path, mode_t mode );
+
+ /**
+ * Add the \c mode bits to the file given by path.
+ *
+ * @return 0 on success, errno on failure
+ */
+ int addmod( const Pathname & path, mode_t mode );
+
+ /**
+ * Remove the \c mode bits from the file given by path.
+ *
+ * @return 0 on success, errno on failure
+ */
+ int delmod( const Pathname & path, mode_t mode );
//@}
///////////////////////////////////////////////////////////////////
* \todo check cooperation with zypp::TmpFile and zypp::TmpDir
**/
int erase( const Pathname & path );
+
+ /**
+ * Report free disk space on a mounted file system.
+ *
+ * path is the path name of any file within the mounted filesystem.
+ *
+ * @return Free disk space or -1 on error.
+ **/
+ ByteCount df( const Pathname & path );
+
+ /**
+ * Get the current umask (file mode creation mask)
+ *
+ * @return The current umask
+ **/
+ mode_t getUmask();
+
+ /**
+ * Modify \c mode_r according to the current umask
+ * <tt>( mode_r & ~getUmask() )</tt>.
+ * \see \ref getUmask.
+ * @return The resulting permissions.
+ **/
+ inline mode_t applyUmaskTo( mode_t mode_r )
+ { return mode_r & ~getUmask(); }
//@}
/////////////////////////////////////////////////////////////////