Repository navigation
fix: stop tests from deleting the system temp dir and FileUtils.delete from following symlinks - #1170
AhmedYoussef98 wants to merge 1 commit into
Conversation
…e from following symlinks
There was a problem hiding this comment.
Hi @AhmedYoussef98, while checking this on Windows, I noticed that it only catches symbolic links, not directory junctions. I tried deleting a directory containing a junction that pointed outside it, and FileUtils.delete() followed the junction and deleted the file in the target directory. Files.isSymbolicLink() returns false for the junction.
I think junctions should be treated as leaf entries before the isDirectory() branch so we never recurse into their targets. It would also be good to add a Windows-only test that creates a junction to an external directory and verifies that the target file is left untouched.
|
Hi @AhmedYoussef98 — I reproduced @skytin1004's junction finding on Windows and can confirm it: for a directory junction, I also verified the two pieces the fix needs, on Windows 11 + JDK 17:
Red/green on the same layout (a directory containing a junction to an external folder with a
A Windows-only test is practical if you want one: If you don't have the bandwidth for this right now, I'd be glad to take it forward from here — your commit stays with your authorship — but no pressure either way; happy to just leave the findings here. |
|
Hi @AhmedYoussef98 — following up on my note above. There has been no update since @skytin1004's CHANGES_REQUESTED on Oct 4, and no reply to my offer on Oct 15, so I'll take this forward now to close the junction gap. Plan, keeping your work credited:
The new PR will note that it supersedes this one; nothing is needed from you. If you would rather finish it yourself, just say so and I'll hand it back. |
|
Hi @AhmedYoussef98 — the new PR is up: #1248. It carries your commit with your authorship intact, plus the Windows junction guard and the I'll leave this PR open for the maintainers to close once #1248 lands. Thanks again for the original fix and the detailed issue report. |
Purpose of the pull request
Closed: #1169
What's changed?
CompatibilityTest#readWithCacheAfterTempDeletionnow deletes only Fesod's own temp directory (FileUtils.getTempFilePrefix()) and no longer deletes the wholejava.io.tmpdir. That is still what the test means to check: Fesod recovers when its temp and cache files are removed while idle. The system temp directory is shared with other processes, so a test must never delete it.FileUtils.deletenow deletes a symbolic link itself and does not follow it. Before,File.isDirectory()/listFiles()resolved links, so the recursive delete could leave the directory it was given. On macOS, anApplications -> /Applicationslink inside a mounted installer DMG under$TMPDIRled it to wipe application bundles (details in [Bug] CompatibilityTest deletes the whole system temp dir, and FileUtils.delete follows symlinks out of it #1169).FileUtilsTest#test_delete_doesNotFollowSymbolicLinks. It fails on currentmain(the link target's contents are deleted) and passes with this change. It is skipped where symbolic links can't be created.Verified with
./mvnw package -Dmaven.test.skip=false -Dtest='FileUtilsTest,CompatibilityTest' -pl fesod-common,fesod-shaded,fesod-sheet(27 tests, all passing) and./mvnw spotless:check.Checklist