Rewrite makeTmpDirectory to not use Uuid methods on windows.

`UuidCreate`, `UuidToString` and `RpcStringFree` need special library
on windows. Lets not use them.
This commit is contained in:
Matthieu Gautier 2019-04-04 16:11:36 +02:00
parent d9e72685ba
commit 938e2a81c1
1 changed files with 11 additions and 16 deletions

View File

@ -228,25 +228,20 @@ bool makeDirectory(const string& path)
string makeTmpDirectory() string makeTmpDirectory()
{ {
#ifdef _WIN32 #ifdef _WIN32
char cbase[MAX_PATH+1]; char cbase[MAX_PATH];
int base_len = GetTempPath(MAX_PATH+1, cbase); char ctmp[MAX_PATH];
UUID uuid; GetTempPath(MAX_PATH-14, cbase);
UuidCreate(&uuid); // This create a file for us, ensure it is unique.
char* dir_name; // So we need to delete it and create the directory using the same name.
UuidToString(&uuid, reinterpret_cast<unsigned char**>(&dir_name)); GetTempFileName(cbase, "kiwix", 0, ctmp);
string dir(cbase, base_len); DeleteFile(ctmp);
dir += dir_name; _mkdir(ctmp);
_mkdir(dir.c_str()); return string(ctmp);
RpcStringFree(reinterpret_cast<unsigned char**>(&dir_name));
#else #else
string base = "/tmp"; char _template_array[] = {"/tmp/kiwix-lib_XXXXXX"};
auto _template = base + "/kiwix-lib_XXXXXX";
char* _template_array = new char[_template.size()+1];
memcpy(_template_array, _template.c_str(), _template.size());
string dir = mkdtemp(_template_array); string dir = mkdtemp(_template_array);
delete[] _template_array;
#endif
return dir; return dir;
#endif
} }
/* Try to create a link and if does not work then make a copy */ /* Try to create a link and if does not work then make a copy */