public void setRemoteLocation(RemoteFile remoteFile) { remoteLocation = remoteFile.getName(); }
/** * Initializes a new randomly named temp file. * * @throws StorageException */ public TempRemoteFile(RemoteFile targetRemoteFile) throws StorageException { super(String.format(NAME_FORMAT, CipherUtil.createRandomAlphabeticString(5), targetRemoteFile.getName())); }
private File getRemoteFile(RemoteFile remoteFile) { String rootPath = getRemoteFilePath(remoteFile.getClass()); return Paths.get(rootPath, remoteFile.getName()).toFile(); }
if (deletedFile.getClass().equals(remoteFileClass)) { T concreteDeletedFile = remoteFileClass.cast(deletedFile); filteredFiles.put(concreteDeletedFile.getName(), concreteDeletedFile);
/** * Returns the subpath identifier for this file. For {@link MultichunkRemoteFile}s, this is the * hex string of the multichunk identifier. For all other files, this is the 128-bit murmur3 hash * of the full filename (fast algorithm!). */ private String getSubPathId(RemoteFile remoteFile) { if (remoteFile.getClass() == MultichunkRemoteFile.class) { return StringUtil.toHex(((MultichunkRemoteFile) remoteFile).getMultiChunkId()); } else { return StringUtil.toHex(Hashing.murmur3_128().hashString(remoteFile.getName(), Charsets.UTF_8).asBytes()); } }
@Override public void printResults(OperationResult operationResult) { LsRemoteOperationResult concreteOperationResult = (LsRemoteOperationResult) operationResult; List<DatabaseRemoteFile> remoteStatus = concreteOperationResult.getUnknownRemoteDatabases(); if (remoteStatus.size() > 0) { for (RemoteFile unknownRemoteFile : remoteStatus) { out.println("? "+unknownRemoteFile.getName()); } } else { out.println("No remote changes."); } }
logger.log(Level.INFO, "File {0} not found, checking if it is being deleted ...", remoteFile.getName()); new Object[] { remoteFile.getName(), tempRemoteFile.getName() }); logger.log(Level.WARNING, "-> File {0} does not exist and is not in any transaction. Throwing exception.", remoteFile.getName()); throw new StorageFileNotFoundException("File " + remoteFile.getName() + " does not exist and is not in any transaction");
@Override public void move(RemoteFile sourceFile, RemoteFile targetFile) throws StorageException { String operationType = "move"; String operationDescription = "move(" + sourceFile.getName() + "," + targetFile.getName() + ")"; if (isNextOperationSuccessful(operationType, operationDescription)) { super.move(sourceFile, targetFile); } else { throw new StorageException("Operation failed: " + operationDescription); } }
@Override public void download(RemoteFile remoteFile, File localFile) throws StorageException { String operationType = "download"; String operationDescription = "download(" + remoteFile.getName() + ", " + localFile.getAbsolutePath() + ")"; if (isNextOperationSuccessful(operationType, operationDescription)) { super.download(remoteFile, localFile); } else { throw new StorageException("Operation failed: " + operationDescription); } }
@Override public void upload(File localFile, RemoteFile remoteFile) throws StorageException { String operationType = "upload"; String operationDescription = "upload(" + localFile.getAbsolutePath() + ", " + remoteFile.getName() + ")"; if (isNextOperationSuccessful(operationType, operationDescription)) { super.upload(localFile, remoteFile); } else { throw new StorageException("Operation failed: " + operationDescription); } }
@Override public boolean delete(RemoteFile remoteFile) throws StorageException { String operationType = "delete"; String operationDescription = "delete(" + remoteFile.getName() + ")"; if (isNextOperationSuccessful(operationType, operationDescription)) { return super.delete(remoteFile); } else { throw new StorageException("Operation failed: " + operationDescription); } }
/** * Adds the opposite actions (rollback actions) for the given unfinished actions * to the rollback transaction. */ private void rollbackActions(List<ActionTO> unfinishedActions) throws StorageException { for (ActionTO action : unfinishedActions) { logger.log(Level.INFO, "- Needs to be rolled back: " + action); switch (action.getType()) { case UPLOAD: delete(action.getRemoteFile()); delete(action.getTempRemoteFile()); break; case DELETE: try { logger.log(Level.INFO, "- Rollback action: Moving " + action.getTempRemoteFile().getName() + " to " + action.getRemoteFile().getName()); move(action.getTempRemoteFile(), action.getRemoteFile()); } catch (StorageMoveException e) { logger.log(Level.WARNING, "Restoring deleted file failed. This might be a problem if the original: " + action.getRemoteFile() + " also does not exist.", e); } break; default: throw new RuntimeException("Transaction contains invalid type: " + action.getType() + ". This should not happen."); } } }