| 33 | return CreateAt(fs::temp_directory_path()); |
| 34 | } |
| 35 | TempFile TempFile::CreateAt(const std::filesystem::path& path, const std::string& nameIn) |
| 36 | { |
| 37 | TempFile tmp; |
| 38 | std::string name = nameIn; |
| 39 | if (name.empty()) { |
| 40 | name = MakeRandomName(); |
| 41 | } |
| 42 | tmp.path_ = path / name; |
| 43 | // don't allow overwrite etc. |
| 44 | if (fs::exists(tmp.path_)) { |
| 45 | throw Except<Exception>("Temp file creation failed: already exists"); |
| 46 | } |
| 47 | // create an empty file (or truncate existing) |
| 48 | std::ofstream{ tmp.path_, std::ios::trunc }; |
| 49 | return tmp; |
| 50 | } |
| 51 | TempFile TempFile::AdoptExisting(const std::filesystem::path& path) |
| 52 | { |
| 53 | TempFile tmp; |