fs: support removing read-only files in rmSync on Windows · nodejs/node@cd10114 · GitHub
Skip to content

Commit cd10114

Browse files
SparshGarg999aduh95
authored andcommitted
fs: support removing read-only files in rmSync on Windows
On Windows, libc++ std::filesystem::remove and remove_all do not automatically clear the read-only attribute before deleting a file (unlike MSVC STL). This causes fs.rmSync to fail with EPERM when trying to remove read-only files in environments where Node.js is built using clang libc++ (such as Electron). This commit introduces a Windows-specific helper ClearReadOnlyAttributeW which clears the FILE_ATTRIBUTE_READONLY attribute recursively (or for a single file) when operation_not_permitted is returned, allowing rmSync to successfully delete read-only files/folders. Fixes: #64374 Signed-off-by: SparshGarg999 <sparshgarg999@gmail.com> PR-URL: #64453 Fixes: #64374 Reviewed-By: Stefan Stojanovic <stefan.stojanovic@janeasystems.com>
1 parent ac37bbe commit cd10114

2 files changed

Lines changed: 81 additions & 0 deletions

File tree

‎src/node_file.cc‎

Lines changed: 54 additions & 0 deletions

‎test/parallel/test-fs-rm.js‎

Lines changed: 27 additions & 0 deletions

0 commit comments

Comments
 (0)