fix(libc): report a status error of the rename parent directory instead of ENOENT or ENOTDIR #8217

Merged
xXPBSXx merged 3 commits from upstream-pr/8217 into main 2026-10-21 05:00:41 +00:00
xXPBSXx commented 2026-10-20 03:58:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-20T03:58:13Z.


What

Follow-up to #8174 after MarcZX10's review there. RenameDotError in core/libs/prx/libc/include/RenameDot.hpp classified the parent directory with exists() and is_directory() taking an error_code, which both return false for a missing path and for an error such as permission denied; the code answered ENOENT or ENOTDIR for both and hid the real error. It now reads the parent with status(): a missing path is ENOENT (ENOTDIR when the status reports not_a_directory), any other status error goes through FilesystemError(status), and only a successful status decides between a directory (EINVAL) and a non-directory (ENOTDIR).
Fixes: none (review of #8174)

Tested

Windows 10 (19045), MinGW-w64 GCC 15.2.0, Release, on upstream/main + this commit:

  • guest_rename_dot and guest_filesystem pass (2 of 2).
  • python tools/check_conventions.py --base upstream/main: passes.
  • No new negative test: on Windows I have no reliable way to make the status() of a parent fail with something other than "not found" (permission denied needs an ACL setup the test cannot assume), so this is a code-level correction.
  • Not tested: Linux, a console, a title run.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; no silent stubs added
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • AI-assisted: yes

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4930790911 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8217). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-20T03:58:13Z. --- ### What Follow-up to #8174 after MarcZX10's review there. `RenameDotError` in `core/libs/prx/libc/include/RenameDot.hpp` classified the parent directory with `exists()` and `is_directory()` taking an `error_code`, which both return false for a missing path and for an error such as permission denied; the code answered `ENOENT` or `ENOTDIR` for both and hid the real error. It now reads the parent with `status()`: a missing path is `ENOENT` (`ENOTDIR` when the status reports `not_a_directory`), any other status error goes through `FilesystemError(status)`, and only a successful status decides between a directory (`EINVAL`) and a non-directory (`ENOTDIR`). Fixes: none (review of #8174) ### Tested Windows 10 (19045), MinGW-w64 GCC 15.2.0, Release, on `upstream/main` + this commit: - `guest_rename_dot` and `guest_filesystem` pass (2 of 2). - `python tools/check_conventions.py --base upstream/main`: passes. - No new negative test: on Windows I have no reliable way to make the `status()` of a parent fail with something other than "not found" (permission denied needs an ACL setup the test cannot assume), so this is a code-level correction. - Not tested: Linux, a console, a title run. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw; no silent stubs added - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none - [x] AI-assisted: yes AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
wachi35676 commented 2026-10-20 11:29:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-20T11:29:43Z.


On Linux this change is observable, so the missing negative test can be written. Head 903f73a3a merged onto main 02fb1ce53. A probe calls rename_nid_postfix(from, "target") with relative paths, from a directory that holds dir/, file.txt and a symbolic-link loop loop -> loop.

from Linux main Linux this PR Windows main Windows this PR FreeBSD
file.txt/. ENOENT (2) ENOTDIR (20) ENOTDIR ENOTDIR ENOTDIR
file.txt/.. ENOENT ENOTDIR ENOTDIR ENOTDIR ENOTDIR
file.txt/sub/. ENOENT ENOTDIR ENOENT ENOENT ENOTDIR
loop/. ENOENT ELOOP (62) (no symlink privilege here) (no symlink privilege here) ELOOP
missing/., missing/sub/. ENOENT ENOENT ENOENT ENOENT ENOENT
dir/., dir/.. EINVAL (22) EINVAL EINVAL EINVAL EINVAL
  • Linux: Ubuntu 24.04 (WSL2, run as root), GCC 13.3, Release, BUILD_TESTING=ON. Windows: Windows 11 (10.0.26300), WinLibs GCC 15.2.0 UCRT, Release.
  • guest_rename_dot passes on both hosts, and guest_filesystem passes on Windows (2 runs each). The existing test passes with or without the change, so it does not cover the new branches.
  • file.txt/. (ENOTDIR) and loop/. (ELOOP) on Linux fail on main and pass with this change. Neither needs ACLs or root, so they could go into GuestRenameDot.cpp under #ifndef _WIN32.
  • On Windows, file.txt/sub/. is still ENOENT, because MinGW's status() reports a path under a regular file as not found rather than not_a_directory. That is unchanged from main, but the description's "ENOTDIR when the status reports not_a_directory" does not cover Windows.

AI-assisted: yes (Claude Code); results above were run on this machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6289843966 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8217#issuecomment-6289843966). Originally posted by [wachi35676](https://github.com/wachi35676) on 2026-10-20T11:29:43Z. --- On Linux this change is observable, so the missing negative test can be written. Head `903f73a3a` merged onto `main` `02fb1ce53`. A probe calls `rename_nid_postfix(from, "target")` with relative paths, from a directory that holds `dir/`, `file.txt` and a symbolic-link loop `loop -> loop`. | `from` | Linux `main` | Linux this PR | Windows `main` | Windows this PR | FreeBSD | |---|---|---|---|---|---| | `file.txt/.` | ENOENT (2) | **ENOTDIR (20)** | ENOTDIR | ENOTDIR | ENOTDIR | | `file.txt/..` | ENOENT | **ENOTDIR** | ENOTDIR | ENOTDIR | ENOTDIR | | `file.txt/sub/.` | ENOENT | **ENOTDIR** | ENOENT | ENOENT | ENOTDIR | | `loop/.` | ENOENT | **ELOOP (62)** | (no symlink privilege here) | (no symlink privilege here) | ELOOP | | `missing/.`, `missing/sub/.` | ENOENT | ENOENT | ENOENT | ENOENT | ENOENT | | `dir/.`, `dir/..` | EINVAL (22) | EINVAL | EINVAL | EINVAL | EINVAL | - Linux: Ubuntu 24.04 (WSL2, run as root), GCC 13.3, Release, `BUILD_TESTING=ON`. Windows: Windows 11 (10.0.26300), WinLibs GCC 15.2.0 UCRT, Release. - `guest_rename_dot` passes on both hosts, and `guest_filesystem` passes on Windows (2 runs each). The existing test passes with or without the change, so it does not cover the new branches. - `file.txt/.` (ENOTDIR) and `loop/.` (ELOOP) on Linux fail on `main` and pass with this change. Neither needs ACLs or root, so they could go into `GuestRenameDot.cpp` under `#ifndef _WIN32`. - On Windows, `file.txt/sub/.` is still ENOENT, because MinGW's `status()` reports a path under a regular file as not found rather than `not_a_directory`. That is unchanged from `main`, but the description's "`ENOTDIR` when the status reports `not_a_directory`" does not cover Windows. AI-assisted: yes (Claude Code); results above were run on this machine.
xXPBSXx commented 2026-10-20 12:29:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-20T12:29:02Z.


Thanks for the Linux data and the table. I added the two cases you named (file.txt/. and loop/.) in 34acda342 ('cover rename through a file and through a symbolic link loop'), so main now fails them on Linux and this PR passes. You are right that on Windows file.txt/sub/. stays ENOENT because status() reports not-found there; the description's 'ENOTDIR when the status reports not_a_directory' holds on hosts where it does. I have not run the new test on Linux myself.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6290851789 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8217#issuecomment-6290851789). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-20T12:29:02Z. --- Thanks for the Linux data and the table. I added the two cases you named (`file.txt/.` and `loop/.`) in 34acda342 ('cover rename through a file and through a symbolic link loop'), so `main` now fails them on Linux and this PR passes. You are right that on Windows `file.txt/sub/.` stays ENOENT because `status()` reports not-found there; the description's 'ENOTDIR when the status reports not_a_directory' holds on hosts where it does. I have not run the new test on Linux myself.
wachi35676 commented 2026-10-20 13:13:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-20T13:13:41Z.


Verdict: confirm, with one small test note. I ran 34acda342 on Linux for you.

I merged it onto main 44e3389c8 (clean merge) and ran on Ubuntu 24.04 (WSL2, as root) with GCC 13.3 and on Windows 11 with WinLibs GCC 15.2.0, both Release.

  • Linux: guest_rename_dot passes, 3 runs out of 3.
  • Linux negative control: with RenameDot.hpp set back to main, the test fails 3 of 3 at rename from file/. must fail with ENOTDIR (20) (errno 2). I then removed the checks one at a time, and each of the three new Linux checks fails on its own against main:
    • rename to file/. gives errno 2.
    • rename from loop/. gives errno 2 instead of ELOOP (62).
  • Windows: guest_rename_dot and guest_filesystem pass 3 of 3 with and without the RenameDot.hpp change, as you described.

Test note: Cleanup() removes only the three directories. If a run aborts between symlink and unlink, anyps5_rename_dot_loop stays in the test directory (build/core/libs/prx/libkernel). Every later run then fails at creating the symbolic link loop failed (errno 17), even with the fix. I reproduced this by leaving the link in place before a run of the PR build. Removing PlainFile and Loop in Cleanup() (std::remove / ::unlink) would avoid it.

AI-assisted: yes (Claude Code); results above were run on this machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6291691160 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8217#issuecomment-6291691160). Originally posted by [wachi35676](https://github.com/wachi35676) on 2026-10-20T13:13:41Z. --- Verdict: confirm, with one small test note. I ran `34acda342` on Linux for you. I merged it onto `main` `44e3389c8` (clean merge) and ran on Ubuntu 24.04 (WSL2, as root) with GCC 13.3 and on Windows 11 with WinLibs GCC 15.2.0, both Release. - Linux: `guest_rename_dot` passes, 3 runs out of 3. - Linux negative control: with `RenameDot.hpp` set back to `main`, the test fails 3 of 3 at `rename from file/. must fail with ENOTDIR (20) (errno 2)`. I then removed the checks one at a time, and each of the three new Linux checks fails on its own against `main`: - `rename to file/.` gives errno 2. - `rename from loop/.` gives errno 2 instead of ELOOP (62). - Windows: `guest_rename_dot` and `guest_filesystem` pass 3 of 3 with and without the `RenameDot.hpp` change, as you described. Test note: `Cleanup()` removes only the three directories. If a run aborts between `symlink` and `unlink`, `anyps5_rename_dot_loop` stays in the test directory (`build/core/libs/prx/libkernel`). Every later run then fails at `creating the symbolic link loop failed (errno 17)`, even with the fix. I reproduced this by leaving the link in place before a run of the PR build. Removing `PlainFile` and `Loop` in `Cleanup()` (`std::remove` / `::unlink`) would avoid it. AI-assisted: yes (Claude Code); results above were run on this machine.
xXPBSXx commented 2026-10-20 20:18:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-20T20:18:06Z.


Good catch, thanks. Cleanup() now also removes the plain file and the symbolic link (std::remove; the two names moved to namespace scope), and the test already calls Cleanup() before it creates anything, so a leftover link from an aborted run no longer fails the next one with EEXIST (commit faec856276). guest_rename_dot still passes on Windows; the loop case runs on Linux only, which I did not run.
AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6300568416 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8217#issuecomment-6300568416). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-20T20:18:06Z. --- Good catch, thanks. `Cleanup()` now also removes the plain file and the symbolic link (`std::remove`; the two names moved to namespace scope), and the test already calls `Cleanup()` before it creates anything, so a leftover link from an aborted run no longer fails the next one with EEXIST (commit faec856276). `guest_rename_dot` still passes on Windows; the loop case runs on Linux only, which I did not run. AI-assisted (Claude Code).
xXPBSXx commented 2026-10-21 03:40:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T03:40:29Z.


Linux data point for faec856276 (WSL2, Ubuntu 24.04, GCC 13.3, Release, -j4; a virtualised kernel, not bare-metal Linux): guest_rename_dot, guest_filesystem and guest_posix_filesystem pass on Linux (3 of 3). This replaces the "Linux not tested" line in the description for this head. Not tested: macOS.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6307456207 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8217#issuecomment-6307456207). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-21T03:40:29Z. --- Linux data point for `faec856276` (WSL2, Ubuntu 24.04, GCC 13.3, Release, `-j4`; a virtualised kernel, not bare-metal Linux): `guest_rename_dot`, `guest_filesystem` and `guest_posix_filesystem` pass on Linux (3 of 3). This replaces the "Linux not tested" line in the description for this head. Not tested: macOS. AI-assisted (Claude Code).
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!8217
No description provided.