mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-04-24 11:36:57 -04:00
Stopped wrapping IOEs as UncheckedIOEs
See: https://github.com/cryptomator/cryptomator/pull/2996#discussion_r1269444937 https://github.com/cryptomator/cryptomator/pull/2996#discussion_r1269445672 https://github.com/cryptomator/cryptomator/pull/2996#discussion_r1269445894
This commit is contained in:
@@ -5,7 +5,6 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.nio.file.FileAlreadyExistsException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.LinkOption;
|
||||
@@ -22,7 +21,7 @@ public final class MountWithinParentUtil {
|
||||
|
||||
private MountWithinParentUtil() {}
|
||||
|
||||
static void prepareParentNoMountPoint(Path mountPoint) throws IllegalMountPointException {
|
||||
static void prepareParentNoMountPoint(Path mountPoint) throws IllegalMountPointException, IOException {
|
||||
Path hideaway = getHideaway(mountPoint);
|
||||
var mpExists = removeResidualJunction(mountPoint); //Handle junction as not existing
|
||||
var hideExists = Files.exists(hideaway, LinkOption.NOFOLLOW_LINKS);
|
||||
@@ -32,12 +31,8 @@ public final class MountWithinParentUtil {
|
||||
} else if (!mpExists) { //only hideaway exists
|
||||
checkIsHideawayDirectory(mountPoint, hideaway);
|
||||
LOG.info("Mountpoint {} seems to be not properly cleaned up. Will be fixed on unmount.", mountPoint);
|
||||
try {
|
||||
if (SystemUtils.IS_OS_WINDOWS) {
|
||||
Files.setAttribute(hideaway, WIN_HIDDEN_ATTR, true, LinkOption.NOFOLLOW_LINKS);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
if (SystemUtils.IS_OS_WINDOWS) {
|
||||
Files.setAttribute(hideaway, WIN_HIDDEN_ATTR, true, LinkOption.NOFOLLOW_LINKS);
|
||||
}
|
||||
} else { //mountpoint exists...
|
||||
try {
|
||||
@@ -61,8 +56,6 @@ public final class MountWithinParentUtil {
|
||||
Thread.sleep(1000);
|
||||
attempts++;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new RuntimeException(e);
|
||||
@@ -71,7 +64,7 @@ public final class MountWithinParentUtil {
|
||||
}
|
||||
|
||||
//visible for testing
|
||||
static boolean removeResidualJunction(Path path) {
|
||||
static boolean removeResidualJunction(Path path) throws IOException {
|
||||
try {
|
||||
if (Files.readAttributes(path, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS).isOther()) {
|
||||
LOG.info("Mountpoint \"{}\" is still a junction. Deleting it.", path);
|
||||
@@ -81,8 +74,6 @@ public final class MountWithinParentUtil {
|
||||
return true;
|
||||
} catch (NoSuchFileException e) {
|
||||
return false;
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.nio.file.DirectoryNotEmptyException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
@@ -79,10 +78,9 @@ class MountWithinParentUtilTest {
|
||||
Files.createFile(hideaway.resolve("dummy"));
|
||||
Files.createDirectory(mount);
|
||||
|
||||
var exc = assertThrows(UncheckedIOException.class, () -> {
|
||||
assertThrows(DirectoryNotEmptyException.class, () -> {
|
||||
prepareParentNoMountPoint(mount);
|
||||
});
|
||||
assertInstanceOf(DirectoryNotEmptyException.class, exc.getCause());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user