Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] CVS-154703, Implement createTempPath(std::string* local_path) for windows #2879

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/filesystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,36 @@ class FileSystem {

*local_path = std::string(tmp_folder);

return StatusCode::OK;
}
#elif _WIN32
static StatusCode createTempPath(std::string* local_path) {
char temp_path[MAX_PATH] = {0};
if (GetTempPath(MAX_PATH, temp_path) == 0) {
SPDLOG_LOGGER_ERROR(modelmanager_logger, "Failed to get temporary directory : {}", GetLastError());
return StatusCode::FILESYSTEM_ERROR;
}

std::string tmp_folder = temp_path;
tmp_folder += "fileXXXXXX";
char tmp_folder_ctr[MAX_PATH];
strncpy(tmp_folder_ctr, tmp_folder.c_str(), MAX_PATH);
for (int i = strlen(tmp_folder_ctr) - 6; i < strlen(tmp_folder_ctr); ++i) {
tmp_folder_ctr[i] = "A" + (rand_r() % 26);
}

if (!CreateDirectoryA(tmp_folder_ctr, NULL)) {
DWORD error = GetLastError();
SPDLOG_LOGGER_ERROR(modelmanager_logger, "Failed to create local temp folder: {} {}", tmp_folder_ctr, strerror(errno));
return StatusCode::FILESYSTEM_ERROR;
}

fs::permission(tmp_folder_ctr,
fs::perms::others_all | fs::perms::group_all,
fs::perm_options::remove);

*local_path = std::string(tmp_folder_ctr);

return StatusCode::OK;
}
#endif
Expand Down