Search in sources :

Example 91 with InvalidPathException

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);
    }
}
Also used : File(java.io.File) DirectoryChooser(javafx.stage.DirectoryChooser) InvalidPathException(java.nio.file.InvalidPathException)

Example 92 with InvalidPathException

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);
}
Also used : AppLaunchEvent(org.cryptomator.ui.launcher.AppLaunchEvent) FileSystem(java.nio.file.FileSystem) InvalidPathException(java.nio.file.InvalidPathException) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 93 with InvalidPathException

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);
    }
}
Also used : Path(java.nio.file.Path) AppLaunchEvent(org.cryptomator.ui.launcher.AppLaunchEvent) InvalidPathException(java.nio.file.InvalidPathException)

Example 94 with InvalidPathException

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;
    }
}
Also used : Path(java.nio.file.Path) UserPrincipalLookupService(java.nio.file.attribute.UserPrincipalLookupService) Mode(alluxio.security.authorization.Mode) IOException(java.io.IOException) PosixFilePermission(java.nio.file.attribute.PosixFilePermission) UserPrincipal(java.nio.file.attribute.UserPrincipal) InvalidPathException(java.nio.file.InvalidPathException) PosixFileAttributeView(java.nio.file.attribute.PosixFileAttributeView) GroupPrincipal(java.nio.file.attribute.GroupPrincipal) FileSystem(java.nio.file.FileSystem) AlluxioException(alluxio.exception.AlluxioException)

Example 95 with InvalidPathException

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;
}
Also used : FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) FuseContext(ru.serce.jnrfuse.struct.FuseContext) SetAttributePOptions(alluxio.grpc.SetAttributePOptions) InvalidPathException(java.nio.file.InvalidPathException) AlluxioURI(alluxio.AlluxioURI)

Aggregations

InvalidPathException (java.nio.file.InvalidPathException)111 Path (java.nio.file.Path)58 IOException (java.io.IOException)30 File (java.io.File)17 URL (java.net.URL)15 MalformedURLException (java.net.MalformedURLException)12 Test (org.junit.Test)11 AlluxioURI (alluxio.AlluxioURI)7 ArrayList (java.util.ArrayList)7 Resource (org.springframework.core.io.Resource)7 Nullable (org.springframework.lang.Nullable)7 URI (java.net.URI)6 URISyntaxException (java.net.URISyntaxException)6 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)5 BufferedReader (java.io.BufferedReader)5 URIStatus (alluxio.client.file.URIStatus)4 ViewResolve (com.nvlad.yii2support.views.entities.ViewResolve)4 RepositoryChanged (com.searchcode.app.dto.RepositoryChanged)4 InputStream (java.io.InputStream)4 InputStreamReader (java.io.InputStreamReader)4