use of org.eclipse.che.api.vfs.VirtualFile in project che by eclipse.
the class LocalVirtualFileTest method deletesFile.
@Test
public void deletesFile() throws Exception {
VirtualFile folder = getRoot().createFolder(generateFolderName());
VirtualFile file = folder.createFile(generateFileName(), DEFAULT_CONTENT);
file.setProperty("property1", "value1");
Path filePath = file.getPath();
file.delete();
assertionHelper.assertThatIoFileDoesNotExist(filePath);
assertionHelper.assertThatMetadataIoFileDoesNotExist(filePath);
}
use of org.eclipse.che.api.vfs.VirtualFile in project che by eclipse.
the class LocalVirtualFileTest method addFolderInSearcherAfterExtractZipArchive.
@Test
public void addFolderInSearcherAfterExtractZipArchive() throws Exception {
VirtualFile folder = getRoot().createFolder(generateFolderName());
Mockito.reset(searcher);
Archiver archiver = mock(Archiver.class);
when(archiverFactory.createArchiver(eq(folder), eq("zip"))).thenReturn(archiver);
folder.unzip(new ByteArrayInputStream(new byte[0]), false, 0);
verify(searcher).add(folder);
}
use of org.eclipse.che.api.vfs.VirtualFile in project che by eclipse.
the class LocalVirtualFileTest method updatesContentOfLockedFileByStreamWithLockToken.
@Test
public void updatesContentOfLockedFileByStreamWithLockToken() throws Exception {
VirtualFile root = getRoot();
VirtualFile file = root.createFile(generateFileName(), DEFAULT_CONTENT);
String lockToken = file.lock(0);
file.updateContent(new ByteArrayInputStream("updated content".getBytes()), lockToken);
assertionHelper.assertThatIoFileHasContent(file.getPath(), "updated content".getBytes());
assertEquals("updated content", file.getContentAsString());
}
use of org.eclipse.che.api.vfs.VirtualFile in project che by eclipse.
the class LocalVirtualFileSystem method getFileLock.
private FileLock getFileLock(LocalVirtualFile virtualFile) throws ServerException {
final PathLockFactory.PathLock lockFilePathLock = pathLockFactory.getLock(virtualFile.getPath(), true).acquire(WAIT_FOR_FILE_LOCK_TIMEOUT);
try {
final FileLock lock;
try {
lock = lockTokensCache.get(virtualFile.getPath());
} catch (ExecutionException e) {
String errorMessage = String.format("Unable get lock of file '%s'", virtualFile.getPath());
LOG.error(errorMessage + "\n" + e.getCause().getMessage(), e.getCause());
throw new ServerException(errorMessage);
}
if (NO_LOCK == lock) {
return lock;
}
if (lock.getExpired() < System.currentTimeMillis()) {
final File fileLockIoFile = getFileLockIoFile(virtualFile.getPath());
if (!fileLockIoFile.delete()) {
if (fileLockIoFile.exists()) {
FileCleaner.addFile(fileLockIoFile);
LOG.warn("Unable delete lock file %s", fileLockIoFile);
}
}
lockTokensCache.put(virtualFile.getPath(), NO_LOCK);
return NO_LOCK;
}
return lock;
} finally {
lockFilePathLock.release();
}
}
use of org.eclipse.che.api.vfs.VirtualFile in project che by eclipse.
the class MemoryVirtualFile method copyTo.
@Override
public VirtualFile copyTo(VirtualFile parent, String newName, boolean overwrite) throws ForbiddenException, ConflictException, ServerException {
checkExistence();
((MemoryVirtualFile) parent).checkExistence();
if (isRoot()) {
throw new ServerException("Unable copy root folder");
}
if (newName == null || newName.trim().isEmpty()) {
newName = this.getName();
}
if (parent.isFolder()) {
VirtualFile copy = doCopy((MemoryVirtualFile) parent, newName, overwrite);
addInSearcher(copy);
return copy;
} else {
throw new ForbiddenException(String.format("Unable create copy of '%s'. Item '%s' specified as parent is not a folder.", getPath(), parent.getPath()));
}
}
Aggregations