Piotr Karwasz created IO-879:
--------------------------------
Summary: Keep DOS `read-only` flag on `FileUtils.forceDelete` error
Key: IO-879
URL: https://issues.apache.org/jira/browse/IO-879
Project: Commons IO
Issue Type: Bug
Reporter: Piotr Karwasz
Deleting a file on Windows involves two steps:
# Clear the DOS {{FILE_ATTRIBUTE_READONLY}} flag.
# Call the Win32 {{DeleteFile}} function.
This process is non-atomic and can partially fail. Clearing the flag does *not*
guarantee that the user has permission to delete the file, since modern file
systems enforce ACLs, not DOS attributes.
*Problem*
Both {{FileUtils.forceDelete}} and {{PathUtils.delete}} remove the DOS
{{read-only}} flag before attempting deletion, but they *do not restore it* if
the deletion fails. This leaves the file writable even though the delete did
not succeed.
*Why is this relevant?*
Since JDK 25, {{File.delete}} no longer clears the DOS {{read-only}} flag
automatically. Users looking for a drop-in replacement may turn to
{{FileUtils.forceDelete}}, so it is important that its behavior is predictable
and does not leave the file in a different state on failure.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)