Skip to content

Commit d0dd31c

Browse files
committed
Fixed isReadOnly on Windows
1 parent 51cad49 commit d0dd31c

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/platform/win.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,8 +496,14 @@ bool winFolderIsReadOnly(path_t path) {
496496
HANDLE tokenHandle = nullptr;
497497

498498
// Get current process token
499-
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &tokenHandle))
500-
return true;
499+
if (!OpenThreadToken(GetCurrentThread(), TOKEN_QUERY, TRUE, &tokenHandle)) {
500+
if (GetLastError() == ERROR_NO_TOKEN) {
501+
if (!ImpersonateSelf(SecurityImpersonation))
502+
return true;
503+
if (!OpenThreadToken(GetCurrentThread(), TOKEN_QUERY, TRUE, &tokenHandle))
504+
return true;
505+
} else return true;
506+
}
501507

502508
PSECURITY_DESCRIPTOR securityDesc = nullptr;
503509
PACL dacl = nullptr;

src/util.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ static std::list<std::string> split_list(const std::string& strToSplit, const ch
156156

157157
path_t fixpath_mkdir(Computer * comp, const std::string& path, bool md, std::string * mountPath) {
158158
if (md && fixpath_ro(comp, path)) return path_t();
159+
path_t firstTest = fixpath(comp, path, true, true, mountPath);
160+
if (!firstTest.empty()) return firstTest;
159161
std::list<std::string> components = split_list(path, "/\\");
160162
while (!components.empty() && components.front().empty()) components.pop_front();
161163
if (components.empty()) return fixpath(comp, "", true);

0 commit comments

Comments
 (0)