Skip to content

Commit

Permalink
fix: Creation of directories with absolute path on Windows (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mixaill authored Jun 10, 2020
1 parent 3030613 commit 19ad6e7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/path/sentry_path_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ sentry__path_create_dir_all(const sentry_path_t *path)
memcpy(p, path->path, len * sizeof(wchar_t));

for (ptr = p; *ptr; ptr++) {
if ((*ptr == L'\\' || *ptr == L'/') && ptr != p) {
if ((*ptr == L'\\' || *ptr == L'/') && ptr != p && ptr[-1] != L':') {
*ptr = 0;
_TRY_MAKE_DIR;
*ptr = L'\\';
Expand Down
19 changes: 18 additions & 1 deletion tests/unit/test_path.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,17 @@ SENTRY_TEST(path_directory)
sentry_path_t *path_2 = sentry__path_from_str("foo/bar");
#ifdef SENTRY_PLATFORM_WINDOWS
sentry_path_t *path_3 = sentry__path_from_str("foo/bar\\baz");

// %TEMP%\\sentry_test_unit\\
wchar_t temp_folder[MAX_PATH];
GetEnvironmentVariableW(L"TEMP", temp_folder, sizeof(temp_folder));
sentry_path_t *path_4 = sentry__path_from_wstr(temp_folder);
path_4 = sentry__path_join_str(path_4, "sentry_test_unit");
#endif

// cleanup before tests
sentry__path_remove_all(path_1);

// create single directory
sentry__path_create_dir_all(path_1);
TEST_CHECK(sentry__path_is_dir(path_1));
Expand All @@ -167,14 +176,22 @@ SENTRY_TEST(path_directory)
sentry__path_remove_all(path_2);
TEST_CHECK(!sentry__path_is_dir(path_2));

// create directories by path with forward slash and backward slashes
#ifdef SENTRY_PLATFORM_WINDOWS
// create directories by path with forward slash and backward slashes
sentry__path_create_dir_all(path_3);
TEST_CHECK(sentry__path_is_dir(path_3));

sentry__path_remove_all(path_3);
TEST_CHECK(!sentry__path_is_dir(path_3));
sentry__path_free(path_3);

// create directories with absolute path
sentry__path_create_dir_all(path_4);
TEST_CHECK(sentry__path_is_dir(path_4));

sentry__path_remove_all(path_4);
TEST_CHECK(!sentry__path_is_dir(path_4));
sentry__path_free(path_4);
#endif

sentry__path_free(path_1);
Expand Down

0 comments on commit 19ad6e7

Please sign in to comment.