use of org.eclipse.che.api.vfs.VirtualFile in project che by eclipse.
the class MemoryVirtualFile method moveTo.
@Override
public VirtualFile moveTo(VirtualFile parent, String newName, boolean overwrite, String lockToken) throws ForbiddenException, ConflictException, ServerException {
checkExistence();
MemoryVirtualFile memoryParent = (MemoryVirtualFile) parent;
memoryParent.checkExistence();
if (isRoot()) {
throw new ForbiddenException("Unable move root folder");
}
if (!parent.isFolder()) {
throw new ForbiddenException("Unable move item. Item specified as parent is not a folder");
}
if (newName == null || newName.trim().isEmpty()) {
newName = this.getName();
}
final boolean isFile = isFile();
final Path myPath = getPath();
final Path newParentPath = parent.getPath();
final boolean folder = isFolder();
if (folder) {
if (newParentPath.isChild(myPath)) {
throw new ForbiddenException(String.format("Unable move item %s to %s. Item may not have itself as parent", myPath, newParentPath));
}
final List<VirtualFile> lockedFiles = new LockedFileFinder(this).findLockedFiles();
if (!lockedFiles.isEmpty()) {
throw new ForbiddenException(String.format("Unable move item '%s'. Child items '%s' are locked", getName(), lockedFiles));
}
} else if (fileIsLockedAndLockTokenIsInvalid(lockToken)) {
throw new ForbiddenException(String.format("Unable move item %s. Item is locked", myPath));
}
if (overwrite) {
MemoryVirtualFile existedItem = memoryParent.children.get(newName);
if (existedItem != null) {
existedItem.delete();
}
}
if (memoryParent.children.containsKey(newName)) {
throw new ConflictException(String.format("Item '%s' already exists", parent.getPath().newPath(newName)));
}
this.parent.children.remove(name);
memoryParent.children.put(newName, this);
this.parent = memoryParent;
this.name = newName;
lock = null;
deleteFromSearcher(myPath, isFile);
addInSearcher(this);
return this;
}
use of org.eclipse.che.api.vfs.VirtualFile in project che by eclipse.
the class DefaultFileWatcherNotificationHandler method convertToVirtualFile.
private VirtualFile convertToVirtualFile(File root, String subPath, boolean isDir) {
try {
LocalVirtualFileSystem virtualFileSystem = (LocalVirtualFileSystem) virtualFileSystemProvider.getVirtualFileSystem(true);
Path vfsPath = Path.of(subPath);
VirtualFile virtualFile = virtualFileSystem.getRoot().getChild(vfsPath);
if (virtualFile == null) {
virtualFile = new DeletedLocalVirtualFile(new File(root, subPath), ROOT.newPath(vfsPath), virtualFileSystem, isDir);
}
return virtualFile;
} catch (ServerException e) {
LOG.warn(e.getMessage());
}
return null;
}
use of org.eclipse.che.api.vfs.VirtualFile in project che by eclipse.
the class IndexedFileUpdateConsumer method accept.
@Override
public void accept(Path path) {
try {
VirtualFileSystem virtualFileSystem = vfsProvider.getVirtualFileSystem();
SearcherProvider searcherProvider = virtualFileSystem.getSearcherProvider();
Searcher searcher = searcherProvider.getSearcher(virtualFileSystem);
Path innerPath = root.toPath().relativize(path);
org.eclipse.che.api.vfs.Path vfsPath = org.eclipse.che.api.vfs.Path.of(innerPath.toString());
VirtualFile child = virtualFileSystem.getRoot().getChild(vfsPath);
if (child != null) {
searcher.update(child);
}
} catch (ServerException e) {
LOG.error("Issue happened during updating modified file in index", e);
}
}
use of org.eclipse.che.api.vfs.VirtualFile in project che by eclipse.
the class LocalVirtualFileSystem method doGetChildren.
private List<VirtualFile> doGetChildren(LocalVirtualFile parent, FilenameFilter ioFileFilter, VirtualFileFilter vfsFilter) throws ServerException {
if (ioFileFilter == null) {
ioFileFilter = IoUtil.ANY_FILTER;
}
final String[] names = parent.toIoFile().list(ioFileFilter);
if (names == null) {
throw new ServerException(String.format("Unable get children of '%s'", parent.getPath()));
}
if (vfsFilter == null) {
vfsFilter = VirtualFileFilter.ACCEPT_ALL;
}
final List<VirtualFile> children = newArrayListWithCapacity(names.length);
for (String name : names) {
final Path childPath = parent.getPath().newPath(name);
final LocalVirtualFile child = new LocalVirtualFile(new File(ioRoot, toIoPath(childPath)), childPath, this);
if (vfsFilter.accept(child)) {
children.add(child);
}
}
return children;
}
use of org.eclipse.che.api.vfs.VirtualFile in project che by eclipse.
the class LocalVirtualFileSystem method doDelete.
private void doDelete(LocalVirtualFile virtualFile, String lockToken) throws ForbiddenException, ServerException {
if (virtualFile.isFolder()) {
final List<VirtualFile> lockedFiles = new LockedFileFinder(virtualFile).findLockedFiles();
if (!lockedFiles.isEmpty()) {
throw new ForbiddenException(String.format("Unable delete folder '%s'. Child items '%s' are locked", virtualFile.getPath(), lockedFiles));
}
} else if (fileIsLockedAndLockTokenIsInvalid(virtualFile, lockToken)) {
throw new ForbiddenException(String.format("Unable delete file '%s'. File is locked", virtualFile.getPath()));
}
cleanUpCaches();
final File fileLockIoFile = getFileLockIoFile(virtualFile.getPath());
if (fileLockIoFile.delete()) {
if (fileLockIoFile.exists()) {
LOG.error("Unable delete lock file {}", fileLockIoFile);
throw new ServerException(String.format("Unable delete item '%s'", virtualFile.getPath()));
}
}
final File metadataIoFile = getMetadataIoFile(virtualFile.getPath());
if (metadataIoFile.delete()) {
if (metadataIoFile.exists()) {
LOG.error("Unable delete metadata file {}", metadataIoFile);
throw new ServerException(String.format("Unable delete item '%s'", virtualFile.getPath()));
}
}
if (!deleteRecursive(virtualFile.toIoFile())) {
LOG.error("Unable delete file {}", virtualFile.toIoFile());
throw new ServerException(String.format("Unable delete item '%s'", virtualFile.getPath()));
}
}
Aggregations