- Create the cache directly from the schema (installed) file.
[platform/upstream/libzypp.git] / zypp / TmpPath.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/TmpPath.h
10  *
11 */
12 #ifndef ZYPP_TMPPATH_H
13 #define ZYPP_TMPPATH_H
14
15 #include <iosfwd>
16
17 #include "zypp/Pathname.h"
18 #include "zypp/base/PtrTypes.h"
19
20 namespace zypp {
21   namespace filesystem {
22
23     ///////////////////////////////////////////////////////////////////
24     //
25     //  CLASS NAME : TmpPath
26     /**
27      * @short Automaticaly deletes files or directories when no longer needed.
28      *
29      * TmpPath is constructed from a Pathname. Multiple TmpPath instances
30      * created by copy and assign, share the same reference counted internal
31      * repesentation.
32      *
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).
35      *
36      * Principally serves as base class, but standalone usable.
37      **/
38     class TmpPath
39     {
40       public:
41         /**
42          * Default Ctor. An empty Pathname.
43          **/
44         TmpPath();
45     
46         /**
47          * Ctor. Takes a Pathname.
48          **/
49         explicit
50         TmpPath( const Pathname & tmpPath_r );
51     
52         /**
53          * Dtor.
54          **/
55         virtual
56         ~TmpPath();
57     
58         /**
59          * Test whether the Pathname is valid (i.e. not empty. NOT whether
60          * it realy denotes an existing file or directory).
61          **/
62         operator const void *const() const;
63     
64         /**
65          * @return The Pathname.
66          **/
67         Pathname
68         path() const;
69     
70         /**
71          * Type conversion to Pathname.
72          **/
73         operator Pathname() const
74         { return path(); }
75     
76       public:
77         /**
78          * @return The default directory where temporary
79          * files should be are created (/var/tmp).
80          **/
81         static const Pathname &
82         defaultLocation();
83
84       protected:
85         class Impl;
86         RW_pointer<Impl> _impl;
87     
88     };
89     ///////////////////////////////////////////////////////////////////
90     
91     /**
92      * Stream output as pathname.
93      **/
94     inline std::ostream &
95     operator<<( std::ostream & str, const TmpPath & obj )
96     { return str << static_cast<Pathname>(obj); }
97     
98     ///////////////////////////////////////////////////////////////////
99     
100     ///////////////////////////////////////////////////////////////////
101     //
102     //  CLASS NAME : TmpFile
103     /**
104      * @short Provide a new empty temporary file and delete it when no
105      * longer needed.
106      *
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.
111      *
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.
115      **/
116     class TmpFile : public TmpPath
117     {
118       public:
119         /**
120          * Ctor. Takes a Pathname.
121          **/
122         explicit
123         TmpFile( const Pathname & inParentDir_r = defaultLocation(),
124                  const std::string & prefix_r = defaultPrefix() );
125     
126       public:
127         /**
128          * @return The default prefix for temporary files (TmpFile.)
129          **/
130         static const std::string &
131         defaultPrefix();
132     
133     };
134     ///////////////////////////////////////////////////////////////////
135     
136     ///////////////////////////////////////////////////////////////////
137     //
138     //  CLASS NAME : TmpDir
139     /**
140      * @short Provide a new empty temporary directory and recursively
141      * delete it when no longer needed.
142      *
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.
147      *
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.
151      **/
152     class TmpDir : public TmpPath
153     {
154       public:
155         /**
156          * Ctor. Takes a Pathname.
157          **/
158         explicit
159         TmpDir( const Pathname & inParentDir_r = defaultLocation(),
160                 const std::string & prefix_r = defaultPrefix() );
161     
162       public:
163         /**
164          * @return The default prefix for temporary directories (TmpDir.)
165          **/
166         static const std::string &
167         defaultPrefix();
168     };
169     ///////////////////////////////////////////////////////////////////
170
171   } // namespace filesystem
172 } // namespace zypp
173
174 #endif // ZYPP_TMPPATH_H