Applied suggestions from code review

See: https://github.com/cryptomator/cryptomator/pull/2996#discussion_r1260955250
This commit is contained in:
JaniruTEC
2023-07-12 19:17:37 +02:00
parent 5e2e8c35d5
commit 96ebb67085

View File

@@ -4,6 +4,7 @@ import org.apache.commons.lang3.SystemUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.DirectoryNotEmptyException;
import java.nio.file.FileAlreadyExistsException;
@@ -74,18 +75,14 @@ public final class MountWithinParentUtil {
private static boolean removeResidualJunction(Path path) throws MountPointPreparationException {
try {
if (!Files.exists(path, LinkOption.NOFOLLOW_LINKS)) {
return false;
}
if (!SystemUtils.IS_OS_WINDOWS) { //So far this is only a problem on Windows
return true;
}
if (Files.readAttributes(path, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS).isOther()) {
LOG.info("Mountpoint \"{}\" is still a junction. Deleting it.", path);
Files.delete(path); //Throws if path is also a non-empty folder
return false;
}
return true;
} catch (FileNotFoundException e) {
return false;
} catch (IOException e) {
throw new MountPointPreparationException(e);
}