From 09f93c586937db7e16837bcc1ee799d5e65947ae Mon Sep 17 00:00:00 2001 From: Jalin Wang Date: Tue, 14 Apr 2026 19:01:37 +0800 Subject: [PATCH] fix: skip drive root in Windows MakePath (#337) CreateDirectoryA("C:", nullptr) returns ERROR_ACCESS_DENIED on Windows (not ERROR_ALREADY_EXISTS), causing MakePath to fail immediately for any path on the C: drive. Skip the CreateDirectoryA call when the intermediate path is a bare drive root (e.g. "C:"). --- src/ailego/utility/file_helper.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ailego/utility/file_helper.cc b/src/ailego/utility/file_helper.cc index 689ad34..722b16f 100644 --- a/src/ailego/utility/file_helper.cc +++ b/src/ailego/utility/file_helper.cc @@ -297,7 +297,11 @@ bool FileHelper::MakePath(const char *path) { // Neither root nor double slash in path if (sp != pp) { *sp = '\0'; - if (!CreateDirectoryA(pathbuf, nullptr) && + // Skip Windows drive roots like "C:" — CreateDirectoryA on a bare drive + // letter returns ERROR_ACCESS_DENIED (not ERROR_ALREADY_EXISTS), which + // would cause MakePath to fail even when all parent dirs already exist. + bool is_drive_root = (sp - pathbuf == 2 && pathbuf[1] == ':'); + if (!is_drive_root && !CreateDirectoryA(pathbuf, nullptr) && GetLastError() != ERROR_ALREADY_EXISTS) { return false; }