aboutsummaryrefslogtreecommitdiffstats
path: root/util/folder/tempdir.h
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /util/folder/tempdir.h
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'util/folder/tempdir.h')
-rw-r--r--util/folder/tempdir.h43
1 files changed, 43 insertions, 0 deletions
diff --git a/util/folder/tempdir.h b/util/folder/tempdir.h
new file mode 100644
index 0000000000..ff458f83b9
--- /dev/null
+++ b/util/folder/tempdir.h
@@ -0,0 +1,43 @@
+#pragma once
+
+#include "fwd.h"
+#include "path.h"
+#include <util/generic/string.h>
+
+class TTempDir {
+public:
+ /// Create new directory in system tmp folder.
+ TTempDir();
+
+ /// Create new directory with this fixed name. If it already exists, clear it.
+ TTempDir(const TString& tempDir);
+
+ ~TTempDir();
+
+ /// Create new directory in given folder.
+ static TTempDir NewTempDir(const TString& root);
+
+ const TString& operator()() const {
+ return Name();
+ }
+
+ const TString& Name() const {
+ return TempDir.GetPath();
+ }
+
+ const TFsPath& Path() const {
+ return TempDir;
+ }
+
+ void DoNotRemove();
+
+private:
+ struct TCreationToken {};
+
+ // Prevent people from confusing this ctor with the public one
+ // by requiring additional fake argument.
+ TTempDir(const char* prefix, TCreationToken);
+
+ TFsPath TempDir;
+ bool Remove;
+};