in src/main/java/org/apache/commons/io/file/PathUtils.java [638:678]
public static PathCounters deleteFile(final Path file, final LinkOption[] linkOptions, final DeleteOption... deleteOptions)
throws NoSuchFileException, IOException {
//
// TODO Needs clean up?
//
if (Files.isDirectory(file, linkOptions)) {
throw new NoSuchFileException(file.toString());
}
final PathCounters pathCounts = Counters.longPathCounters();
boolean exists = exists(file, linkOptions);
long size = exists && !Files.isSymbolicLink(file) ? Files.size(file) : 0;
try {
if (Files.deleteIfExists(file)) {
pathCounts.getFileCounter().increment();
pathCounts.getByteCounter().add(size);
return pathCounts;
}
} catch (final AccessDeniedException ignored) {
// Ignore and try again below.
}
final Path parent = getParent(file);
PosixFileAttributes posixFileAttributes = null;
try {
if (overrideReadOnly(deleteOptions)) {
posixFileAttributes = readPosixFileAttributes(parent, linkOptions);
setReadOnly(file, false, linkOptions);
}
// Read size _after_ having read/execute access on POSIX.
exists = exists(file, linkOptions);
size = exists && !Files.isSymbolicLink(file) ? Files.size(file) : 0;
if (Files.deleteIfExists(file)) {
pathCounts.getFileCounter().increment();
pathCounts.getByteCounter().add(size);
}
} finally {
if (posixFileAttributes != null) {
Files.setPosixFilePermissions(parent, posixFileAttributes.permissions());
}
}
return pathCounts;
}