[
https://issues.apache.org/jira/browse/IO-874?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Gary D. Gregory resolved IO-874.
--------------------------------
Fix Version/s: 2.20.0
Resolution: Fixed
> 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.17.0, 2.18.0, 2.19.0
> Reporter: Andy Russell
> Priority: Major
> Fix For: 2.20.0
>
>
> 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)