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 really denotes an existing file or directory).
62 operator const void * () 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 * TmpFile provides the Pathname of the temporary file, or an empty
113 * path in case of any error.
115 class TmpFile : public TmpPath
119 * Ctor. Takes a Pathname.
122 TmpFile( const Pathname & inParentDir_r = defaultLocation(),
123 const std::string & prefix_r = defaultPrefix() );
125 /** Provide a new empty temporary directory as sibling.
127 * TmpFile s = makeSibling( "/var/lib/myfile" );
128 * // returns: /var/lib/myfile.XXXXXX
130 * If \c sibling_r exists, sibling is created using the same mode.
132 static TmpFile makeSibling( const Pathname & sibling_r );
136 * @return The default prefix for temporary files (TmpFile.)
138 static const std::string &
142 ///////////////////////////////////////////////////////////////////
144 ///////////////////////////////////////////////////////////////////
146 // CLASS NAME : TmpDir
148 * @short Provide a new empty temporary directory and recursively
149 * delete it when no longer needed.
151 * The temporary directory is per default created in '/var/tmp' and
152 * named 'TmpDir.XXXXXX', with XXXXXX replaced by a string which makes
153 * the name unique. Different location and file prefix may be passed
154 * to the ctor. TmpDir is created with mode 0700.
156 * TmpDir provides the Pathname of the temporary directory , or an empty
157 * path in case of any error.
159 class TmpDir : public TmpPath
163 * Ctor. Takes a Pathname.
166 TmpDir( const Pathname & inParentDir_r = defaultLocation(),
167 const std::string & prefix_r = defaultPrefix() );
169 /** Provide a new empty temporary directory as sibling.
171 * TmpDir s = makeSibling( "/var/lib/mydir" );
172 * // returns: /var/lib/mydir.XXXXXX
174 * If \c sibling_r exists, sibling is created using the same mode.
176 static TmpDir makeSibling( const Pathname & sibling_r );
180 * @return The default prefix for temporary directories (TmpDir.)
182 static const std::string &
185 ///////////////////////////////////////////////////////////////////
187 } // namespace filesystem
190 #endif // ZYPP_TMPPATH_H