Search in sources :

Example 96 with InvalidPathException

use of java.nio.file.InvalidPathException in project alluxio by Alluxio.

the class AlluxioFuseFileSystem method readdirInternal.

private int readdirInternal(String path, Pointer buff, FuseFillDir filter, @off_t long offset, FuseFileInfo fi) {
    final AlluxioURI turi = mPathResolverCache.getUnchecked(path);
    try {
        final List<URIStatus> ls = mFileSystem.listStatus(turi);
        // standard . and .. entries
        filter.apply(buff, ".", null, 0);
        filter.apply(buff, "..", null, 0);
        for (final URIStatus file : ls) {
            filter.apply(buff, file.getName(), null, 0);
        }
    } catch (FileDoesNotExistException | InvalidPathException e) {
        LOG.debug("Failed to read directory {}, path does not exist or is invalid", path);
        return -ErrorCodes.ENOENT();
    } catch (Throwable t) {
        LOG.error("Failed to read directory {}", path, t);
        return AlluxioFuseUtils.getErrorCode(t);
    }
    return 0;
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) URIStatus(alluxio.client.file.URIStatus) InvalidPathException(java.nio.file.InvalidPathException) AlluxioURI(alluxio.AlluxioURI)

Example 97 with InvalidPathException

use of java.nio.file.InvalidPathException in project alluxio by Alluxio.

the class AlluxioFuseFileSystem method createInternal.

private int createInternal(String path, @mode_t long mode, FuseFileInfo fi) {
    final AlluxioURI uri = mPathResolverCache.getUnchecked(path);
    if (uri.getName().length() > MAX_NAME_LENGTH) {
        LOG.error("Failed to create {}, file name is longer than {} characters", path, MAX_NAME_LENGTH);
        return -ErrorCodes.ENAMETOOLONG();
    }
    try {
        if (mOpenFiles.size() >= MAX_OPEN_FILES) {
            LOG.error("Cannot create {}: too many open files (MAX_OPEN_FILES: {})", path, MAX_OPEN_FILES);
            return -ErrorCodes.EMFILE();
        }
        SetAttributePOptions.Builder attributeOptionsBuilder = SetAttributePOptions.newBuilder();
        FuseContext fc = getContext();
        long uid = fc.uid.get();
        long gid = fc.gid.get();
        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();
        FileOutStream os = mFileSystem.createFile(uri, CreateFilePOptions.newBuilder().setMode(new alluxio.security.authorization.Mode((short) mode).toProto()).build());
        long fid = mNextOpenFileId.getAndIncrement();
        mOpenFiles.add(new OpenFileEntry(fid, path, null, os));
        fi.fh.set(fid);
        if (gid != GID || uid != UID) {
            LOG.debug("Set attributes of path {} to {}", path, setAttributePOptions);
            mFileSystem.setAttribute(uri, setAttributePOptions);
        }
    } catch (FileAlreadyExistsException e) {
        LOG.debug("Failed to create {}, file already exists", path);
        return -ErrorCodes.EEXIST();
    } catch (InvalidPathException e) {
        LOG.debug("Failed to create {}, path is invalid", path);
        return -ErrorCodes.ENOENT();
    } catch (Throwable t) {
        LOG.error("Failed to create {}", path, t);
        return AlluxioFuseUtils.getErrorCode(t);
    }
    return 0;
}
Also used : FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) FileOutStream(alluxio.client.file.FileOutStream) InvalidPathException(java.nio.file.InvalidPathException) FuseContext(ru.serce.jnrfuse.struct.FuseContext) SetAttributePOptions(alluxio.grpc.SetAttributePOptions) AlluxioURI(alluxio.AlluxioURI)

Example 98 with InvalidPathException

use of java.nio.file.InvalidPathException in project alluxio by Alluxio.

the class AlluxioFuseFileSystem method openInternal.

private int openInternal(String path, FuseFileInfo fi) {
    final AlluxioURI uri = mPathResolverCache.getUnchecked(path);
    // (see {@code man 2 open} for the structure of the flags bitfield)
    // File creation flags are the last two bits of flags
    final int flags = fi.flags.get();
    if (mOpenFiles.size() >= MAX_OPEN_FILES) {
        LOG.error("Cannot open {}: too many open files (MAX_OPEN_FILES: {})", path, MAX_OPEN_FILES);
        return ErrorCodes.EMFILE();
    }
    FileInStream is;
    try {
        try {
            is = mFileSystem.openFile(uri);
        } catch (FileIncompleteException e) {
            if (AlluxioFuseUtils.waitForFileCompleted(mFileSystem, uri)) {
                is = mFileSystem.openFile(uri);
            } else {
                throw e;
            }
        }
    } catch (OpenDirectoryException e) {
        LOG.error("Cannot open folder {}", path);
        return -ErrorCodes.EISDIR();
    } catch (FileIncompleteException e) {
        LOG.error("Cannot open incomplete file {}", path);
        return -ErrorCodes.EFAULT();
    } catch (FileDoesNotExistException | InvalidPathException e) {
        LOG.error("Failed to open file {}, path does not exist or is invalid", path);
        return -ErrorCodes.ENOENT();
    } catch (Throwable t) {
        LOG.error("Failed to open file {}", path, t);
        return AlluxioFuseUtils.getErrorCode(t);
    }
    long fid = mNextOpenFileId.getAndIncrement();
    mOpenFiles.add(new OpenFileEntry<>(fid, path, is, null));
    fi.fh.set(fid);
    return 0;
}
Also used : OpenDirectoryException(alluxio.exception.OpenDirectoryException) FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) FileInStream(alluxio.client.file.FileInStream) FileIncompleteException(alluxio.exception.FileIncompleteException) InvalidPathException(java.nio.file.InvalidPathException) AlluxioURI(alluxio.AlluxioURI)

Example 99 with InvalidPathException

use of java.nio.file.InvalidPathException in project jboss-modules by jboss-modules.

the class PathResourceLoader method getResource.

@Override
public Resource getResource(final String name) {
    final String cleanName = PathUtils.canonicalize(PathUtils.relativize(name));
    final Path file;
    try {
        file = root.resolve(cleanName);
    } catch (InvalidPathException ignored) {
        return null;
    }
    if (!doPrivilegedIfNeeded(context, () -> Files.exists(file))) {
        return null;
    }
    return new PathResource(file, cleanName, context);
}
Also used : Path(java.nio.file.Path) InvalidPathException(java.nio.file.InvalidPathException)

Example 100 with InvalidPathException

use of java.nio.file.InvalidPathException in project jboss-modules by jboss-modules.

the class PathResourceLoader method getClassSpec.

@Override
public ClassSpec getClassSpec(final String fileName) throws IOException {
    final Path file;
    try {
        file = root.resolve(fileName);
    } catch (InvalidPathException ignored) {
        return null;
    }
    return doPrivilegedIfNeeded(context, IOException.class, () -> {
        if (!Files.exists(file)) {
            return null;
        }
        final ClassSpec spec = new ClassSpec();
        spec.setCodeSource(codeSource);
        spec.setBytes(Files.readAllBytes(file));
        return spec;
    });
}
Also used : Path(java.nio.file.Path) InvalidPathException(java.nio.file.InvalidPathException)

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