Search in sources :

Example 21 with VirtualFile

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);
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) Path(org.eclipse.che.api.vfs.Path) Test(org.junit.Test)

Example 22 with VirtualFile

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);
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) ByteArrayInputStream(java.io.ByteArrayInputStream) Archiver(org.eclipse.che.api.vfs.Archiver) Test(org.junit.Test)

Example 23 with VirtualFile

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());
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test)

Example 24 with VirtualFile

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();
    }
}
Also used : PathLockFactory(org.eclipse.che.api.vfs.PathLockFactory) ServerException(org.eclipse.che.api.core.ServerException) ExecutionException(java.util.concurrent.ExecutionException) VirtualFile(org.eclipse.che.api.vfs.VirtualFile) File(java.io.File)

Example 25 with VirtualFile

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()));
    }
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ServerException(org.eclipse.che.api.core.ServerException)

Aggregations

VirtualFile (org.eclipse.che.api.vfs.VirtualFile)321 Test (org.junit.Test)267 Path (org.eclipse.che.api.vfs.Path)62 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)54 ByteArrayInputStream (java.io.ByteArrayInputStream)32 ConflictException (org.eclipse.che.api.core.ConflictException)28 VirtualFileSystem (org.eclipse.che.api.vfs.VirtualFileSystem)27 MemoryVirtualFileSystem (org.eclipse.che.api.vfs.impl.memory.MemoryVirtualFileSystem)22 QueryExpression (org.eclipse.che.api.vfs.search.QueryExpression)22 ServerException (org.eclipse.che.api.core.ServerException)18 Test (org.testng.annotations.Test)18 File (java.io.File)17 Archiver (org.eclipse.che.api.vfs.Archiver)14 InputStream (java.io.InputStream)10 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)7 OutputStream (java.io.OutputStream)6 LockedFileFinder (org.eclipse.che.api.vfs.LockedFileFinder)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 Map (java.util.Map)5