Search in sources :

Example 11 with MCRFilesystemNode

use of org.mycore.datamodel.ifs.MCRFilesystemNode in project mycore by MyCoRe-Org.

the class MCRTransferPackageFileContainer method processNode.

/**
 * @param node the node to process
 */
private void processNode(MCRFilesystemNode node) {
    MCRDirectory dir = (MCRDirectory) node;
    MCRFilesystemNode[] children = dir.getChildren();
    for (MCRFilesystemNode child : children) {
        if (child instanceof MCRDirectory) {
            processNode(child);
        }
        if (child instanceof MCRFile) {
            this.fileList.add((MCRFile) child);
        }
    }
}
Also used : MCRFile(org.mycore.datamodel.ifs.MCRFile) MCRDirectory(org.mycore.datamodel.ifs.MCRDirectory) MCRFilesystemNode(org.mycore.datamodel.ifs.MCRFilesystemNode)

Example 12 with MCRFilesystemNode

use of org.mycore.datamodel.ifs.MCRFilesystemNode in project mycore by MyCoRe-Org.

the class MCRDirectoryStream method deleteFileSystemNode.

/**
 * Deletes {@link MCRFilesystemNode} if it exists.
 *
 * @param path
 *            relative or absolute
 * @throws IOException
 */
private void deleteFileSystemNode(MCRPath path) throws IOException {
    checkClosed();
    if (path.isAbsolute()) {
        Files.delete(path);
    }
    MCRFilesystemNode childByPath = dir.getChildByPath(path.toString());
    if (childByPath == null) {
        throw new NoSuchFileException(dir.toPath().toString(), path.toString(), null);
    }
    try {
        childByPath.delete();
    } catch (MCRPersistenceException e) {
        throw new IOException("Error whil deleting file system node.", e);
    }
}
Also used : MCRFilesystemNode(org.mycore.datamodel.ifs.MCRFilesystemNode) NoSuchFileException(java.nio.file.NoSuchFileException) IOException(java.io.IOException) MCRPersistenceException(org.mycore.common.MCRPersistenceException)

Example 13 with MCRFilesystemNode

use of org.mycore.datamodel.ifs.MCRFilesystemNode in project mycore by MyCoRe-Org.

the class MCRFileSystemProvider method resolvePath.

static MCRFilesystemNode resolvePath(MCRPath path) throws IOException {
    try {
        String ifsid = nodeCache.getUnchecked(path);
        MCRFilesystemNode node = MCRFilesystemNode.getNode(ifsid);
        if (node != null) {
            return node;
        }
        nodeCache.invalidate(path);
        return resolvePath(path);
    } catch (UncheckedExecutionException e) {
        Throwable cause = e.getCause();
        if (cause instanceof NoSuchFileException) {
            throw (NoSuchFileException) cause;
        }
        if (cause instanceof NotDirectoryException) {
            throw (NotDirectoryException) cause;
        }
        if (cause instanceof IOException) {
            throw (IOException) cause;
        }
        throw e;
    }
}
Also used : NotDirectoryException(java.nio.file.NotDirectoryException) MCRFilesystemNode(org.mycore.datamodel.ifs.MCRFilesystemNode) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) NoSuchFileException(java.nio.file.NoSuchFileException) IOException(java.io.IOException)

Example 14 with MCRFilesystemNode

use of org.mycore.datamodel.ifs.MCRFilesystemNode in project mycore by MyCoRe-Org.

the class MCRFileSystemProvider method newDirectoryStream.

/* (non-Javadoc)
     * @see java.nio.file.spi.FileSystemProvider#newDirectoryStream(java.nio.file.Path, java.nio.file.DirectoryStream.Filter)
     */
@Override
public DirectoryStream<Path> newDirectoryStream(Path dir, Filter<? super Path> filter) throws IOException {
    MCRPath mcrPath = MCRFileSystemUtils.checkPathAbsolute(dir);
    MCRFilesystemNode node = resolvePath(mcrPath);
    if (node instanceof MCRDirectory) {
        return new MCRDirectoryStream((MCRDirectory) node, mcrPath);
    }
    throw new NotDirectoryException(dir.toString());
}
Also used : NotDirectoryException(java.nio.file.NotDirectoryException) MCRFilesystemNode(org.mycore.datamodel.ifs.MCRFilesystemNode) MCRDirectory(org.mycore.datamodel.ifs.MCRDirectory) MCRPath(org.mycore.datamodel.niofs.MCRPath)

Example 15 with MCRFilesystemNode

use of org.mycore.datamodel.ifs.MCRFilesystemNode in project mycore by MyCoRe-Org.

the class MCRFileSystemProvider method createDirectory.

/* (non-Javadoc)
     * @see java.nio.file.spi.FileSystemProvider#createDirectory(java.nio.file.Path, java.nio.file.attribute.FileAttribute[])
     */
@Override
public void createDirectory(Path dir, FileAttribute<?>... attrs) throws IOException {
    if (attrs.length > 0) {
        throw new UnsupportedOperationException("Setting 'attrs' atomically is unsupported.");
    }
    MCRPath mcrPath = MCRFileSystemUtils.checkPathAbsolute(dir);
    MCRDirectory rootDirectory;
    if (mcrPath.isAbsolute() && mcrPath.getNameCount() == 0) {
        rootDirectory = MCRDirectory.getDirectory(mcrPath.getOwner());
        if (rootDirectory != null) {
            throw new FileAlreadyExistsException(mcrPath.toString());
        }
        rootDirectory = new MCRDirectory(mcrPath.getOwner());
        return;
    }
    rootDirectory = getRootDirectory(mcrPath);
    MCRPath parentPath = mcrPath.getParent();
    MCRPath absolutePath = getAbsolutePathFromRootComponent(parentPath);
    MCRFilesystemNode childByPath = rootDirectory.getChildByPath(absolutePath.toString());
    if (childByPath == null) {
        throw new NoSuchFileException(parentPath.toString(), dir.getFileName().toString(), "parent directory does not exist");
    }
    if (childByPath instanceof MCRFile) {
        throw new NotDirectoryException(parentPath.toString());
    }
    MCRDirectory parentDir = (MCRDirectory) childByPath;
    String dirName = mcrPath.getFileName().toString();
    if (parentDir.getChild(dirName) != null) {
        throw new FileAlreadyExistsException(mcrPath.toString());
    }
    new MCRDirectory(dirName, parentDir);
}
Also used : MCRFile(org.mycore.datamodel.ifs.MCRFile) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) NotDirectoryException(java.nio.file.NotDirectoryException) MCRDirectory(org.mycore.datamodel.ifs.MCRDirectory) MCRFilesystemNode(org.mycore.datamodel.ifs.MCRFilesystemNode) NoSuchFileException(java.nio.file.NoSuchFileException) MCRPath(org.mycore.datamodel.niofs.MCRPath)

Aggregations

MCRFilesystemNode (org.mycore.datamodel.ifs.MCRFilesystemNode)19 MCRDirectory (org.mycore.datamodel.ifs.MCRDirectory)12 MCRPath (org.mycore.datamodel.niofs.MCRPath)11 MCRFile (org.mycore.datamodel.ifs.MCRFile)10 NoSuchFileException (java.nio.file.NoSuchFileException)9 IOException (java.io.IOException)5 NotDirectoryException (java.nio.file.NotDirectoryException)5 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)3 DirectoryNotEmptyException (java.nio.file.DirectoryNotEmptyException)2 Path (java.nio.file.Path)2 BasicFileAttributeView (java.nio.file.attribute.BasicFileAttributeView)2 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 Field (java.lang.reflect.Field)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 CopyOption (java.nio.file.CopyOption)1 InvalidPathException (java.nio.file.InvalidPathException)1 LinkOption (java.nio.file.LinkOption)1