aboutsummaryrefslogtreecommitdiffstats
path: root/util/folder/tempdir.h
blob: ff458f83b9b8e4b3e01f92d1ac409870e7d3cb90 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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;
};