X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ffs%2Fredirectedpath.h;fp=source%2Ffs%2Fredirectedpath.h;h=50a3609bd36eb7e163826707ddf7a0bc50c0a0df;hb=d08f1d5d468beb303a4bd80f7e37169c464cf942;hp=0000000000000000000000000000000000000000;hpb=bcca7a40a6c59ee1effbaa1027a5364213434448;p=libs%2Fcore.git diff --git a/source/fs/redirectedpath.h b/source/fs/redirectedpath.h new file mode 100644 index 0000000..50a3609 --- /dev/null +++ b/source/fs/redirectedpath.h @@ -0,0 +1,30 @@ +#ifndef MSP_FS_REDIRECTEDPATH_H_ +#define MSP_FS_REDIRECTEDPATH_H_ + +#include "path.h" + +namespace Msp { +namespace FS { + +/** +Provides a redirected path for the lifetime of the object. When RedirectedPath +goes out of scope, it is renamed to the original path. If destruction happens +due to an exception, it is unlinked instead. The primary use for this is to +atomically overwrite a file with a new version. +*/ +class RedirectedPath: public Path +{ +private: + Path original; + +public: + explicit RedirectedPath(const Path &, const char * = ".tmp"); + RedirectedPath(const Path &, const std::string &); + RedirectedPath(const Path &, const Path &); + ~RedirectedPath(); +}; + +} // namespace FS +} // namespace Msp + +#endif