tempdir.h 896 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #pragma once
  2. #include "fwd.h"
  3. #include "path.h"
  4. #include <util/generic/string.h>
  5. class TTempDir {
  6. public:
  7. /// Create new directory in system tmp folder.
  8. TTempDir();
  9. /// Create new directory with this fixed name. If it already exists, clear it.
  10. TTempDir(const TString& tempDir);
  11. ~TTempDir();
  12. /// Create new directory in given folder.
  13. static TTempDir NewTempDir(const TString& root);
  14. const TString& operator()() const {
  15. return Name();
  16. }
  17. const TString& Name() const {
  18. return TempDir.GetPath();
  19. }
  20. const TFsPath& Path() const {
  21. return TempDir;
  22. }
  23. void DoNotRemove();
  24. private:
  25. struct TCreationToken {};
  26. // Prevent people from confusing this ctor with the public one
  27. // by requiring additional fake argument.
  28. TTempDir(const char* prefix, TCreationToken);
  29. TFsPath TempDir;
  30. bool Remove;
  31. };