From 98ad13b1224c22ff7ce5da4cc8ab8e6d461c2ff3 Mon Sep 17 00:00:00 2001 From: Willi Raschkowski Date: Sat, 3 Dec 2022 20:44:08 +0000 Subject: [PATCH 1/3] PathConvertingFileSystem renames paths without creating new FileStatus objects --- .../hadoop/PathConvertingFileSystem.java | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/hadoop-crypto/src/main/java/com/palantir/crypto2/hadoop/PathConvertingFileSystem.java b/hadoop-crypto/src/main/java/com/palantir/crypto2/hadoop/PathConvertingFileSystem.java index f79025c75..59c8cac3e 100644 --- a/hadoop-crypto/src/main/java/com/palantir/crypto2/hadoop/PathConvertingFileSystem.java +++ b/hadoop-crypto/src/main/java/com/palantir/crypto2/hadoop/PathConvertingFileSystem.java @@ -154,19 +154,8 @@ private Path from(Path path) { return fromFunc.apply(path); } - private FileStatus toReturnFileStatus(FileStatus status) throws IOException { - // same as FileStatus copy constructor - return new FileStatus( - status.getLen(), - status.isDirectory(), - status.getReplication(), - status.getBlockSize(), - status.getModificationTime(), - status.getAccessTime(), - status.getPermission(), - status.getOwner(), - status.getGroup(), - status.isSymlink() ? status.getSymlink() : null, // getSymlink throws if file is not a symlink - from(status.getPath())); + private FileStatus toReturnFileStatus(FileStatus status) { + status.setPath(from(status.getPath())); + return status; } } From 9e3b85da94b13f6ee6ea0e75f8245b11c3ad4e20 Mon Sep 17 00:00:00 2001 From: svc-changelog Date: Sat, 3 Dec 2022 20:46:56 +0000 Subject: [PATCH 2/3] Add generated changelog entries --- changelog/@unreleased/pr-638.v2.yml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 changelog/@unreleased/pr-638.v2.yml diff --git a/changelog/@unreleased/pr-638.v2.yml b/changelog/@unreleased/pr-638.v2.yml new file mode 100644 index 000000000..2dc21cd49 --- /dev/null +++ b/changelog/@unreleased/pr-638.v2.yml @@ -0,0 +1,6 @@ +type: improvement +improvement: + description: PathConvertingFileSystem renames paths without creating new FileStatus + objects. + links: + - https://github.com/palantir/hadoop-crypto/pull/638 From 410ff78fd541b1d7cd088d55aed9b84af7c9292f Mon Sep 17 00:00:00 2001 From: Willi Raschkowski Date: Sun, 4 Dec 2022 16:04:32 +0000 Subject: [PATCH 3/3] Reflect updated FileStatus conversion in test --- .../hadoop/PathConvertingFileSystemTest.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/hadoop-crypto/src/test/java/com/palantir/crypto2/hadoop/PathConvertingFileSystemTest.java b/hadoop-crypto/src/test/java/com/palantir/crypto2/hadoop/PathConvertingFileSystemTest.java index d7a4a8821..d57911cc9 100644 --- a/hadoop-crypto/src/test/java/com/palantir/crypto2/hadoop/PathConvertingFileSystemTest.java +++ b/hadoop-crypto/src/test/java/com/palantir/crypto2/hadoop/PathConvertingFileSystemTest.java @@ -120,18 +120,24 @@ public void makeQualified() { @Test public void listStatus() throws Exception { - when(delegate.listStatus(DELEGATE_PATH)).thenReturn(new FileStatus[] {fileStatus(DELEGATE_PATH)}); + FileStatus delegateFileStatus = fileStatus(DELEGATE_PATH); + when(delegate.listStatus(DELEGATE_PATH)).thenReturn(new FileStatus[] {delegateFileStatus}); FileStatus[] fileStatuses = convertingFs.listStatus(PATH); - assertThat(fileStatuses).containsExactly(fileStatus(RETURN_PATH)); + assertThat(fileStatuses) + .satisfiesExactly(status -> + // The returned status is the same object returned by the delegate, the path converted in-place + assertThat(status).isEqualTo(fileStatus(RETURN_PATH)).isSameAs(delegateFileStatus)); } @Test public void getFileStatus() throws Exception { - when(delegate.getFileStatus(DELEGATE_PATH)).thenReturn(fileStatus(DELEGATE_PATH)); - FileStatus fileStatus = convertingFs.getFileStatus(PATH); + FileStatus delegateFileStatus = fileStatus(DELEGATE_PATH); + when(delegate.getFileStatus(DELEGATE_PATH)).thenReturn(delegateFileStatus); + FileStatus convertedFileStatus = convertingFs.getFileStatus(PATH); - assertThat(fileStatus).isEqualTo(fileStatus(RETURN_PATH)); + // The returned status is the same object returned by the delegate, the path converted in-place + assertThat(convertedFileStatus).isEqualTo(fileStatus(RETURN_PATH)).isSameAs(delegateFileStatus); } @Test