mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-11 17:51:04 +00:00
Better handling of temporary folders
This commit is contained in:
parent
f87994edc7
commit
7e4462e0ac
6 changed files with 34 additions and 17 deletions
|
@ -223,6 +223,16 @@ std::string CreateTempFile()
|
|||
return path;
|
||||
}
|
||||
|
||||
std::string CreateTempDir()
|
||||
{
|
||||
std::string path = TempPath() + DIR_DELIM "MT_XXXXXX";
|
||||
_mktemp_s(&path[0], path.size() + 1); // modifies path
|
||||
// will error if it already exists
|
||||
if (!CreateDirectory(path.c_str(), nullptr))
|
||||
return "";
|
||||
return path;
|
||||
}
|
||||
|
||||
bool CopyFileContents(const std::string &source, const std::string &target)
|
||||
{
|
||||
BOOL ok = CopyFileEx(source.c_str(), target.c_str(), nullptr, nullptr,
|
||||
|
@ -446,6 +456,15 @@ std::string CreateTempFile()
|
|||
return path;
|
||||
}
|
||||
|
||||
std::string CreateTempDir()
|
||||
{
|
||||
std::string path = TempPath() + DIR_DELIM "MT_XXXXXX";
|
||||
auto r = mkdtemp(&path[0]); // modifies path
|
||||
if (!r)
|
||||
return "";
|
||||
return path;
|
||||
}
|
||||
|
||||
namespace {
|
||||
struct FileDeleter {
|
||||
void operator()(FILE *stream) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue