20 #include <zypp-core/base/ReferenceCounted.h> 21 #include <zypp-core/base/NonCopyable.h> 22 #include <zypp-core/base/Logger.h> 23 #include <zypp-core/fs/PathInfo.h> 24 #include <zypp-core/fs/TmpPath.h> 80 INT <<
"TmpPath cleanup error (" << res <<
") " << p << endl;
82 DBG <<
"TmpPath cleaned up " << p << endl;
121 :_impl( tmpPath_r.empty() ?
nullptr : new
Impl(
std::move(tmpPath_r) ) )
163 static Pathname p( getenv(
"ZYPPTMPDIR") ? getenv(
"ZYPPTMPDIR") :
"/var/tmp" );
186 const std::string & prefix_r )
191 ERR <<
"Parent directory '" << inParentDir_r <<
"' can't be created." << endl;
196 Pathname tmpPath = (inParentDir_r + prefix_r).extend(
"XXXXXX");
197 char * buf = ::strdup( tmpPath.
asString().c_str() );
200 ERR <<
"Out of memory" << endl;
204 int tmpFd = ::mkostemp( buf, O_CLOEXEC );
212 ERR <<
"Cant create '" << buf <<
"' " <<
::strerror( errno ) << endl;
251 static std::string p(
"TmpFile." );
267 const std::string & prefix_r )
272 ERR <<
"Parent directory '" << inParentDir_r <<
"' can't be created." << endl;
277 Pathname tmpPath = (inParentDir_r + prefix_r).extend(
"XXXXXX");
278 char * buf = ::strdup( tmpPath.
asString().c_str() );
281 ERR <<
"Out of memory" << endl;
285 char * tmp = ::mkdtemp( buf );
290 ERR <<
"Cant create '" << tmpPath <<
"' " <<
::strerror( errno ) << endl;
321 static std::string p(
"TmpDir." );
int assert_dir(const Pathname &path, unsigned mode)
Like 'mkdir -p'.
bool autoCleanup() const
Whether path is valid and deleted when the last reference drops.
TmpFile(const Pathname &inParentDir_r=defaultLocation(), const std::string &prefix_r=defaultPrefix())
Ctor.
static TmpDir makeSibling(const Pathname &sibling_r)
Provide a new empty temporary directory as sibling.
int chmod(const Pathname &path, mode_t mode)
Like 'chmod'.
int clean_dir(const Pathname &path)
Like 'rm -r DIR/ *'.
Impl(Pathname &&path_r, Flags flags_r=CtorDefault)
static const Pathname & defaultLocation()
TmpDir(const Pathname &inParentDir_r=defaultLocation(), const std::string &prefix_r=defaultPrefix())
Ctor.
std::string basename() const
Return the last component of this path.
Provide a new empty temporary file and delete it when no longer needed.
bool empty() const
Test for an empty path.
Clean or delete a directory on destruction.
Provide a new empty temporary directory and recursively delete it when no longer needed.
static const std::string & defaultPrefix()
int unlink(const Pathname &path)
Like 'unlink'.
const Pathname & path() const
const std::string & asString() const
String representation.
bool isExist() const
Return whether valid stat info exists.
Pathname dirname() const
Return all but the last component od this path.
int recursive_rmdir(const Pathname &path)
Like 'rm -r DIR'.
Base class for reference counted objects.
Impl & operator=(const Impl &)=delete
Wrapper class for ::stat/::lstat.
static TmpFile makeSibling(const Pathname &sibling_r)
Provide a new empty temporary directory as sibling.
std::string strerror(int errno_r)
Return string describing the error_r code.
Easy-to use interface to the ZYPP dependency resolver.
void autoCleanup(bool yesno_r)
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
static ManagedFile asManagedFile()
Create a temporary file and convert it to a automatically cleaned up ManagedFile. ...
static const std::string & defaultPrefix()