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);
}
}
}
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);
}
}
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;
}
}
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());
}
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);
}
Aggregations