Source:
<code><START> public CompletableFuture<Snapshot> copyTo(FileWrapper target, UserContext context) { <END> ensureUnmodified(); NetworkAccess network = context.network; SafeRandom random = context.crypto.random; Hasher hasher = context.crypto.hasher; if (! target.isDirectory()) { return Futures.errored(new IllegalStateException("CopyTo target " + target + " must be a directory")); } return context.network.synchronizer.applyComplexUpdate(target.owner(), target.signingPair(), (base, committer) -> { return target.hasChildWithName(base.get(target.writer()).props, getFileProperties().name, network).thenCompose(childExists -> { if (childExists) { CompletableFuture<Snapshot> error = new CompletableFuture<>(); error.completeExceptionally(new IllegalStateException("CopyTo target " + target + " already has child with name " + getFileProperties().name)); return error; } if (isDirectory()) { byte[] newMapKey = random.randomBytes(32); SymmetricKey newBaseKey = SymmetricKey.random(); SymmetricKey newWriterBaseKey = SymmetricKey.random(); WritableAbsoluteCapability newCap = new WritableAbsoluteCapability(target.owner(), target.writer(), newMapKey, newBaseKey, newWriterBaseKey); SymmetricKey newParentParentKey = target.getParentKey(); return pointer.fileAccess.copyTo(base, committer, pointer.capability, newBaseKey, target.writableFilePointer(), target.entryWriter, newParentParentKey, newMapKey, network, random, hasher) .thenCompose(updatedBase -> { return target.addLinkTo(updatedBase, committer, getName(), newCap, network, random, hasher); }); } else { return base.withWriter(owner(), writer(), network).thenCompose(snapshot -> getInputStream(snapshot.get(writer()).props, network, random, x -> {}) .thenCompose(stream -> target.uploadFileSection(snapshot, committer, getName(), stream, false, 0, getSize(), Optional.empty(), false, network, random, hasher, x -> {}, target.generateChildLocations(props.getNumberOfChunks(), random)))); } }); }); }</code><technical_language>this impact web-ui code. Do want expose Snapshot in API</technical_language>

Target:
public CompletableFuture<Boolean> copyTo(FileWrapper target, UserContext context) { ensureUnmodified(); NetworkAccess network = context.network; SafeRandom random = context.crypto.random; Hasher hasher = context.crypto.hasher; if (! target.isDirectory()) { return Futures.errored(new IllegalStateException("CopyTo target " + target + " must be a directory")); } return context.network.synchronizer.applyComplexUpdate(target.owner(), target.signingPair(), (base, committer) -> { return target.hasChildWithName(base.get(target.writer()).props, getFileProperties().name, network).thenCompose(childExists -> { if (childExists) { CompletableFuture<Snapshot> error = new CompletableFuture<>(); error.completeExceptionally(new IllegalStateException("CopyTo target " + target + " already has child with name " + getFileProperties().name)); return error; } if (isDirectory()) { byte[] newMapKey = random.randomBytes(32); SymmetricKey newBaseKey = SymmetricKey.random(); SymmetricKey newWriterBaseKey = SymmetricKey.random(); WritableAbsoluteCapability newCap = new WritableAbsoluteCapability(target.owner(), target.writer(), newMapKey, newBaseKey, newWriterBaseKey); SymmetricKey newParentParentKey = target.getParentKey(); return pointer.fileAccess.copyTo(base, committer, pointer.capability, newBaseKey, target.writableFilePointer(), target.entryWriter, newParentParentKey, newMapKey, network, random, hasher) .thenCompose(updatedBase -> { return target.addLinkTo(updatedBase, committer, getName(), newCap, network, random, hasher); }); } else { return base.withWriter(owner(), writer(), network).thenCompose(snapshot -> getInputStream(snapshot.get(writer()).props, network, random, x -> {}) .thenCompose(stream -> target.uploadFileSection(snapshot, committer, getName(), stream, false, 0, getSize(), Optional.empty(), false, network, random, hasher, x -> {}, target.generateChildLocations(props.getNumberOfChunks(), random)))); } }); }).thenApply(newAccess -> true); }