Andy Russell created IO-874:
-------------------------------
Summary: FileUtils.forceDelete ignores broken symlinks
Key: IO-874
URL: https://issues.apache.org/jira/browse/IO-874
Project: Commons IO
Issue Type: Bug
Affects Versions: 2.19.0, 2.18.0, 2.17.0
Reporter: Andy Russell
I recently attempted an upgrade of Commons IO from 2.16.1 to 2.19.0. A test
started failing due to a behavior change introduced in 2.17.0.
Previously, calling `FileUtils.forceDelete` on a *broken* symbolic link would
result in the symlink being deleted. Now, it results in a
`FileNotFoundException`, but the symlink remains on the filesystem if the
exception is caught.
I would expect the broken symlink to be deleted.
Sample test case demonstrating the issue:
{code:java}
@Test
public void testForceDeleteBrokenSymlink() throws Exception {
final ImmutablePair<Path, Path> pair = createTempSymlinkedRelativeDir();
final Path symlinkedDir = pair.getLeft();
final Path targetDir = pair.getRight(); Files.delete(targetDir);
assertFalse(Files.exists(symlinkedDir));
assertTrue(Files.isSymbolicLink(symlinkedDir)); try {
FileUtils.forceDelete(symlinkedDir.toFile());
} catch (IOException e) {
// do nothing (on 2.16.1 this does not throw)
}
assertFalse(Files.exists(symlinkedDir));
assertFalse(Files.isSymbolicLink(symlinkedDir));
}{code}
`git bisect` shows this regressed in 4c14c076.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)