use of ch.cyberduck.core.sds.io.swagger.client.model.MoveNode in project cyberduck by iterate-ch.
the class SDSMoveFeature method move.
@Override
public Path move(final Path file, final Path renamed, final TransferStatus status, final Delete.Callback callback, final ConnectionCallback connectionCallback) throws BackgroundException {
try {
final long nodeId = Long.parseLong(nodeid.getVersionId(file, new DisabledListProgressListener()));
if (containerService.isContainer(file)) {
final Node node = new NodesApi(session.getClient()).updateRoom(new UpdateRoomRequest().name(renamed.getName()), nodeId, StringUtils.EMPTY, null);
nodeid.cache(renamed, file.attributes().getVersionId());
nodeid.cache(file, null);
return renamed.withAttributes(new SDSAttributesAdapter(session).toAttributes(node));
} else {
if (status.isExists()) {
// Handle case insensitive. Find feature will have reported target to exist if same name with different case
if (!new CaseInsensitivePathPredicate(file).test(renamed)) {
log.warn(String.format("Delete existing file %s", renamed));
new SDSDeleteFeature(session, nodeid).delete(Collections.singletonMap(renamed, status), connectionCallback, callback);
}
}
if (new SimplePathPredicate(file.getParent()).test(renamed.getParent())) {
// Rename only
if (file.isDirectory()) {
new NodesApi(session.getClient()).updateFolder(new UpdateFolderRequest().name(renamed.getName()), nodeId, StringUtils.EMPTY, null);
} else {
new NodesApi(session.getClient()).updateFile(new UpdateFileRequest().name(renamed.getName()), nodeId, StringUtils.EMPTY, null);
}
} else {
// Move to different parent
new NodesApi(session.getClient()).moveNodes(new MoveNodesRequest().resolutionStrategy(MoveNodesRequest.ResolutionStrategyEnum.OVERWRITE).addItemsItem(new MoveNode().id(nodeId).name(renamed.getName())).keepShareLinks(new HostPreferences(session.getHost()).getBoolean("sds.upload.sharelinks.keep")), Long.parseLong(nodeid.getVersionId(renamed.getParent(), new DisabledListProgressListener())), StringUtils.EMPTY, null);
}
nodeid.cache(renamed, file.attributes().getVersionId());
nodeid.cache(file, null);
// Copy original file attributes
return renamed.withAttributes(new PathAttributes(file.attributes()).withVersionId(String.valueOf(nodeId)));
}
} catch (ApiException e) {
throw new SDSExceptionMappingService(nodeid).map("Cannot rename {0}", e, file);
}
}
Aggregations