mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-17 10:11:27 +00:00
Updated CustomMountPointChooser to use MPR instead of OS-Checks
Updated CustomMountPointChooser to use MountPointRequirements instead of OS-Checks.
This led to the discovery of the bug that was fixed in 724b20c826.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package org.cryptomator.common.mountpoint;
|
||||
|
||||
import org.apache.commons.lang3.SystemUtils;
|
||||
import org.cryptomator.common.vaults.MountPointRequirement;
|
||||
import org.cryptomator.common.vaults.Vault;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -34,28 +34,37 @@ public class CustomMountPointChooser implements MountPointChooser {
|
||||
|
||||
@Override
|
||||
public boolean prepare(Path mountPoint) throws InvalidMountPointException {
|
||||
//On Windows the target folder MUST NOT exist...
|
||||
//https://github.com/billziss-gh/winfsp/issues/320
|
||||
if (SystemUtils.IS_OS_WINDOWS) {
|
||||
//We must use #notExists() here because notExists =/= !exists (see docs)
|
||||
if (Files.notExists(mountPoint, LinkOption.NOFOLLOW_LINKS)) {
|
||||
//File really doesn't exist
|
||||
return false;
|
||||
}
|
||||
//File exists OR can't be determined
|
||||
throw wrapAsIMPE(new FileAlreadyExistsException(mountPoint.toString()));
|
||||
}
|
||||
MountPointRequirement requirement = this.vault.getMountPointRequirement();
|
||||
//Requirement "NONE" doesn't make any sense here.
|
||||
//No need to prepare/verify a Mountpoint without requiring one...
|
||||
assert requirement != MountPointRequirement.NONE;
|
||||
|
||||
//... on Mac and Linux it's the opposite
|
||||
if (!Files.isDirectory(mountPoint)) {
|
||||
throw wrapAsIMPE(new NotDirectoryException(mountPoint.toString()));
|
||||
}
|
||||
try (DirectoryStream<Path> ds = Files.newDirectoryStream(mountPoint)) {
|
||||
if (ds.iterator().hasNext()) {
|
||||
throw wrapAsIMPE(new DirectoryNotEmptyException(mountPoint.toString()));
|
||||
//Not implemented anywhere (yet)
|
||||
assert requirement != MountPointRequirement.PARENT_OPT_MOUNT_POINT;
|
||||
|
||||
if(requirement == MountPointRequirement.PARENT_NO_MOUNT_POINT) {
|
||||
//This the case on Windows when using FUSE
|
||||
//See https://github.com/billziss-gh/winfsp/issues/320
|
||||
|
||||
//We must use #notExists() here because notExists =/= !exists (see docs)
|
||||
if (!Files.notExists(mountPoint, LinkOption.NOFOLLOW_LINKS)) {
|
||||
//File exists OR can't be determined
|
||||
throw wrapAsIMPE(new FileAlreadyExistsException(mountPoint.toString()));
|
||||
}
|
||||
} else if(requirement == MountPointRequirement.EMPTY_MOUNT_POINT) {
|
||||
//This is the case for Windows when using Dokany
|
||||
//and for Linux and Mac
|
||||
|
||||
if (!Files.isDirectory(mountPoint)) {
|
||||
throw wrapAsIMPE(new NotDirectoryException(mountPoint.toString()));
|
||||
}
|
||||
try (DirectoryStream<Path> ds = Files.newDirectoryStream(mountPoint)) {
|
||||
if (ds.iterator().hasNext()) {
|
||||
throw wrapAsIMPE(new DirectoryNotEmptyException(mountPoint.toString()));
|
||||
}
|
||||
} catch (IOException exception) {
|
||||
throw wrapAsIMPE(exception);
|
||||
}
|
||||
} catch (IOException exception) {
|
||||
throw wrapAsIMPE(exception);
|
||||
}
|
||||
LOG.debug("Successfully checked custom mount point: {}", mountPoint);
|
||||
return false;
|
||||
@@ -64,5 +73,4 @@ public class CustomMountPointChooser implements MountPointChooser {
|
||||
private InvalidMountPointException wrapAsIMPE(Exception exception) {
|
||||
return new InvalidMountPointException(exception);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user