1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/TmpPath.h
12 #ifndef ZYPP_TMPPATH_H
13 #define ZYPP_TMPPATH_H
17 #include "zypp/Pathname.h"
18 #include "zypp/base/PtrTypes.h"
21 namespace filesystem {
23 ///////////////////////////////////////////////////////////////////
25 // CLASS NAME : TmpPath
27 * @short Automaticaly deletes files or directories when no longer needed.
29 * TmpPath is constructed from a Pathname. Multiple TmpPath instances
30 * created by copy and assign, share the same reference counted internal
33 * When the last reference drops any file or directory located at the path
34 * passed to the ctor is deleted (recursivly in case of directories).
36 * Principally serves as base class, but standalone usable.
42 * Default Ctor. An empty Pathname.
47 * Ctor. Takes a Pathname.
50 TmpPath( const Pathname & tmpPath_r );
59 * Test whether the Pathname is valid (i.e. not empty. NOT whether
60 * it realy denotes an existing file or directory).
62 operator const void *const() const;
65 * @return The Pathname.
71 * Type conversion to Pathname.
73 operator Pathname() const
78 * @return The default directory where temporary
79 * files should be are created (/var/tmp).
81 static const Pathname &
86 RW_pointer<Impl> _impl;
89 ///////////////////////////////////////////////////////////////////
92 * Stream output as pathname.
95 operator<<( std::ostream & str, const TmpPath & obj )
96 { return str << static_cast<Pathname>(obj); }
98 ///////////////////////////////////////////////////////////////////
100 ///////////////////////////////////////////////////////////////////
102 // CLASS NAME : TmpFile
104 * @short Provide a new empty temporary file and delete it when no
107 * The temporary file is per default created in '/var/tmp' and named
108 ' TmpFile.XXXXXX', with XXXXXX replaced by a string which makes the
109 * name unique. Different location and file prefix may be passed to
110 * the ctor. TmpFile is created with mode 0600.
112 * The directory where the temporary file is to be created must exist.
113 * TmpFile provides the Pathname of the temporary file, or an empty
114 * path in case of any error.
116 class TmpFile : public TmpPath
120 * Ctor. Takes a Pathname.
123 TmpFile( const Pathname & inParentDir_r = defaultLocation(),
124 const std::string & prefix_r = defaultPrefix() );
128 * @return The default prefix for temporary files (TmpFile.)
130 static const std::string &
134 ///////////////////////////////////////////////////////////////////
136 ///////////////////////////////////////////////////////////////////
138 // CLASS NAME : TmpDir
140 * @short Provide a new empty temporary directory and recursively
141 * delete it when no longer needed.
143 * The temporary directory is per default created in '/var/tmp' and
144 ' named TmpDir.XXXXXX', with XXXXXX replaced by a string which makes
145 * the name unique. Different location and file prefix may be passed
146 * to the ctor. TmpDir is created with mode 0700.
148 * The directory where the temporary directory is to be created must exist.
149 * TmpDir provides the Pathname of the temporary directory , or an empty
150 * path in case of any error.
152 class TmpDir : public TmpPath
156 * Ctor. Takes a Pathname.
159 TmpDir( const Pathname & inParentDir_r = defaultLocation(),
160 const std::string & prefix_r = defaultPrefix() );
164 * @return The default prefix for temporary directories (TmpDir.)
166 static const std::string &
169 ///////////////////////////////////////////////////////////////////
171 } // namespace filesystem
174 #endif // ZYPP_TMPPATH_H