use of org.eclipse.che.api.core.ServerException in project che by eclipse.
the class LocalVirtualFileSystem method doCopy.
private void doCopy(LocalVirtualFile from, LocalVirtualFile to) throws ServerException {
try {
// First copy metadata (properties) for source. If we do in this way and fail cause to any i/o or other error client
// will see error and may try to copy again. But if we successfully copy tree (or single file) and then fail to copy
// metadata client may not try to copy again because copy destination already exists.
final File fromMetadataFile = getMetadataIoFile(from.getPath());
final File toMetadataFile = getMetadataIoFile(to.getPath());
if (fromMetadataFile.exists()) {
IoUtil.copy(fromMetadataFile, toMetadataFile, null);
}
IoUtil.copy(from.toIoFile(), to.toIoFile(), VFS_LOCK_FILTER);
} catch (IOException e) {
String errorMessage = String.format("Unable copy '%s' to '%s'", from, to);
LOG.error(errorMessage + "\n" + e.getMessage(), e);
throw new ServerException(errorMessage);
}
}
use of org.eclipse.che.api.core.ServerException in project che by eclipse.
the class LocalVirtualFileSystem method doUnlock.
private void doUnlock(LocalVirtualFile virtualFile) throws ForbiddenException, ServerException {
try {
final File fileLockIoFile = getFileLockIoFile(virtualFile.getPath());
if (!fileLockIoFile.delete()) {
if (fileLockIoFile.exists()) {
throw new IOException(String.format("Unable delete lock file %s", fileLockIoFile));
}
}
lockTokensCache.put(virtualFile.getPath(), NO_LOCK);
} catch (IOException e) {
String errorMessage = String.format("Unable unlock file '%s'", virtualFile.getPath());
LOG.error(errorMessage + "\n" + e.getMessage(), e);
throw new ServerException(errorMessage);
}
}
use of org.eclipse.che.api.core.ServerException in project che by eclipse.
the class LocalVirtualFileSystem method doLock.
private String doLock(LocalVirtualFile virtualFile, long timeout) throws ConflictException, ServerException {
try {
if (NO_LOCK == lockTokensCache.get(virtualFile.getPath())) {
final FileLock lock = createLock(timeout);
final File fileLockIoFile = getFileLockIoFile(virtualFile.getPath());
fileLockIoFile.getParentFile().mkdirs();
try (DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(fileLockIoFile)))) {
locksSerializer.write(dos, lock);
}
lockTokensCache.put(virtualFile.getPath(), lock);
return lock.getLockToken();
}
throw new ConflictException(String.format("Unable lock file '%s'. File already locked", virtualFile.getPath()));
} catch (IOException | ExecutionException e) {
String errorMessage = String.format("Unable lock file '%s'", virtualFile.getPath());
if (e instanceof ExecutionException) {
LOG.error(errorMessage + "\n" + e.getCause().getMessage(), e.getCause());
} else {
LOG.error(errorMessage + "\n" + e.getMessage(), e);
}
throw new ServerException(errorMessage);
}
}
use of org.eclipse.che.api.core.ServerException in project che by eclipse.
the class LocalVirtualFileSystem method doUpdateProperties.
private void doUpdateProperties(LocalVirtualFile virtualFile, Map<String, String> updates) throws ServerException {
try {
final Map<String, String> properties = getProperties(virtualFile);
for (Map.Entry<String, String> entry : updates.entrySet()) {
if (entry.getValue() == null) {
properties.remove(entry.getKey());
} else {
properties.put(entry.getKey(), entry.getValue());
}
}
final File metadataIoFile = getMetadataIoFile(virtualFile.getPath());
if (properties.isEmpty()) {
if (!metadataIoFile.delete()) {
if (metadataIoFile.exists()) {
LOG.error("Unable delete metadata file {}", metadataIoFile);
throw new IOException(String.format("Unable update properties of item '%s'", virtualFile.getPath()));
}
}
} else {
metadataIoFile.getParentFile().mkdirs();
try (DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(metadataIoFile)))) {
metadataSerializer.write(dos, properties);
}
}
metadataCache.put(virtualFile.getPath(), properties);
if (!virtualFile.toIoFile().setLastModified(System.currentTimeMillis())) {
LOG.warn("Unable to set timestamp to '{}'", virtualFile.toIoFile());
}
} catch (IOException e) {
String errorMessage = String.format("Unable lock file '%s'", virtualFile.getPath());
LOG.error(errorMessage + "\n" + e.getMessage(), e);
throw new ServerException(errorMessage);
}
}
use of org.eclipse.che.api.core.ServerException in project che by eclipse.
the class LocalVirtualFileSystem method unzip.
void unzip(LocalVirtualFile parent, InputStream zipped, boolean overwrite, int stripNumber) throws ForbiddenException, ConflictException, ServerException {
if (archiverFactory == null)
throw new ServerException("VFS: Could not create zip archiver. Archiver Factory is not properly configured (is null)");
if (parent.isFolder()) {
extract(archiverFactory.createArchiver(parent, "zip"), zipped, overwrite, stripNumber);
addInSearcher(parent);
} else {
throw new ForbiddenException(String.format("Unable import zip content. Item '%s' is not a folder", parent.getPath()));
}
}
Aggregations