-
Notifications
You must be signed in to change notification settings - Fork 213
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
CVS-154703, Implement createTempPath(std::string* local_path) for windows #2879
base: main
Are you sure you want to change the base?
Changes from 14 commits
fbab2f2
9b52998
95aca2f
730a2d1
d0b39f3
38fa6c4
b4c76bf
b0f90d3
361af23
d867f55
48e559d
77aeb4d
a27303c
5d0c0cf
fbf9a93
4645579
3eae2db
5cf7da9
c06c9c4
e8578e6
12e3bb0
05a9c67
32febc6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,6 +146,44 @@ class FileSystem { | |
|
||
*local_path = std::string(tmp_folder); | ||
|
||
return StatusCode::OK; | ||
} | ||
#elif _WIN32 | ||
static StatusCode createTempPath(std::string* local_path) { | ||
if (!local_path) | ||
return StatusCode::FILESYSTEM_ERROR; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets add log here that target temp path is not set: SPDLOG_LOGGER_ERROR(modelmanager_logger, "Target path variable for createTempPAth not set. {}" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. following the commit and the modify the code |
||
|
||
wchar_t temp_path[MAX_PATH]; | ||
wchar_t temp_file[MAX_PATH]; | ||
|
||
DWORD path_len = GetTempPathW(MAX_PATH, temp_path); | ||
if (path_len == 0 || path_len > MAX_PATH) { | ||
SPDLOG_LOGGER_ERROR(modelmanager_logger, "Failed to get temp path: {}", GetLastError()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add logging error message: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add message to log in all LastError cases. |
||
return StatusCode::FILESYSTEM_ERROR; | ||
} | ||
|
||
UINT unique_num = GetTempFileNameW(temp_path, L"file", 0, temp_file); | ||
if (unique_num == 0) { | ||
SPDLOG_LOGGER_ERROR(modelmanager_logger, "Failed to create temp file: {}", GetLastError()); | ||
return StatusCode::FILESYSTEM_ERROR; | ||
} | ||
|
||
if (!DeleteFileW(temp_file)) { | ||
SetLastError(0); | ||
DeleteFileW(temp_file); | ||
SPDLOG_LOGGER_ERROR(modelmanager_logger, "Failed to delete temp file: {}", GetLastError()); | ||
return StatusCode::FILESYSTEM_ERROR; | ||
} | ||
|
||
if (!CreateDirectoryW(temp_file, NULL)) { | ||
SetLastError(0); | ||
DeleteFileW(temp_file); | ||
SPDLOG_LOGGER_ERROR(modelmanager_logger, "Failed to create temp directory: {}", GetLastError()); | ||
return StatusCode::FILESYSTEM_ERROR; | ||
} | ||
|
||
*local_path = fs::path(temp_file).generic_string(); | ||
|
||
return StatusCode::OK; | ||
} | ||
#endif | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error path should be in { } for the local_path check