if(status.isExists()) { log.warn(String.format("Delete existing file %s", file)); delete.delete(Collections.singletonList(file), callback, new Delete.DisabledCallback());
log.info(String.format("Rename file %s to %s", file, status.getDisplayname().remote)); move.move(file, status.getDisplayname().remote, status, new Delete.DisabledCallback(), new DisabledConnectionCallback());
session.getFeature(Delete.class).delete(Collections.singletonList(r.getKey()), callback, new Delete.DisabledCallback());
if(!segments.isEmpty()) { new SwiftMultipleDeleteFeature(session).delete(segments, callback, new Delete.DisabledCallback());
@Override public Path copy(final Path source, final Path target, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { final OneDriveCopyOperation copyOperation = new OneDriveCopyOperation(); if(!StringUtils.equals(source.getName(), target.getName())) { copyOperation.rename(target.getName()); } if(status.isExists()) { new GraphDeleteFeature(session).delete(Collections.singletonList(target), callback, new Delete.DisabledCallback()); } final OneDriveFolder targetItem = session.toFolder(target.getParent()); copyOperation.copy(targetItem); final OneDriveItem item = session.toItem(source); try { item.copy(copyOperation).await(statusObject -> logger.info(String.format("Copy Progress Operation %s progress %f status %s", statusObject.getOperation(), statusObject.getPercentage(), statusObject.getStatus()))); target.attributes().setVersionId(null); return new Path(target.getParent(), target.getName(), target.getType(), new GraphAttributesFinderFeature(session).find(target)); } catch(OneDriveAPIException e) { throw new GraphExceptionMappingService().map("Cannot copy {0}", e, source); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Cannot copy {0}", e, source); } }
/** * Rename existing file on server if there is a conflict. */ @Override public void apply(final Path file, final Local local, final TransferStatus status, final ProgressListener listener) throws BackgroundException { // Rename existing file before putting new file in place if(status.isExists()) { Path rename; do { final String proposal = MessageFormat.format(PreferencesFactory.get().getProperty("queue.upload.file.rename.format"), FilenameUtils.getBaseName(file.getName()), UserDateFormatterFactory.get().getMediumFormat(System.currentTimeMillis(), false).replace(Path.DELIMITER, '-').replace(':', '-'), StringUtils.isNotBlank(file.getExtension()) ? String.format(".%s", file.getExtension()) : StringUtils.EMPTY); rename = new Path(file.getParent(), proposal, file.getType()); } while(find.withCache(cache).find(rename)); if(log.isInfoEnabled()) { log.info(String.format("Rename existing file %s to %s", file, rename)); } move.move(file, rename, new TransferStatus().exists(false), new Delete.DisabledCallback(), new DisabledConnectionCallback()); if(log.isDebugEnabled()) { log.debug(String.format("Clear exist flag for file %s", file)); } status.setExists(false); } super.apply(file, local, status, listener); } }
@Override public Path copy(final Path source, final Path target, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { if(status.isExists()) { new DropboxDeleteFeature(session).delete(Collections.singletonList(target), callback, new Delete.DisabledCallback()); } // If the source path is a folder all its contents will be copied. new DbxUserFilesRequests(session.getClient()).copyV2(source.getAbsolute(), target.getAbsolute()); return target; } catch(DbxException e) { throw new DropboxExceptionMappingService().map("Cannot copy {0}", e, source); } }