public void setRemoteLocation(RemoteFile remoteFile) { remoteLocation = remoteFile.getName(); }
public void setRemoteTempLocation(TempRemoteFile tempRemoteFile) { remoteTempLocation = tempRemoteFile.getName(); }
public RemoteFile getRemoteFile() throws StorageException { return RemoteFile.createRemoteFile(remoteLocation); }
/** * 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 int compareTo(DatabaseRemoteFile r2) { int clientNameCompare = getClientName().compareTo(r2.getClientName()); if (clientNameCompare != 0) { return clientNameCompare; } else { return (int) (getClientVersion() - r2.getClientVersion()); } }
private void uploadMasterFile(File masterFile, TransferManager transferManager) throws Exception { transferManager.upload(masterFile, new MasterRemoteFile()); }
@Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((clientName == null) ? 0 : clientName.hashCode()); result = prime * result + (int) (clientVersion ^ (clientVersion >>> 32)); return result; }
private boolean isOutdatedActionFile(ActionRemoteFile actionFile) { // TODO [low] Even though this is UTC and the times frames are large, this might be an issue with different timezones or wrong system clocks return System.currentTimeMillis() - ACTION_FILE_DELETE_TIME > actionFile.getTimestamp(); }
/** * Creates a new remote file by its name. The name is used by {@link TransferManager}s * to identify a file on the remote storage. * * <p>The constructor parses and validates the given name using the * {@link #validateName(String) validateName()} method. While <tt>RemoteFile</tt> has no name * pattern (and never throws an exception), sub-classes might. * * <p><b>Important:</b> Sub-classes must also implement a one-parameter constructor that takes a * <tt>String</tt> argument. This constructor is required by the {@link RemoteFileFactory}. * * @param name The name of the file (as it is identified by Syncany) * @throws StorageException If the name does not match the name pattern defined by the class.<br /> * <b>Note:</b> <tt>RemoteFile</tt> does never throw this exceptions, however, subclasses might. */ public RemoteFile(String name) throws StorageException { this.name = validateName(name); this.attributes = Maps.newHashMap(); }
protected long getLastRemoteCleanupNumber(Map<String, CleanupRemoteFile> cleanupFiles) { long cleanupNumber = 0; // Find the number of the last cleanup for (CleanupRemoteFile cleanupRemoteFile : cleanupFiles.values()) { cleanupNumber = Math.max(cleanupNumber, cleanupRemoteFile.getCleanupNumber()); } return cleanupNumber; }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!super.equals(obj)) { return false; } if (!(obj instanceof DatabaseRemoteFile)) { return false; } DatabaseRemoteFile other = (DatabaseRemoteFile) obj; if (clientName == null) { if (other.clientName != null) { return false; } } else if (!clientName.equals(other.clientName)) { return false; } if (clientVersion != other.clientVersion) { return false; } return true; }
private void uploadRepoFile(File repoFile, TransferManager transferManager) throws Exception { transferManager.upload(repoFile, new SyncanyRemoteFile()); } }
public ActionFileHandler(TransferManager transferManager, String operationName, String machineName) { try { this.transferManager = transferManager; this.actionFile = new ActionRemoteFile(operationName, machineName, System.currentTimeMillis()); this.actionRenewalTimer = createNewActionRenewalTimer(); } catch (Exception e) { throw new RuntimeException(e); } }
private RemoteFile createPathAwareRemoteFile(RemoteFile remoteFile) throws StorageException { PathAwareRemoteFileAttributes pathAwareRemoteFileAttributes = new PathAwareRemoteFileAttributes(); remoteFile.setAttributes(pathAwareRemoteFileAttributes); if (isFolderizable(remoteFile.getClass())) { // If remote file is folderizable, i.e. an 'affected file', // get the sub-path for it String subPathId = getSubPathId(remoteFile); String subPath = getSubPath(subPathId); pathAwareRemoteFileAttributes.setPath(subPath); } return remoteFile; }
/** * Adds the deletion of a file to this transaction. Generates a temporary file * to store it while the transaction is being finalized. */ public void delete(RemoteFile remoteFile) throws StorageException { TempRemoteFile temporaryRemoteFile = new TempRemoteFile(remoteFile); logger.log(Level.INFO, "- Adding file to TX for DELETE: " + remoteFile + "-> Temp. remote file: " + temporaryRemoteFile); ActionTO action = new ActionTO(); action.setType(ActionType.DELETE); action.setRemoteLocation(remoteFile); action.setRemoteTempLocation(temporaryRemoteFile); transactionTO.addAction(action); }
/** * 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())); }
public TempRemoteFile getTempRemoteFile() { try { return RemoteFile.createRemoteFile(remoteTempLocation, TempRemoteFile.class); } catch (StorageException e) { logger.log(Level.INFO, "Invalid remote temporary filename: " + remoteTempLocation, e); return null; } }
private SaltedSecretKey askPasswordAndCreateMasterKey() throws CipherException, StorageException { File tmpMasterFile = downloadFile(transferManager, new MasterRemoteFile()); MasterTO masterTO = readMasterFile(tmpMasterFile); tmpMasterFile.delete(); String masterKeyPassword = getOrAskPassword(); byte[] masterKeySalt = masterTO.getSalt(); return createMasterKeyFromPassword(masterKeyPassword, masterKeySalt); // This takes looong! }
@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 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); } }