fix(libc): remove read-only files on Windows #2342
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2342"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-09T15:57:51Z.
What
On FreeBSD,
unlink(and soremove) ignores the file's own permission bits: what matters is write access to the directory. A guest that doeschmod(path, 0400)and laterremove(path)therefore succeeds on the console.On Windows, the guest
chmod(_wchmod) setsFILE_ATTRIBUTE_READONLYwhen the write bit is cleared.DeleteFileWthen fails withERROR_ACCESS_DENIED, soremovereturned -1 withEACCES, and the file stayed.When the entry carries
FILE_ATTRIBUTE_READONLY(the attributes are already read),removenow clears it before the single delete. If the delete fails (e.g. the file is open without delete sharing), it restores the original attributes and reports the delete's error, so a failedremoveleaves the file as it was. Linux is unchanged.Tested
Windows 11, WinLibs GCC 15.2.0 r7, Release,
-DBUILD_TESTING=ON:guest_filesystem: a file made read-only withsceKernelChmod(0400)is removed byremove, and no longer exists.mainit fails at that line with guest errno 13.removefails (EBUSY), the file stays, andFILE_ATTRIBUTE_READONLYis restored;chmodnever sets the attribute on directories, so directory removal is unaffected.ctest -E "^agc_|video_out": 249/249.tools/check_conventions.pypasses, andtools/pr_overlap.py --branchreports no overlap. It also merges cleanly with the open PRs that touchGuestFilesystem.cppandFilesystem.cpp: #1192, #1620, #1624, #1628, #1755, #1764, #1777, #2086, #2115, #2129, #2170, #2260, #2289 and #2300.sceKernelUnlink/unlinkin libkernel likely behave the same way on Windows. They are left for a separate PR, because #2289 changes that function.A Linux and Windows full build will be posted here once it has run.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-09T16:30:01Z.
Full Linux and Windows builds and tests for this head (
58e18f08), using the project's Build workflow. I can't start the upstream manual run, so I ran the samebuild.ymlin my fork through a mirror PR. Like the upstream run, the jobs check out the PR head merged into currentmain(d70b8998):ctest: 516/516 passedctest: 507/507 passedRun: https://github.com/AchrafReyani/AnyPS5/actions/runs/37955618179
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T20:15:23Z.
remove_nid_postfixdeletes, and onERROR_ACCESS_DENIEDclears the read-only attribute and deletes again (Filesystem.cpp:121-136). Retrying after an error isn't allowed here;attributesis already read, so please clearFILE_ATTRIBUTE_READONLYbefore the first delete when it's set (restoring it if that delete fails), and drop the second attempt.Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-09T20:24:54Z.
Done in
e8d4c022:removenow clearsFILE_ATTRIBUTE_READONLYbefore the single delete when it is set, and restores the original attributes if that delete fails. The second attempt is gone.I rechecked on Windows:
guest_filesystempasses;EBUSY, stays in place and keeps its read-only attribute;ctest -E "^agc_|video_out"is 249/249, andcheck_conventions.pypasses.The Linux and Windows full build for the new head is running and will be posted here.
Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-09T20:43:14Z.
Full Linux and Windows builds and tests for this head (
e8d4c022), using the project's Build workflow. I can't start the upstream manual run, so I ran the samebuild.ymlin my fork through a mirror PR. Like the upstream run, the jobs check out the PR head merged into currentmain(d70b8998):ctest: 516/516 passedctest: 507/507 passedRun: https://github.com/AchrafReyani/AnyPS5/actions/runs/37986819849