diff options
Diffstat (limited to 'runtime/shims/file_system.cpp')
| -rw-r--r-- | runtime/shims/file_system.cpp | 103 |
1 files changed, 75 insertions, 28 deletions
diff --git a/runtime/shims/file_system.cpp b/runtime/shims/file_system.cpp index 2a31b664d..720c106f3 100644 --- a/runtime/shims/file_system.cpp +++ b/runtime/shims/file_system.cpp | |||
| @@ -119,6 +119,49 @@ bool lies_under(const std::wstring& path, const std::filesystem::path& root) { | |||
| 119 | return p.compare(0, base.size(), base) == 0 && (p.size() == base.size() || p[base.size()] == L'\\'); | 119 | return p.compare(0, base.size(), base) == 0 && (p.size() == base.size() || p[base.size()] == L'\\'); |
| 120 | } | 120 | } |
| 121 | 121 | ||
| 122 | // The console shim may resolve even a short guest name to an extended-length host path. GetFullPathNameW | ||
| 123 | // applies the ordinary DOS path rules (including trailing dots and spaces) before the extended prefix disables | ||
| 124 | // that normalization. The headroom is for CreateDirectoryW's shorter limit on an unprefixed directory name. | ||
| 125 | std::filesystem::path win32_io_path(const std::filesystem::path& path) { | ||
| 126 | const auto& native = path.native(); | ||
| 127 | constexpr size_t kDirectoryPathLimit = MAX_PATH - 12; | ||
| 128 | if (native.size() < kDirectoryPathLimit || !path.is_absolute() || | ||
| 129 | native.starts_with(L"\\\\?\\") || native.starts_with(L"\\\\.\\")) | ||
| 130 | return path; | ||
| 131 | |||
| 132 | const DWORD capacity = ::GetFullPathNameW(native.c_str(), 0, nullptr, nullptr); | ||
| 133 | if (capacity == 0) return path; | ||
| 134 | std::wstring full(capacity, L'\0'); | ||
| 135 | const DWORD size = ::GetFullPathNameW(native.c_str(), capacity, full.data(), nullptr); | ||
| 136 | if (size == 0 || size >= capacity) return path; | ||
| 137 | full.resize(size); | ||
| 138 | |||
| 139 | // DOS device names such as NUL can normalize to a device path. Leave those to the native API as before. | ||
| 140 | if (full.starts_with(L"\\\\.\\")) return path; | ||
| 141 | if (full.starts_with(L"\\\\")) return std::filesystem::path(L"\\\\?\\UNC\\" + full.substr(2)); | ||
| 142 | return std::filesystem::path(L"\\\\?\\" + full); | ||
| 143 | } | ||
| 144 | |||
| 145 | std::filesystem::path win32_find_path(const std::filesystem::path& path, const std::wstring& leaf) { | ||
| 146 | if (path.native().size() < MAX_PATH) return path; | ||
| 147 | const auto search = win32_io_path(path); | ||
| 148 | if (search == path || !leaf.ends_with(L'.') || leaf.find_first_of(L"*?") == std::wstring::npos) return search; | ||
| 149 | |||
| 150 | // GetFullPathNameW strips a terminal dot, but that dot changes a native Win32 search (e.g. "mesh*."). | ||
| 151 | // Preserve the DOS wildcard expression for the extended path and let the filesystem match it, including | ||
| 152 | // short names. The DOS_STAR, DOS_QM and DOS_DOT tokens are defined by MS-FSA 2.1.4.3-4. | ||
| 153 | std::wstring mask = search.filename().native(); | ||
| 154 | if (mask.ends_with(L'*')) mask.back() = L'<'; | ||
| 155 | else mask.push_back(L'"'); | ||
| 156 | for (size_t i = 0; i + 1 < mask.size(); ++i) { | ||
| 157 | const wchar_t next = mask[i + 1]; | ||
| 158 | if (mask[i] == L'?') mask[i] = L'>'; | ||
| 159 | else if (mask[i] == L'*' && next == L'.') mask[i] = L'<'; | ||
| 160 | else if (mask[i] == L'.' && (next == L'*' || next == L'?' || next == L'<')) mask[i] = L'"'; | ||
| 161 | } | ||
| 162 | return search.parent_path() / mask; | ||
| 163 | } | ||
| 164 | |||
| 122 | // "G:\x" is the installed package, like "GAME:\x", and "T:\x" a scratch folder the title may write to, the way the | 165 | // "G:\x" is the installed package, like "GAME:\x", and "T:\x" a scratch folder the title may write to, the way the |
| 123 | // other console layers map those two drives (RT-218). Only the executable can say which spelling the title uses, so | 166 | // other console layers map those two drives (RT-218). Only the executable can say which spelling the title uses, so |
| 124 | // a host drive of the same letter must keep working: a path under --game-dir or the overlay (a package on drive G:, | 167 | // a host drive of the same letter must keep working: a path under --game-dir or the overlay (a package on drive G:, |
| @@ -151,7 +194,7 @@ Parsed parse_console(const std::wstring& path, std::vector<std::wstring>& parts) | |||
| 151 | const std::filesystem::path overlay = roots().overlay; | 194 | const std::filesystem::path overlay = roots().overlay; |
| 152 | const DWORD last_error = ::GetLastError(); | 195 | const DWORD last_error = ::GetLastError(); |
| 153 | std::error_code ec; | 196 | std::error_code ec; |
| 154 | if (!overlay.empty()) std::filesystem::create_directories(overlay / kScratchDir, ec); | 197 | if (!overlay.empty()) std::filesystem::create_directories(win32_io_path(overlay / kScratchDir), ec); |
| 155 | ::SetLastError(last_error); | 198 | ::SetLastError(last_error); |
| 156 | } | 199 | } |
| 157 | const size_t floor = parts.size(); // ".." may not climb out of the drive's own root | 200 | const size_t floor = parts.size(); // ".." may not climb out of the drive's own root |
| @@ -194,6 +237,10 @@ std::filesystem::path join(const std::filesystem::path& root, const std::vector< | |||
| 194 | return p; | 237 | return p; |
| 195 | } | 238 | } |
| 196 | 239 | ||
| 240 | std::filesystem::path disk_path(const std::filesystem::path& root, const std::vector<std::wstring>& parts) { | ||
| 241 | return win32_io_path(join(root, parts)); | ||
| 242 | } | ||
| 243 | |||
| 197 | bool drive_root(const std::wstring& path, const std::vector<std::wstring>& parts) { | 244 | bool drive_root(const std::wstring& path, const std::vector<std::wstring>& parts) { |
| 198 | size_t prefix_length = 0; | 245 | size_t prefix_length = 0; |
| 199 | return parts.empty() || (parts.size() == 1 && console_drive(path, prefix_length) == Drive::Scratch); | 246 | return parts.empty() || (parts.size() == 1 && console_drive(path, prefix_length) == Drive::Scratch); |
| @@ -224,11 +271,13 @@ bool deleted(const std::filesystem::path& overlay, const std::vector<std::wstrin | |||
| 224 | // Only regular files are deletion markers; parent directories inside .gta6rt-deleted/ exist only to hold markers | 271 | // Only regular files are deletion markers; parent directories inside .gta6rt-deleted/ exist only to hold markers |
| 225 | // for nested deleted files and must not hide the corresponding ancestor directories in the package. | 272 | // for nested deleted files and must not hide the corresponding ancestor directories in the package. |
| 226 | const std::filesystem::path m = marker(overlay, parts); | 273 | const std::filesystem::path m = marker(overlay, parts); |
| 227 | return std::filesystem::is_regular_file(m, ec) || std::filesystem::is_regular_file(m / kRemovedDirMarker, ec); | 274 | return std::filesystem::is_regular_file(win32_io_path(m), ec) || |
| 275 | std::filesystem::is_regular_file(win32_io_path(m / kRemovedDirMarker), ec); | ||
| 228 | } | 276 | } |
| 229 | 277 | ||
| 230 | // Writes an empty hidden marker file. On failure `error` holds the reason. | 278 | // Writes an empty hidden marker file. On failure `error` holds the reason. |
| 231 | bool write_marker(const std::filesystem::path& mark, DWORD& error) { | 279 | bool write_marker(const std::filesystem::path& path, DWORD& error) { |
| 280 | const std::filesystem::path mark = win32_io_path(path); | ||
| 232 | std::error_code ec; | 281 | std::error_code ec; |
| 233 | std::filesystem::create_directories(mark.parent_path(), ec); | 282 | std::filesystem::create_directories(mark.parent_path(), ec); |
| 234 | if (ec) { | 283 | if (ec) { |
| @@ -247,7 +296,7 @@ bool write_marker(const std::filesystem::path& mark, DWORD& error) { | |||
| 247 | 296 | ||
| 248 | // Flushes a file the shim wrote on the title's behalf, for MOVEFILE_WRITE_THROUGH. On failure `error` holds the reason. | 297 | // Flushes a file the shim wrote on the title's behalf, for MOVEFILE_WRITE_THROUGH. On failure `error` holds the reason. |
| 249 | bool flush_file(const std::filesystem::path& path, DWORD& error) { | 298 | bool flush_file(const std::filesystem::path& path, DWORD& error) { |
| 250 | const HANDLE h = ::CreateFileW(path.c_str(), GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, | 299 | const HANDLE h = ::CreateFileW(win32_io_path(path).c_str(), GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, |
| 251 | nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); | 300 | nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); |
| 252 | if (h == INVALID_HANDLE_VALUE) { | 301 | if (h == INVALID_HANDLE_VALUE) { |
| 253 | error = ::GetLastError(); | 302 | error = ::GetLastError(); |
| @@ -276,14 +325,14 @@ View view(const Roots& r, const std::vector<std::wstring>& parts) { | |||
| 276 | return v; | 325 | return v; |
| 277 | } | 326 | } |
| 278 | if (!r.overlay.empty()) { | 327 | if (!r.overlay.empty()) { |
| 279 | const std::filesystem::path p = join(r.overlay, parts); | 328 | const std::filesystem::path p = disk_path(r.overlay, parts); |
| 280 | if (std::filesystem::exists(p, ec)) { | 329 | if (std::filesystem::exists(p, ec)) { |
| 281 | v.in_overlay = true; | 330 | v.in_overlay = true; |
| 282 | v.kind = std::filesystem::is_directory(p, ec) ? Kind::Directory : Kind::File; | 331 | v.kind = std::filesystem::is_directory(p, ec) ? Kind::Directory : Kind::File; |
| 283 | } | 332 | } |
| 284 | } | 333 | } |
| 285 | if (!r.game.empty() && !deleted(r.overlay, parts)) { | 334 | if (!r.game.empty() && !deleted(r.overlay, parts)) { |
| 286 | const std::filesystem::path p = join(r.game, parts); | 335 | const std::filesystem::path p = disk_path(r.game, parts); |
| 287 | if (std::filesystem::exists(p, ec)) { | 336 | if (std::filesystem::exists(p, ec)) { |
| 288 | v.in_package = true; | 337 | v.in_package = true; |
| 289 | if (v.kind == Kind::None) v.kind = std::filesystem::is_directory(p, ec) ? Kind::Directory : Kind::File; | 338 | if (v.kind == Kind::None) v.kind = std::filesystem::is_directory(p, ec) ? Kind::Directory : Kind::File; |
| @@ -310,7 +359,7 @@ std::vector<std::wstring> parent_of(const std::vector<std::wstring>& parts) { | |||
| 310 | bool empty_in_view(const Roots& r, const std::vector<std::wstring>& parts) { | 359 | bool empty_in_view(const Roots& r, const std::vector<std::wstring>& parts) { |
| 311 | std::error_code ec; | 360 | std::error_code ec; |
| 312 | if (!r.overlay.empty()) { | 361 | if (!r.overlay.empty()) { |
| 313 | const std::filesystem::path p = join(r.overlay, parts); | 362 | const std::filesystem::path p = disk_path(r.overlay, parts); |
| 314 | for (auto it = std::filesystem::directory_iterator(p, ec); !ec && it != std::filesystem::directory_iterator(); | 363 | for (auto it = std::filesystem::directory_iterator(p, ec); !ec && it != std::filesystem::directory_iterator(); |
| 315 | it.increment(ec)) { | 364 | it.increment(ec)) { |
| 316 | if (parts.empty() && internal_dir(it->path().filename().c_str())) continue; | 365 | if (parts.empty() && internal_dir(it->path().filename().c_str())) continue; |
| @@ -319,7 +368,7 @@ bool empty_in_view(const Roots& r, const std::vector<std::wstring>& parts) { | |||
| 319 | } | 368 | } |
| 320 | ec.clear(); | 369 | ec.clear(); |
| 321 | if (!r.game.empty()) { | 370 | if (!r.game.empty()) { |
| 322 | const std::filesystem::path p = join(r.game, parts); | 371 | const std::filesystem::path p = disk_path(r.game, parts); |
| 323 | for (auto it = std::filesystem::directory_iterator(p, ec); !ec && it != std::filesystem::directory_iterator(); | 372 | for (auto it = std::filesystem::directory_iterator(p, ec); !ec && it != std::filesystem::directory_iterator(); |
| 324 | it.increment(ec)) { | 373 | it.increment(ec)) { |
| 325 | std::vector<std::wstring> child = parts; | 374 | std::vector<std::wstring> child = parts; |
| @@ -350,7 +399,7 @@ Target read_target(const std::wstring& path) { | |||
| 350 | 399 | ||
| 351 | std::error_code ec; | 400 | std::error_code ec; |
| 352 | if (!r.overlay.empty()) { | 401 | if (!r.overlay.empty()) { |
| 353 | const std::filesystem::path overlay_path = join(r.overlay, parts); | 402 | const std::filesystem::path overlay_path = disk_path(r.overlay, parts); |
| 354 | if (std::filesystem::exists(overlay_path, ec)) { | 403 | if (std::filesystem::exists(overlay_path, ec)) { |
| 355 | Target t; | 404 | Target t; |
| 356 | t.path = overlay_path; | 405 | t.path = overlay_path; |
| @@ -361,7 +410,7 @@ Target read_target(const std::wstring& path) { | |||
| 361 | if (deleted(r.overlay, parts)) return fail(ERROR_FILE_NOT_FOUND); | 410 | if (deleted(r.overlay, parts)) return fail(ERROR_FILE_NOT_FOUND); |
| 362 | 411 | ||
| 363 | Target t; | 412 | Target t; |
| 364 | t.path = join(r.game, parts); | 413 | t.path = disk_path(r.game, parts); |
| 365 | return t; | 414 | return t; |
| 366 | } | 415 | } |
| 367 | 416 | ||
| @@ -388,7 +437,7 @@ Target write_target(const std::wstring& path, bool copy_up) { | |||
| 388 | if (!scratch && !is_folder(r, parent_of(parts))) return fail(ERROR_PATH_NOT_FOUND); | 437 | if (!scratch && !is_folder(r, parent_of(parts))) return fail(ERROR_PATH_NOT_FOUND); |
| 389 | 438 | ||
| 390 | Target t; | 439 | Target t; |
| 391 | t.path = join(r.overlay, parts); | 440 | t.path = disk_path(r.overlay, parts); |
| 392 | 441 | ||
| 393 | std::error_code ec; | 442 | std::error_code ec; |
| 394 | std::filesystem::create_directories(t.path.parent_path(), ec); | 443 | std::filesystem::create_directories(t.path.parent_path(), ec); |
| @@ -400,7 +449,7 @@ Target write_target(const std::wstring& path, bool copy_up) { | |||
| 400 | // A deleted package file is not there to copy: copying it up would bring the name back, and an open that keeps | 449 | // A deleted package file is not there to copy: copying it up would bring the name back, and an open that keeps |
| 401 | // the contents (OPEN_EXISTING, TRUNCATE_EXISTING) has to fail on it instead. CREATE_ALWAYS and CREATE_NEW still | 450 | // the contents (OPEN_EXISTING, TRUNCATE_EXISTING) has to fail on it instead. CREATE_ALWAYS and CREATE_NEW still |
| 402 | // make a new overlay file, which reads prefer over the package and so over the marker. | 451 | // make a new overlay file, which reads prefer over the package and so over the marker. |
| 403 | const std::filesystem::path package_path = join(r.game, parts); | 452 | const std::filesystem::path package_path = disk_path(r.game, parts); |
| 404 | // One copy-up at a time: a second thread writing the same file waits here and then finds the first one's copy, so | 453 | // One copy-up at a time: a second thread writing the same file waits here and then finds the first one's copy, so |
| 405 | // it neither fails on the taken name nor collides with that file's open through a rename of its own. | 454 | // it neither fails on the taken name nor collides with that file's open through a rename of its own. |
| 406 | static std::mutex s_copy_mutex; | 455 | static std::mutex s_copy_mutex; |
| @@ -412,9 +461,9 @@ Target write_target(const std::wstring& path, bool copy_up) { | |||
| 412 | // not a truncated file that reads would prefer over the package. | 461 | // not a truncated file that reads would prefer over the package. |
| 413 | static unsigned s_copies = 0; // under s_copy_mutex | 462 | static unsigned s_copies = 0; // under s_copy_mutex |
| 414 | const std::filesystem::path staging = r.overlay / kCopyDir; | 463 | const std::filesystem::path staging = r.overlay / kCopyDir; |
| 415 | std::filesystem::create_directories(staging, ec); | 464 | std::filesystem::create_directories(win32_io_path(staging), ec); |
| 416 | const std::filesystem::path tmp = | 465 | const std::filesystem::path tmp = |
| 417 | staging / (std::to_wstring(::GetCurrentProcessId()) + L"-" + std::to_wstring(++s_copies)); | 466 | win32_io_path(staging / (std::to_wstring(::GetCurrentProcessId()) + L"-" + std::to_wstring(++s_copies))); |
| 418 | // Use CopyFileW for staging because MSVC's std::filesystem::copy_file calls CopyFile2, which Wine 9 lacks. | 467 | // Use CopyFileW for staging because MSVC's std::filesystem::copy_file calls CopyFile2, which Wine 9 lacks. |
| 419 | if (ec) { | 468 | if (ec) { |
| 420 | t.error = static_cast<DWORD>(ec.value()); | 469 | t.error = static_cast<DWORD>(ec.value()); |
| @@ -530,7 +579,7 @@ bool collect(const std::wstring& pattern, const std::vector<std::wstring>& parts | |||
| 530 | if (!r.overlay.empty()) { | 579 | if (!r.overlay.empty()) { |
| 531 | const std::filesystem::path marks = marker(r.overlay, dirs); | 580 | const std::filesystem::path marks = marker(r.overlay, dirs); |
| 532 | WIN32_FIND_DATAW m{}; | 581 | WIN32_FIND_DATAW m{}; |
| 533 | const HANDLE mh = ::FindFirstFileW((marks / L"*").c_str(), &m); | 582 | const HANDLE mh = ::FindFirstFileW(win32_io_path(marks / L"*").c_str(), &m); |
| 534 | if (mh != INVALID_HANDLE_VALUE) { | 583 | if (mh != INVALID_HANDLE_VALUE) { |
| 535 | has_markers = true; | 584 | has_markers = true; |
| 536 | do { | 585 | do { |
| @@ -547,7 +596,7 @@ bool collect(const std::wstring& pattern, const std::vector<std::wstring>& parts | |||
| 547 | // markers of a nested delete. A missing sentinel is that ordinary answer (status() reports not_found | 596 | // markers of a nested delete. A missing sentinel is that ordinary answer (status() reports not_found |
| 548 | // with an error code set); any other error leaves the decision to deleted() per entry. | 597 | // with an error code set); any other error leaves the decision to deleted() per entry. |
| 549 | std::error_code ec; | 598 | std::error_code ec; |
| 550 | const auto st = std::filesystem::status(marks / m.cFileName / kRemovedDirMarker, ec); | 599 | const auto st = std::filesystem::status(win32_io_path(marks / m.cFileName / kRemovedDirMarker), ec); |
| 551 | if (st.type() == std::filesystem::file_type::regular) deleted_here.insert(ascii_key(m.cFileName)); | 600 | if (st.type() == std::filesystem::file_type::regular) deleted_here.insert(ascii_key(m.cFileName)); |
| 552 | else if (st.type() != std::filesystem::file_type::not_found && ec) markers_exact = false; | 601 | else if (st.type() != std::filesystem::file_type::not_found && ec) markers_exact = false; |
| 553 | } while (::FindNextFileW(mh, &m)); | 602 | } while (::FindNextFileW(mh, &m)); |
| @@ -580,10 +629,8 @@ bool collect(const std::wstring& pattern, const std::vector<std::wstring>& parts | |||
| 580 | 629 | ||
| 581 | auto add_root = [&](const std::filesystem::path& root, bool overlay_root) { | 630 | auto add_root = [&](const std::filesystem::path& root, bool overlay_root) { |
| 582 | if (root.empty()) return; | 631 | if (root.empty()) return; |
| 583 | std::filesystem::path search = join(root, dirs); | ||
| 584 | search /= leaf; | ||
| 585 | WIN32_FIND_DATAW found{}; | 632 | WIN32_FIND_DATAW found{}; |
| 586 | const HANDLE h = ::FindFirstFileW(search.c_str(), &found); | 633 | const HANDLE h = ::FindFirstFileW(win32_find_path(join(root, dirs) / leaf, leaf).c_str(), &found); |
| 587 | if (h == INVALID_HANDLE_VALUE) return; | 634 | if (h == INVALID_HANDLE_VALUE) return; |
| 588 | do { | 635 | do { |
| 589 | if (overlay_root && internal_dir(found.cFileName)) continue; | 636 | if (overlay_root && internal_dir(found.cFileName)) continue; |
| @@ -917,13 +964,13 @@ BOOL WINAPI delete_file_w(LPCWSTR name) { | |||
| 917 | 964 | ||
| 918 | bool removed = false; | 965 | bool removed = false; |
| 919 | std::error_code ec; | 966 | std::error_code ec; |
| 920 | const std::filesystem::path overlay_path = join(r.overlay, parts); | 967 | const std::filesystem::path overlay_path = disk_path(r.overlay, parts); |
| 921 | if (std::filesystem::exists(overlay_path, ec)) { | 968 | if (std::filesystem::exists(overlay_path, ec)) { |
| 922 | if (!::DeleteFileW(overlay_path.c_str())) return FALSE; | 969 | if (!::DeleteFileW(overlay_path.c_str())) return FALSE; |
| 923 | removed = true; | 970 | removed = true; |
| 924 | } | 971 | } |
| 925 | if (!r.game.empty() && !deleted(r.overlay, parts)) { | 972 | if (!r.game.empty() && !deleted(r.overlay, parts)) { |
| 926 | const std::filesystem::path package_path = join(r.game, parts); | 973 | const std::filesystem::path package_path = disk_path(r.game, parts); |
| 927 | if (std::filesystem::exists(package_path, ec)) { | 974 | if (std::filesystem::exists(package_path, ec)) { |
| 928 | if (std::filesystem::is_directory(package_path, ec)) { | 975 | if (std::filesystem::is_directory(package_path, ec)) { |
| 929 | SetLastError(ERROR_ACCESS_DENIED); | 976 | SetLastError(ERROR_ACCESS_DENIED); |
| @@ -982,7 +1029,7 @@ BOOL create_directory(LPCWSTR template_name, LPCWSTR name, LPSECURITY_ATTRIBUTES | |||
| 982 | if (view(r, parts).kind != Kind::None) return fail_bool(ERROR_ALREADY_EXISTS); // "GAME:" included | 1029 | if (view(r, parts).kind != Kind::None) return fail_bool(ERROR_ALREADY_EXISTS); // "GAME:" included |
| 983 | if (!is_folder(r, parent_of(parts))) return fail_bool(ERROR_PATH_NOT_FOUND); | 1030 | if (!is_folder(r, parent_of(parts))) return fail_bool(ERROR_PATH_NOT_FOUND); |
| 984 | 1031 | ||
| 985 | const std::filesystem::path target = join(r.overlay, parts); | 1032 | const std::filesystem::path target = disk_path(r.overlay, parts); |
| 986 | std::error_code ec; | 1033 | std::error_code ec; |
| 987 | std::filesystem::create_directories(target.parent_path(), ec); | 1034 | std::filesystem::create_directories(target.parent_path(), ec); |
| 988 | if (ec) return fail_bool(static_cast<DWORD>(ec.value())); | 1035 | if (ec) return fail_bool(static_cast<DWORD>(ec.value())); |
| @@ -1038,7 +1085,7 @@ BOOL WINAPI remove_directory_w(LPCWSTR name) { | |||
| 1038 | if (v.kind == Kind::File) return fail_bool(ERROR_DIRECTORY); | 1085 | if (v.kind == Kind::File) return fail_bool(ERROR_DIRECTORY); |
| 1039 | if (!empty_in_view(r, parts)) return fail_bool(ERROR_DIR_NOT_EMPTY); | 1086 | if (!empty_in_view(r, parts)) return fail_bool(ERROR_DIR_NOT_EMPTY); |
| 1040 | 1087 | ||
| 1041 | if (v.in_overlay && !::RemoveDirectoryW(join(r.overlay, parts).c_str())) return FALSE; // its error | 1088 | if (v.in_overlay && !::RemoveDirectoryW(disk_path(r.overlay, parts).c_str())) return FALSE; // its error |
| 1042 | if (v.in_package) { | 1089 | if (v.in_package) { |
| 1043 | // The package folder stays where it is; the marker hides it, and its files are already hidden one by one. | 1090 | // The package folder stays where it is; the marker hides it, and its files are already hidden one by one. |
| 1044 | DWORD error = 0; | 1091 | DWORD error = 0; |
| @@ -1072,7 +1119,7 @@ BOOL WINAPI move_file_ex_w(LPCWSTR from, LPCWSTR to, DWORD flags) { | |||
| 1072 | if (drive_root(from, src) || drive_root(to, dst)) return fail_bool(ERROR_ACCESS_DENIED); | 1119 | if (drive_root(from, src) || drive_root(to, dst)) return fail_bool(ERROR_ACCESS_DENIED); |
| 1073 | const View from_view = view(r, src); | 1120 | const View from_view = view(r, src); |
| 1074 | if (from_view.kind == Kind::None) return fail_bool(ERROR_FILE_NOT_FOUND); | 1121 | if (from_view.kind == Kind::None) return fail_bool(ERROR_FILE_NOT_FOUND); |
| 1075 | const std::filesystem::path overlay_from = join(r.overlay, src), overlay_to = join(r.overlay, dst); | 1122 | const std::filesystem::path overlay_from = disk_path(r.overlay, src), overlay_to = disk_path(r.overlay, dst); |
| 1076 | if (same_entry(src, dst)) { | 1123 | if (same_entry(src, dst)) { |
| 1077 | // The destination is the source, so it is not "already there". The host succeeds at a move onto the same | 1124 | // The destination is the source, so it is not "already there". The host succeeds at a move onto the same |
| 1078 | // name and changes nothing, and renames when only the case differs. Here the case of a name is the overlay's | 1125 | // name and changes nothing, and renames when only the case differs. Here the case of a name is the overlay's |
| @@ -1086,7 +1133,7 @@ BOOL WINAPI move_file_ex_w(LPCWSTR from, LPCWSTR to, DWORD flags) { | |||
| 1086 | std::error_code same_ec; | 1133 | std::error_code same_ec; |
| 1087 | std::filesystem::create_directories(overlay_to.parent_path(), same_ec); | 1134 | std::filesystem::create_directories(overlay_to.parent_path(), same_ec); |
| 1088 | if (same_ec) return fail_bool(static_cast<DWORD>(same_ec.value())); | 1135 | if (same_ec) return fail_bool(static_cast<DWORD>(same_ec.value())); |
| 1089 | if (!::CopyFileW(join(r.game, src).c_str(), overlay_to.c_str(), TRUE)) return FALSE; | 1136 | if (!::CopyFileW(disk_path(r.game, src).c_str(), overlay_to.c_str(), TRUE)) return FALSE; |
| 1090 | DWORD flush_error = 0; | 1137 | DWORD flush_error = 0; |
| 1091 | if ((flags & MOVEFILE_WRITE_THROUGH) != 0 && !flush_file(overlay_to, flush_error)) return fail_bool(flush_error); | 1138 | if ((flags & MOVEFILE_WRITE_THROUGH) != 0 && !flush_file(overlay_to, flush_error)) return fail_bool(flush_error); |
| 1092 | return TRUE; | 1139 | return TRUE; |
| @@ -1117,7 +1164,7 @@ BOOL WINAPI move_file_ex_w(LPCWSTR from, LPCWSTR to, DWORD flags) { | |||
| 1117 | // The host never sees a move here, only a copy and a marker, so MOVEFILE_WRITE_THROUGH is honoured by | 1164 | // The host never sees a move here, only a copy and a marker, so MOVEFILE_WRITE_THROUGH is honoured by |
| 1118 | // flushing both before returning, as MoveFileEx does for its own copy and delete. | 1165 | // flushing both before returning, as MoveFileEx does for its own copy and delete. |
| 1119 | const BOOL fail_if_exists = (flags & MOVEFILE_REPLACE_EXISTING) == 0; | 1166 | const BOOL fail_if_exists = (flags & MOVEFILE_REPLACE_EXISTING) == 0; |
| 1120 | if (!::CopyFileW(join(r.game, src).c_str(), overlay_to.c_str(), fail_if_exists)) return FALSE; | 1167 | if (!::CopyFileW(disk_path(r.game, src).c_str(), overlay_to.c_str(), fail_if_exists)) return FALSE; |
| 1121 | if (write_through && !flush_file(overlay_to, error)) return fail_bool(error); | 1168 | if (write_through && !flush_file(overlay_to, error)) return fail_bool(error); |
| 1122 | } | 1169 | } |
| 1123 | if (from_view.in_package) { | 1170 | if (from_view.in_package) { |
| @@ -1167,7 +1214,7 @@ bool copy_destination(LPCWSTR to, bool fail_if_exists, std::filesystem::path& ou | |||
| 1167 | if (v.kind == Kind::File && fail_if_exists) return false; | 1214 | if (v.kind == Kind::File && fail_if_exists) return false; |
| 1168 | error = ERROR_PATH_NOT_FOUND; | 1215 | error = ERROR_PATH_NOT_FOUND; |
| 1169 | if (!is_folder(r, parent_of(parts))) return false; | 1216 | if (!is_folder(r, parent_of(parts))) return false; |
| 1170 | out = join(r.overlay, parts); | 1217 | out = disk_path(r.overlay, parts); |
| 1171 | std::error_code ec; | 1218 | std::error_code ec; |
| 1172 | std::filesystem::create_directories(out.parent_path(), ec); | 1219 | std::filesystem::create_directories(out.parent_path(), ec); |
| 1173 | if (ec) { | 1220 | if (ec) { |
| @@ -1326,7 +1373,7 @@ BOOL WINAPI set_file_attributes_w(LPCWSTR name, DWORD attributes) { | |||
| 1326 | 1373 | ||
| 1327 | // The attributes belong to the overlay copy: a package file is copied up and a package folder mirrored first, | 1374 | // The attributes belong to the overlay copy: a package file is copied up and a package folder mirrored first, |
| 1328 | // so the package keeps its own attributes and reads, which prefer the overlay, see the new ones. | 1375 | // so the package keeps its own attributes and reads, which prefer the overlay, see the new ones. |
| 1329 | const std::filesystem::path target = join(r.overlay, parts); | 1376 | const std::filesystem::path target = disk_path(r.overlay, parts); |
| 1330 | if (!v.in_overlay) { | 1377 | if (!v.in_overlay) { |
| 1331 | std::error_code ec; | 1378 | std::error_code ec; |
| 1332 | if (v.kind == Kind::Directory) { | 1379 | if (v.kind == Kind::Directory) { |