]> git.tdb.fi Git - libs/core.git/blob - source/fs/redirectedpath.cpp
Add RAII class for atomic overwrites
[libs/core.git] / source / fs / redirectedpath.cpp
1 #include <exception>
2 #include "redirectedpath.h"
3 #include "stat.h"
4 #include "utils.h"
5
6 using namespace std;
7
8 namespace Msp {
9 namespace FS {
10
11 RedirectedPath::RedirectedPath(const Path &p, const char *ext):
12         Path(p.str()+ext),
13         original(p)
14 { }
15
16 RedirectedPath::RedirectedPath(const Path &p, const string &ext):
17         Path(p.str()+ext),
18         original(p)
19 { }
20
21 RedirectedPath::RedirectedPath(const Path &p, const Path &r):
22         Path(r),
23         original(p)
24 { }
25
26 RedirectedPath::~RedirectedPath()
27 {
28         if(exists(*this))
29         {
30                 if(uncaught_exception())
31                         unlink(*this);
32                 else
33                         rename(*this, original);
34         }
35 }
36
37 } // namespace FS
38 } // namespace Msp