diff options
| author | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 23:13:36 -0500 |
|---|---|---|
| committer | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 23:13:36 -0500 |
| commit | 2800fa3bc682c82e579d9cc1dbf5c00d2a484ab7 (patch) | |
| tree | 56f230b92677154299510b64133fd44f684535a9 /runtime/shims/file_system.cpp | |
| parent | 50c4cfefe2cc8734d91057910e4cd3ac91be7e65 (diff) | |
| parent | 844e650bfabc57342ece360830a4cc72fc59b6c8 (diff) | |
Merge pull request #4328 from Maxime Mansiet
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/shims/file_system.cpp')
| -rw-r--r-- | runtime/shims/file_system.cpp | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/runtime/shims/file_system.cpp b/runtime/shims/file_system.cpp index 4789959e2..cdf4c50af 100644 --- a/runtime/shims/file_system.cpp +++ b/runtime/shims/file_system.cpp | |||
| @@ -144,7 +144,14 @@ Parsed parse_console(const std::wstring& path, std::vector<std::wstring>& parts) | |||
| 144 | const Drive drive = console_drive(path, prefix_length); | 144 | const Drive drive = console_drive(path, prefix_length); |
| 145 | if (drive == Drive::None) return Parsed::Host; | 145 | if (drive == Drive::None) return Parsed::Host; |
| 146 | parts.clear(); | 146 | parts.clear(); |
| 147 | if (drive == Drive::Scratch) parts.push_back(kScratchDir); | 147 | if (drive == Drive::Scratch) { |
| 148 | parts.push_back(kScratchDir); | ||
| 149 | const std::filesystem::path overlay = roots().overlay; | ||
| 150 | const DWORD last_error = ::GetLastError(); | ||
| 151 | std::error_code ec; | ||
| 152 | if (!overlay.empty()) std::filesystem::create_directories(overlay / kScratchDir, ec); | ||
| 153 | ::SetLastError(last_error); | ||
| 154 | } | ||
| 148 | const size_t floor = parts.size(); // ".." may not climb out of the drive's own root | 155 | const size_t floor = parts.size(); // ".." may not climb out of the drive's own root |
| 149 | std::wstring part; | 156 | std::wstring part; |
| 150 | auto flush = [&]() -> bool { | 157 | auto flush = [&]() -> bool { |
| @@ -180,6 +187,11 @@ std::filesystem::path join(const std::filesystem::path& root, const std::vector< | |||
| 180 | return p; | 187 | return p; |
| 181 | } | 188 | } |
| 182 | 189 | ||
| 190 | bool drive_root(const std::wstring& path, const std::vector<std::wstring>& parts) { | ||
| 191 | size_t prefix_length = 0; | ||
| 192 | return parts.empty() || (parts.size() == 1 && console_drive(path, prefix_length) == Drive::Scratch); | ||
| 193 | } | ||
| 194 | |||
| 183 | struct Target { | 195 | struct Target { |
| 184 | std::filesystem::path path; | 196 | std::filesystem::path path; |
| 185 | DWORD error = 0; // non-zero: the caller fails with this error and does not touch the host | 197 | DWORD error = 0; // non-zero: the caller fails with this error and does not touch the host |
| @@ -959,7 +971,7 @@ BOOL WINAPI remove_directory_w(LPCWSTR name) { | |||
| 959 | 971 | ||
| 960 | const Roots r = roots(); | 972 | const Roots r = roots(); |
| 961 | if (r.game.empty() || r.overlay.empty()) return fail_bool(ERROR_PATH_NOT_FOUND); | 973 | if (r.game.empty() || r.overlay.empty()) return fail_bool(ERROR_PATH_NOT_FOUND); |
| 962 | if (parts.empty()) return fail_bool(ERROR_ACCESS_DENIED); // "GAME:" itself stays | 974 | if (drive_root(name, parts)) return fail_bool(ERROR_ACCESS_DENIED); // "GAME:" and "T:" themselves stay |
| 963 | const View v = view(r, parts); | 975 | const View v = view(r, parts); |
| 964 | if (v.kind == Kind::None) return fail_bool(ERROR_FILE_NOT_FOUND); | 976 | if (v.kind == Kind::None) return fail_bool(ERROR_FILE_NOT_FOUND); |
| 965 | if (v.kind == Kind::File) return fail_bool(ERROR_DIRECTORY); | 977 | if (v.kind == Kind::File) return fail_bool(ERROR_DIRECTORY); |
| @@ -996,7 +1008,7 @@ BOOL WINAPI move_file_ex_w(LPCWSTR from, LPCWSTR to, DWORD flags) { | |||
| 996 | 1008 | ||
| 997 | const Roots r = roots(); | 1009 | const Roots r = roots(); |
| 998 | if (r.game.empty() || r.overlay.empty()) return fail_bool(ERROR_PATH_NOT_FOUND); | 1010 | if (r.game.empty() || r.overlay.empty()) return fail_bool(ERROR_PATH_NOT_FOUND); |
| 999 | if (src.empty() || dst.empty()) return fail_bool(ERROR_ACCESS_DENIED); | 1011 | if (drive_root(from, src) || drive_root(to, dst)) return fail_bool(ERROR_ACCESS_DENIED); |
| 1000 | const View from_view = view(r, src); | 1012 | const View from_view = view(r, src); |
| 1001 | if (from_view.kind == Kind::None) return fail_bool(ERROR_FILE_NOT_FOUND); | 1013 | if (from_view.kind == Kind::None) return fail_bool(ERROR_FILE_NOT_FOUND); |
| 1002 | const std::filesystem::path overlay_from = join(r.overlay, src), overlay_to = join(r.overlay, dst); | 1014 | const std::filesystem::path overlay_from = join(r.overlay, src), overlay_to = join(r.overlay, dst); |