Skip to content

Use Files.deleteIfExists in FileUtils.forceDelete - #350

Merged
slachiewicz merged 2 commits into
masterfrom
agent/force-delete-deleteifexists
Nov 9, 2026
Merged

slachiewicz merged 2 commits into
masterfrom
agent/force-delete-deleteifexists

Conversation

@slachiewicz

Copy link
Copy Markdown
Member

Deletes with Files.deleteIfExists first, which also removes dangling symlinks, and keeps the System.gc() and sleep retry only for files that still exist after a failed delete. Absent files no longer pay the Windows retry cost.

The retry path only runs on a locked file under Windows, so it is not covered by a test here; the new tests pin the non-existent file and dangling symlink cases.

Closes #21

Verified: mvn -B -ntp verify → BUILD SUCCESS, 254 tests, 0 failures, 3 skipped (macOS, JDK 17)

Retry with System.gc() and a sleep only for files that still exist after
a failed delete, so deleting an absent file no longer pays that cost on
Windows. Files.deleteIfExists also removes dangling symlinks.
@slachiewicz slachiewicz added the bug Something isn't working label Nov 8, 2026
@slachiewicz
slachiewicz marked this pull request as ready for review November 8, 2026 23:11
Windows stops reporting a file link as a symlink once its target is
deleted, so the precondition of the test, not the fix, failed there.
@slachiewicz
slachiewicz merged commit 44a05db into master Nov 9, 2026
13 checks passed
@slachiewicz
slachiewicz deleted the agent/force-delete-deleteifexists branch November 9, 2026 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FileUtils.foreceDelete consumed on Windows-System a lot of system resources

1 participant