host/fs: propagate child failures before parent cleanup

Check the child result and saved directory-read error before returning
from recursive delete and clean. Restore the error after closing the
directory, and call rmdir only after every child succeeded. This makes
error propagation explicit and removes the new undefined-errno finding
reported through the recursive-delete tests.

Validation: filesystem, mutation and commit-list tests pass (761 checks);
LLVM 23.1.4 reports no findings above the existing baseline. Mac host and
documentation checks pass.

Co-authored-by: seedds <[email protected]>
This commit is contained in:
seeddsandseedds committed 2026-11-17 15:37:37 +08:00
1 parent 42c91e1c8b
commit b04c42b0dd
2 files changed
+5 -5

No files matched your search

+4 -4
View File
@@ -1252,8 +1252,8 @@ static int rm_tree(const char *p) {
if ((rc = rm_entry(c))) break; // keep the first failure, before readdir can clear errno
}
int err = errno; closedir(d);
if (err) { errno = err; return -1; }
return rc | rmdir(p);
if (rc || err) { errno = err; return -1; }
return rmdir(p);
}
HLE_FORCE("_ZN2nn2fs26DeleteDirectoryRecursivelyEPKc", "fsp-srv → recursive delete (only inside writable mounts)", Result, h_fs_DeleteDirRec, const char *path) { dm_thread_service_request();
SDK_PATH(path, "_ZN2nn2fs26DeleteDirectoryRecursivelyEPKc", Result (*)(const char *), path);
@@ -1270,8 +1270,8 @@ HLE_FORCE("_ZN2nn2fs25CleanDirectoryRecursivelyEPKc", "fsp-srv → recursively d
if ((rc = rm_entry(c))) break;
}
int err = errno; closedir(d);
if (err) { errno = err; return save_path_error("cleandir", path); }
return rc ? save_path_error("cleandir", path) : RES_OK;
if (rc || err) { errno = err; return save_path_error("cleandir", path); }
return RES_OK;
}
// file data cache (a global read cache in the fs process): the host reads through the page cache and leaves the buffer unused
HLE_FORCE("_ZN2nn2fs25EnableGlobalFileDataCacheEPvm", "fsp-srv global read cache; unused by the host", void, h_fs_EnableGlobalCache, void *buf, size_t sz) { (void)buf; (void)sz; }
+1 -1
View File
@@ -239,7 +239,7 @@ Most service calls can be found before they crash, before the first boot or the
- **Symptom:** after an unexpected host error while creating, opening for writing, deleting or renaming a save entry, `Commit` could publish the other changes in the working directory without the failed change.
- **Cause:** writes and size changes through file handles marked the backing transaction failed, but path lookup and most path mutations did not. A recursive delete also continued after a child failed, letting the next directory read replace its error.
- **Fix:** unexpected mutation failures mark the transaction by its exact guest mount name, even when lookup failed before a physical path existed. Aliases share the backing transaction's marker; read-only and non-save mounts do not mark it. Ordinary missing, existing, type, not-empty and invalid-name results (what Horizon answers too) remain unmarked; a rename whose name metadata and rollback both fail marks it whatever the first error, since the entry stays at the new path. Recursive deletion stops at the first failure and preserves it. The existing commit refusal restores the committed version and notifies the front end; the next complete save can succeed.
- **Fix:** unexpected mutation failures mark the transaction by its exact guest mount name, even when lookup failed before a physical path existed. Aliases share the backing transaction's marker; read-only and non-save mounts do not mark it. Ordinary missing, existing, type, not-empty and invalid-name results (what Horizon answers too) remain unmarked; a rename whose name metadata and rollback both fail marks it whatever the first error, since the entry stays at the new path. Recursive deletion and cleaning check the child result as well as the saved directory-read error before returning, restoring that error after closing the directory; deletion calls `rmdir` only after every child succeeded. This also keeps the analyzer from treating a failed child followed by a successful `rmdir` as a failure with undefined `errno`. The existing commit refusal restores the committed version and notifies the front end; the next complete save can succeed.
- **Found on:** the [synthetic save-mutation regression](../../dm/host/tests/t_fs_mutation.c), following the filesystem lead in [issue #1692](https://github.com/seedds/nxnative/issues/1692) for [Ocarina of Time](../../dm/games/0400486024DEC000/README.md). The cause of that game's area-transition crash and subsequent black screen remains unconfirmed; this correction does not establish that connection or repair an already damaged save.
### A save folder that cannot clone directories