mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-21 12:55:57 +00:00
Delete read-only folders and cloud placeholders of an old save working copy, retry for 2 s, and name the failing path in the fatal
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6c2595275d
commit
d3f403ecf6
4 files changed
+80
-13
No files matched your search
@@ -1038,6 +1038,8 @@ const void *plat_file_map(PlatFile *f) {
|
||||
return v == MAP_FAILED ? NULL : v;
|
||||
}
|
||||
|
||||
int plat_fs_os_error(void) { return errno; }
|
||||
|
||||
static int fs_err(int e) {
|
||||
switch (e) {
|
||||
case ENOENT: case ENOTDIR: return PLAT_FS_NOT_FOUND;
|
||||
|
||||
@@ -316,8 +316,9 @@ enum { PLAT_FS_OK, PLAT_FS_NOT_FOUND, PLAT_FS_EXISTS, PLAT_FS_NOT_EMPTY, PLAT_FS
|
||||
enum { PLAT_FS_MISSING = -1, PLAT_FS_FILE, PLAT_FS_DIR, PLAT_FS_LINK }; // plat_fs_kind; LINK: a symbolic link or
|
||||
// reparse point, never followed
|
||||
int plat_fs_kind(const char *path);
|
||||
int plat_fs_os_error(void); // the OS error code (GetLastError, errno) of this thread's last failed plat_fs_* call
|
||||
int plat_fs_mkdir(const char *path); // PLAT_FS_EXISTS when something is there
|
||||
int plat_fs_rmdir(const char *path); // an empty directory, or a link to one
|
||||
int plat_fs_rmdir(const char *path); // an empty directory (a read-only one too), or a link to one
|
||||
int plat_fs_unlink(const char *path); // a file or a link; a read-only one too
|
||||
// Renames a file or directory; never replaces (PLAT_FS_EXISTS). durable: the change is on the disk at return.
|
||||
int plat_fs_rename(const char *from, const char *to, int durable);
|
||||
|
||||
@@ -866,7 +866,11 @@ const void *plat_file_map(PlatFile *f) {
|
||||
return v;
|
||||
}
|
||||
|
||||
static __thread DWORD fs_last_error;
|
||||
int plat_fs_os_error(void) { return (int)fs_last_error; }
|
||||
|
||||
static int fs_err(DWORD e) {
|
||||
fs_last_error = e;
|
||||
switch (e) {
|
||||
case ERROR_FILE_NOT_FOUND: case ERROR_PATH_NOT_FOUND: case ERROR_DIRECTORY: return PLAT_FS_NOT_FOUND;
|
||||
case ERROR_FILE_EXISTS: case ERROR_ALREADY_EXISTS: return PLAT_FS_EXISTS;
|
||||
@@ -876,12 +880,23 @@ static int fs_err(DWORD e) {
|
||||
}
|
||||
}
|
||||
|
||||
// A symbolic link or junction is a link: removed as a link, never followed. Any other reparse point (OneDrive's cloud
|
||||
// placeholders, deduplicated files) is an ordinary file or directory whose content the file system fetches on access.
|
||||
static int fs_kind_of(const WIN32_FIND_DATAW *fd) {
|
||||
DWORD a = fd->dwFileAttributes;
|
||||
if (a & FILE_ATTRIBUTE_REPARSE_POINT && (fd->dwReserved0 == IO_REPARSE_TAG_SYMLINK || fd->dwReserved0 == IO_REPARSE_TAG_MOUNT_POINT))
|
||||
return PLAT_FS_LINK;
|
||||
return a & FILE_ATTRIBUTE_DIRECTORY ? PLAT_FS_DIR : PLAT_FS_FILE;
|
||||
}
|
||||
|
||||
int plat_fs_kind(const char *path) {
|
||||
wchar_t w[WPATH];
|
||||
if (!widen(path, w, WPATH)) return PLAT_FS_MISSING;
|
||||
DWORD a = GetFileAttributesW(w);
|
||||
if (a == INVALID_FILE_ATTRIBUTES) return PLAT_FS_MISSING;
|
||||
return a & FILE_ATTRIBUTE_REPARSE_POINT ? PLAT_FS_LINK : a & FILE_ATTRIBUTE_DIRECTORY ? PLAT_FS_DIR : PLAT_FS_FILE;
|
||||
WIN32_FIND_DATAW fd;
|
||||
HANDLE h = FindFirstFileW(w, &fd); // the reparse tag comes with the find data only
|
||||
if (h == INVALID_HANDLE_VALUE) return PLAT_FS_MISSING;
|
||||
FindClose(h);
|
||||
return fs_kind_of(&fd);
|
||||
}
|
||||
|
||||
int plat_fs_mkdir(const char *path) {
|
||||
@@ -893,7 +908,15 @@ int plat_fs_mkdir(const char *path) {
|
||||
int plat_fs_rmdir(const char *path) {
|
||||
wchar_t w[WPATH];
|
||||
if (!widen(path, w, WPATH)) return PLAT_FS_ERROR;
|
||||
return RemoveDirectoryW(w) ? PLAT_FS_OK : fs_err(GetLastError());
|
||||
if (RemoveDirectoryW(w)) return PLAT_FS_OK;
|
||||
DWORD e = GetLastError(), a = GetFileAttributesW(w);
|
||||
if (e == ERROR_ACCESS_DENIED && a != INVALID_FILE_ATTRIBUTES && (a & FILE_ATTRIBUTE_READONLY)) {
|
||||
// a read-only directory (copied over from another emulator's save folder) refuses RemoveDirectoryW
|
||||
SetFileAttributesW(w, a & ~(DWORD)FILE_ATTRIBUTE_READONLY);
|
||||
if (RemoveDirectoryW(w)) return PLAT_FS_OK;
|
||||
e = GetLastError();
|
||||
}
|
||||
return fs_err(e);
|
||||
}
|
||||
|
||||
int plat_fs_unlink(const char *path) {
|
||||
@@ -1038,9 +1061,7 @@ int plat_fs_list(const char *dir, int (*cb)(const char *name, int kind, uint64_t
|
||||
if (!wcscmp(fd.cFileName, L".") || !wcscmp(fd.cFileName, L"..")) continue;
|
||||
char name[1024];
|
||||
if (!WideCharToMultiByte(CP_UTF8, 0, fd.cFileName, -1, name, sizeof name, NULL, NULL)) continue;
|
||||
DWORD a = fd.dwFileAttributes;
|
||||
int kind = a & FILE_ATTRIBUTE_REPARSE_POINT ? PLAT_FS_LINK : a & FILE_ATTRIBUTE_DIRECTORY ? PLAT_FS_DIR
|
||||
: PLAT_FS_FILE;
|
||||
int kind = fs_kind_of(&fd);
|
||||
if (!cb(name, kind, (uint64_t)fd.nFileSizeHigh << 32 | fd.nFileSizeLow, ctx)) break;
|
||||
} while (FindNextFileW(h, &fd));
|
||||
FindClose(h);
|
||||
|
||||
Reference in new issue
Block a user