Source:
public CompletableFuture<FileWrapper> rename(String newFilename, FileWrapper parent, boolean overwrite, UserContext userContext) { if (! isLegalName(newFilename)) return CompletableFuture.completedFuture(parent); if (! parent.isWritable()) return Futures.errored(new IllegalStateException("You cannot rename something without write access to the parent!")); CompletableFuture<Optional<FileWrapper>> childExists = parent == null ? CompletableFuture.completedFuture(Optional.empty()) : parent.getDescendentByPath(newFilename, userContext.crypto.hasher, userContext.network); ensureUnmodified(); FileProperties currentProps = getFileProperties(); setModified(); return childExists .thenCompose(existing -> { if (existing.isPresent() && !overwrite) throw new IllegalStateException("Cannot rename, child already exists with name: " + newFilename); return ((overwrite && existing.isPresent()) ? existing.get().remove(parent, userContext) : CompletableFuture.completedFuture(parent) ).thenCompose(res -> { RetrievedCapability ourPointer = linkPointer.orElse(pointer); WritableAbsoluteCapability us = (WritableAbsoluteCapability) ourPointer.capability; CryptreeNode nodeToUpdate = ourPointer.fileAccess; boolean isDir = this.isDirectory(); boolean isLink = ourPointer.getProperties().isLink; FileProperties newProps = new FileProperties(newFilename, isDir, isLink, currentProps.mimeType, currentProps.size, currentProps.modified, currentProps.isHidden, currentProps.thumbnail, currentProps.streamSecret); SigningPrivateKeyAndPublicHash signer = isLink ? parent.signingPair() : signingPair(); return userContext.network.synchronizer.applyComplexUpdate(owner(), signer, (s, committer) -> nodeToUpdate.updateProperties(s, committer, us, entryWriter, newProps, userContext.network)) .thenApply(newVersion -> res.withVersion(newVersion)); }); }); }

Target:
public CompletableFuture<FileWrapper> rename(String newFilename, FileWrapper parent, boolean overwrite, UserContext userContext) { if (! isLegalName(newFilename)) return CompletableFuture.completedFuture(parent); if (! parent.isWritable()) return Futures.errored(new IllegalStateException("Unable to rename something without write access to the parent!")); CompletableFuture<Optional<FileWrapper>> childExists = parent == null ? CompletableFuture.completedFuture(Optional.empty()) : parent.getDescendentByPath(newFilename, userContext.crypto.hasher, userContext.network); ensureUnmodified(); FileProperties currentProps = getFileProperties(); setModified(); return childExists .thenCompose(existing -> { if (existing.isPresent() && !overwrite) throw new IllegalStateException("Cannot rename, child already exists with name: " + newFilename); return ((overwrite && existing.isPresent()) ? existing.get().remove(parent, userContext) : CompletableFuture.completedFuture(parent) ).thenCompose(res -> { RetrievedCapability ourPointer = linkPointer.orElse(pointer); WritableAbsoluteCapability us = (WritableAbsoluteCapability) ourPointer.capability; CryptreeNode nodeToUpdate = ourPointer.fileAccess; boolean isDir = this.isDirectory(); boolean isLink = ourPointer.getProperties().isLink; FileProperties newProps = new FileProperties(newFilename, isDir, isLink, currentProps.mimeType, currentProps.size, currentProps.modified, currentProps.isHidden, currentProps.thumbnail, currentProps.streamSecret); SigningPrivateKeyAndPublicHash signer = isLink ? parent.signingPair() : signingPair(); return userContext.network.synchronizer.applyComplexUpdate(owner(), signer, (s, committer) -> nodeToUpdate.updateProperties(s, committer, us, entryWriter, newProps, userContext.network)) .thenApply(newVersion -> res.withVersion(newVersion)); }); }); }