Mercurial > minori
comparison src/core/filesystem.cpp @ 44:619cbd6e69f9
filesystem: fix CreateDirectories function
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Fri, 22 Sep 2023 13:52:11 -0400 |
parents | 2743011a6042 |
children | 4b05bc7668eb |
comparison
equal
deleted
inserted
replaced
43:eb9a78345ecb | 44:619cbd6e69f9 |
---|---|
24 | 24 |
25 bool CreateDirectories(std::string path) { | 25 bool CreateDirectories(std::string path) { |
26 std::string temp = ""; | 26 std::string temp = ""; |
27 size_t start; | 27 size_t start; |
28 size_t end = 0; | 28 size_t end = 0; |
29 temp.append(path.substr(0, path.find_first_not_of(DELIM, end))); | |
29 | 30 |
30 while ((start = path.find_first_not_of(DELIM, end)) != std::string::npos) { | 31 while ((start = path.find_first_not_of(DELIM, end)) != std::string::npos) { |
31 end = path.find(DELIM, start); | 32 end = path.find(DELIM, start); |
32 temp.append(path.substr(start, end - start)); | 33 temp.append(path.substr(start, end - start)); |
33 #ifdef WIN32 | 34 #ifdef WIN32 |
34 if (!CreateDirectoryA(temp.c_str(), NULL) && GetLastError() == ERROR_PATH_NOT_FOUND) | 35 if (!CreateDirectoryA(temp.c_str(), NULL) && GetLastError() == ERROR_PATH_NOT_FOUND) |
35 /* ERROR_PATH_NOT_FOUND should NOT happen here */ | 36 /* ERROR_PATH_NOT_FOUND should NOT happen here */ |
36 return false; | 37 return false; |
37 #else | 38 #else |
38 if (mkdir(temp.c_str(), 0755)) | 39 struct stat st; |
39 return false; | 40 if (stat(temp.c_str(), &st) == -1) |
41 mkdir(temp.c_str(), 0755); | |
40 #endif | 42 #endif |
41 temp.append(DELIM); | 43 temp.append(DELIM); |
42 } | 44 } |
43 return true; | 45 return true; |
44 } | 46 } |