Commit 028dd62
authored
Improve
* Improve `FileUtils.forceDelete()` tests on Windows
On Windows, the `DeleteFile` Win32 API has a little quirk: it refuses to delete files with the legacy **DOS read-only attribute** set. (Because apparently 99% of Windows users don’t realize that “deleting a file” is actually an operation on the *directory*, not the file itself 😉).
So the usual drill is: clear the read-only flag first, then delete.
* Until JDK 25, `File.delete()` did this for you behind the scenes: it quietly stripped the flag before calling into `DeleteFile`. That meant your file might be left behind (with the flag missing) if the *real* ACLs didn’t allow deletion.
* From JDK 25 onward, `File.delete()` doesn’t touch the flag anymore. If the bit is set, `DeleteFile` fails, end of story.
* `FileUtils.forceDelete()` already knows how to juggle the flag itself, so its behavior didn’t change.
This PR:
* Updates two tests that were (unfairly) comparing `File.delete` with `FileUtils.forceDelete`. With JDK 25, their expectations diverged.
* Adds a new test to confirm that `FileUtils.forceDelete` restores the read-only flag if the actual deletion fails.
> [!WARNING]
> I didn’t develop this on a Windows box, so I couldn’t test it locally. Leaving this as a **draft PR** until CI tells us whether Windows agrees with me.
* fix: always clear read-only bit
* fix: check for `IOException`, not `AccessDeniedException`
* feat: add holder for file and parent attributes
Introduce a helper that snapshots file and parent directory attributes before `setReadOnly` is applied.
If a deletion attempt fails, the holder can restore the original attributes to keep the filesystem state consistent.
* fix: Spotbugs failure
* fix: prefer POSIX to DOS attributes when both are available
On Linux/Unix, both POSIX and DOS attribute views may be supported,
while on Windows only DOS attributes are available.
Check for POSIX first to ensure the correct view is used across platforms.
* fix: revert read-only related changesFileUtils.forceDelete() tests on Windows (#791)1 parent 5331074 commit 028dd62
1 file changed
+36
-21
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| 55 | + | |
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
| |||
1735 | 1736 | | |
1736 | 1737 | | |
1737 | 1738 | | |
1738 | | - | |
1739 | | - | |
1740 | | - | |
1741 | | - | |
1742 | | - | |
| 1739 | + | |
| 1740 | + | |
| 1741 | + | |
| 1742 | + | |
| 1743 | + | |
| 1744 | + | |
| 1745 | + | |
| 1746 | + | |
| 1747 | + | |
1743 | 1748 | | |
1744 | 1749 | | |
1745 | 1750 | | |
1746 | 1751 | | |
1747 | | - | |
1748 | | - | |
1749 | | - | |
| 1752 | + | |
| 1753 | + | |
| 1754 | + | |
1750 | 1755 | | |
1751 | 1756 | | |
1752 | | - | |
| 1757 | + | |
| 1758 | + | |
| 1759 | + | |
| 1760 | + | |
| 1761 | + | |
| 1762 | + | |
| 1763 | + | |
1753 | 1764 | | |
1754 | 1765 | | |
1755 | 1766 | | |
| |||
1823 | 1834 | | |
1824 | 1835 | | |
1825 | 1836 | | |
1826 | | - | |
1827 | | - | |
1828 | | - | |
1829 | | - | |
1830 | | - | |
1831 | | - | |
| 1837 | + | |
| 1838 | + | |
| 1839 | + | |
| 1840 | + | |
| 1841 | + | |
| 1842 | + | |
| 1843 | + | |
| 1844 | + | |
| 1845 | + | |
| 1846 | + | |
1832 | 1847 | | |
1833 | 1848 | | |
1834 | 1849 | | |
1835 | 1850 | | |
1836 | | - | |
1837 | | - | |
1838 | | - | |
1839 | | - | |
1840 | | - | |
| 1851 | + | |
| 1852 | + | |
| 1853 | + | |
| 1854 | + | |
| 1855 | + | |
1841 | 1856 | | |
1842 | | - | |
| 1857 | + | |
1843 | 1858 | | |
1844 | 1859 | | |
1845 | 1860 | | |
| |||
0 commit comments