use of java.nio.file.InvalidPathException in project cryptomator by cryptomator.
the class MountOptionsController method chooseCustomMountPointOrReset.
private void chooseCustomMountPointOrReset(Toggle previousMountToggle) {
DirectoryChooser directoryChooser = new DirectoryChooser();
directoryChooser.setTitle(resourceBundle.getString("vaultOptions.mount.mountPoint.directoryPickerTitle"));
try {
var initialDir = vault.getVaultSettings().getCustomMountPath().orElse(System.getProperty("user.home"));
directoryChooser.setInitialDirectory(Path.of(initialDir).toFile());
} catch (InvalidPathException e) {
// no-op
}
File file = directoryChooser.showDialog(window);
if (file != null) {
vault.getVaultSettings().customMountPath().set(file.getAbsolutePath());
} else {
mountPoint.selectToggle(previousMountToggle);
}
}
use of java.nio.file.InvalidPathException in project cryptomator by cryptomator.
the class FileOpenRequestHandlerTest method testOpenArgsWithIncorrectPaths.
@Test
@DisplayName("./cryptomator.exe foo (with 'foo' being an invalid path)")
public void testOpenArgsWithIncorrectPaths() {
FileSystem fs = Mockito.mock(FileSystem.class);
Mockito.when(fs.getPath("foo")).thenThrow(new InvalidPathException("foo", "foo is not a path"));
inTest.handleLaunchArgs(fs, List.of("foo"));
AppLaunchEvent evt = queue.poll();
Assertions.assertNull(evt);
}
use of java.nio.file.InvalidPathException in project cryptomator by cryptomator.
the class FileOpenRequestHandler method handleLaunchArgs.
// visible for testing
void handleLaunchArgs(FileSystem fs, List<String> args) {
Collection<Path> pathsToOpen = args.stream().map(str -> {
try {
return fs.getPath(str);
} catch (InvalidPathException e) {
LOG.trace("Argument not a valid path: {}", str);
return null;
}
}).filter(Objects::nonNull).toList();
if (!pathsToOpen.isEmpty()) {
AppLaunchEvent launchEvent = new AppLaunchEvent(AppLaunchEvent.EventType.OPEN_FILE, pathsToOpen);
tryToEnqueueFileOpenRequest(launchEvent);
}
}
use of java.nio.file.InvalidPathException in project alluxio by Alluxio.
the class AbstractFileManager method addFile.
@Override
public boolean addFile(String fileName, String permission, byte[] content) {
try {
verifyFileName(fileName);
Path path = Paths.get(getNextFilePath(fileName));
short perm = Short.parseShort(permission, 8);
Mode mode = new Mode(perm);
Set<PosixFilePermission> permissions = PosixFilePermissions.fromString(mode.toString());
FileAttribute<?> fileAttribute = PosixFilePermissions.asFileAttribute(permissions);
Files.deleteIfExists(path);
path = Files.createFile(path, fileAttribute);
FileSystem fileSystem = path.getFileSystem();
UserPrincipalLookupService service = fileSystem.getUserPrincipalLookupService();
UserPrincipal userPrincipal = service.lookupPrincipalByName(mUser);
GroupPrincipal groupPrincipal = service.lookupPrincipalByGroupName(mGroup);
Files.write(path, content);
Files.setOwner(path, userPrincipal);
Files.getFileAttributeView(path, PosixFileAttributeView.class, LinkOption.NOFOLLOW_LINKS).setGroup(groupPrincipal);
// sometimes umask is applied, so forcefully set permissions
Files.setPosixFilePermissions(path, permissions);
return true;
} catch (InvalidPathException | IOException | AlluxioException e) {
LOG.warn("Failed to add file {} to version manager", fileName, e);
return false;
}
}
use of java.nio.file.InvalidPathException in project alluxio by Alluxio.
the class AlluxioFuseFileSystem method mkdirInternal.
private int mkdirInternal(String path, @mode_t long mode) {
final AlluxioURI turi = mPathResolverCache.getUnchecked(path);
if (turi.getName().length() > MAX_NAME_LENGTH) {
LOG.error("Failed to create directory {}, directory name is longer than {} characters", path, MAX_NAME_LENGTH);
return -ErrorCodes.ENAMETOOLONG();
}
SetAttributePOptions.Builder attributeOptionsBuilder = SetAttributePOptions.newBuilder();
FuseContext fc = getContext();
long uid = fc.uid.get();
long gid = fc.gid.get();
try {
if (gid != GID) {
String groupName = AlluxioFuseUtils.getGroupName(gid);
if (groupName.isEmpty()) {
// This should never be reached since input gid is always valid
LOG.error("Failed to get group name from gid {}.", gid);
return -ErrorCodes.EFAULT();
}
attributeOptionsBuilder.setGroup(groupName);
}
if (uid != UID) {
String userName = AlluxioFuseUtils.getUserName(uid);
if (userName.isEmpty()) {
// This should never be reached since input uid is always valid
LOG.error("Failed to get user name from uid {}", uid);
return -ErrorCodes.EFAULT();
}
attributeOptionsBuilder.setOwner(userName);
}
SetAttributePOptions setAttributePOptions = attributeOptionsBuilder.build();
mFileSystem.createDirectory(turi, CreateDirectoryPOptions.newBuilder().setMode(new alluxio.security.authorization.Mode((short) mode).toProto()).build());
if (gid != GID || uid != UID) {
LOG.debug("Set attributes of path {} to {}", path, setAttributePOptions);
mFileSystem.setAttribute(turi, setAttributePOptions);
}
} catch (FileAlreadyExistsException e) {
LOG.debug("Failed to create directory {}, directory already exists", path);
return -ErrorCodes.EEXIST();
} catch (InvalidPathException e) {
LOG.debug("Failed to create directory {}, path is invalid", path);
return -ErrorCodes.ENOENT();
} catch (Throwable t) {
LOG.error("Failed to create directory {}", path, t);
return AlluxioFuseUtils.getErrorCode(t);
}
return 0;
}
Aggregations