LocalFsClient implements FsClient, EventloopService, EventloopJmxBeanEx { @Override public Promise<Void> move(@NotNull String name, @NotNull String target, long targetRevision, long tombstoneRevision) { checkArgument(defaultRevision == null || targetRevision == defaultRevision, "unsupported revision"); checkArgument(defaultRevision == null || tombstoneRevision == defaultRevision, "unsupported revision"); return Promise.ofBlockingCallable(executor, () -> { if (defaultRevision == null) { doCopy(name, target, targetRevision); doDelete(name, tombstoneRevision); return (Void) null; } if (tombstoneRevision != defaultRevision) { throw UNSUPPORTED_REVISION; } Path path = resolve(name); Path targetPath = resolve(target); if (Files.isDirectory(path) || Files.isDirectory(targetPath)) { throw MOVING_DIRS; } if (path.equals(targetPath)) { return null; } if (Files.isRegularFile(targetPath)) { throw FILE_EXISTS; } if (Files.isRegularFile(path)) { Files.createDirectories(targetPath.getParent()); Files.move(path, targetPath, ATOMIC_MOVE); } else { Files.deleteIfExists(targetPath); } return null; }) .whenComplete(toLogger(logger, TRACE, "move", name, target, this)) .whenComplete(singleMovePromise.recordStats()); } private  LocalFsClient(Eventloop eventloop, Path storage, Executor executor); static LocalFsClient create(Eventloop eventloop, Executor executor, Path storageDir); LocalFsClient withLazyOverrides(boolean lazyOverrides); LocalFsClient withDefaultRevision(long defaultRevision); LocalFsClient withRevisions(); LocalFsClient withRevisions(FileNamingScheme namingScheme, Duration tombstoneTtl); LocalFsClient withReaderBufferSize(MemSize size); @Override Promise<ChannelConsumer<ByteBuf>> upload(@NotNull String name, long offset, long revision); @Override Promise<ChannelSupplier<ByteBuf>> download(@NotNull String name, long offset, long length); @Override Promise<List<FileMetadata>> listEntities(@NotNull String glob); @Override Promise<List<FileMetadata>> list(@NotNull String glob); @Override Promise<Void> move(@NotNull String name, @NotNull String target, long targetRevision, long tombstoneRevision); @Override Promise<Void> moveDir(@NotNull String name, @NotNull String target, long targetRevision, long removeRevision); @Override Promise<Void> copy(@NotNull String name, @NotNull String target, long targetRevision); @Override Promise<Void> delete(@NotNull String name, long revision); @Override Promise<Void> ping(); @Override Promise<FileMetadata> getMetadata(@NotNull String name); @Override FsClient subfolder(@NotNull String folder); @NotNull @Override Eventloop getEventloop(); @NotNull @Override Promise<Void> start(); @NotNull @Override Promise<Void> stop(); Promise<Void> cleanup(); Promise<Void> remove(String name); @Override String toString(); @JmxAttribute PromiseStats getWriteBeginPromise(); @JmxAttribute PromiseStats getWriteFinishPromise(); @JmxAttribute PromiseStats getReadBeginPromise(); @JmxAttribute PromiseStats getReadFinishPromise(); @JmxAttribute PromiseStats getListPromise(); @JmxAttribute PromiseStats getMovePromise(); @JmxAttribute PromiseStats getSingleMovePromise(); @JmxAttribute PromiseStats getCopyPromise(); @JmxAttribute PromiseStats getSingleCopyPromise(); @JmxAttribute PromiseStats getDeletePromise(); @JmxAttribute PromiseStats getSingleDeletePromise(); static final FileNamingScheme REVISION_NAMING_SCHEME; static final Duration DEFAULT_TOMBSTONE_TTL; static final char FILE_SEPARATOR_CHAR; static final String FILE_SEPARATOR; }
@Test public void testMove() throws IOException { byte[] expected = Files.readAllBytes(storagePath.resolve("1/a.txt")); await(client.move("1/a.txt", "3/new_folder/z.txt")); assertArrayEquals(expected, Files.readAllBytes(storagePath.resolve("3/new_folder/z.txt"))); assertFalse(Files.exists(storagePath.resolve("1/a.txt"))); }