Skip to content

Commit b5112a2

Browse files
rshkvsvc-changelog
andauthored
PathConvertingFileSystem converts FileStatus objects in-place (#638)
* PathConvertingFileSystem renames paths without creating new FileStatus objects * Add generated changelog entries * Reflect updated FileStatus conversion in test Co-authored-by: svc-changelog <[email protected]>
1 parent d0853ab commit b5112a2

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
type: improvement
2+
improvement:
3+
description: PathConvertingFileSystem renames paths without creating new FileStatus
4+
objects.
5+
links:
6+
- https://github.com/palantir/hadoop-crypto/pull/638

hadoop-crypto/src/main/java/com/palantir/crypto2/hadoop/PathConvertingFileSystem.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -154,19 +154,8 @@ private Path from(Path path) {
154154
return fromFunc.apply(path);
155155
}
156156

157-
private FileStatus toReturnFileStatus(FileStatus status) throws IOException {
158-
// same as FileStatus copy constructor
159-
return new FileStatus(
160-
status.getLen(),
161-
status.isDirectory(),
162-
status.getReplication(),
163-
status.getBlockSize(),
164-
status.getModificationTime(),
165-
status.getAccessTime(),
166-
status.getPermission(),
167-
status.getOwner(),
168-
status.getGroup(),
169-
status.isSymlink() ? status.getSymlink() : null, // getSymlink throws if file is not a symlink
170-
from(status.getPath()));
157+
private FileStatus toReturnFileStatus(FileStatus status) {
158+
status.setPath(from(status.getPath()));
159+
return status;
171160
}
172161
}

hadoop-crypto/src/test/java/com/palantir/crypto2/hadoop/PathConvertingFileSystemTest.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,24 @@ public void makeQualified() {
120120

121121
@Test
122122
public void listStatus() throws Exception {
123-
when(delegate.listStatus(DELEGATE_PATH)).thenReturn(new FileStatus[] {fileStatus(DELEGATE_PATH)});
123+
FileStatus delegateFileStatus = fileStatus(DELEGATE_PATH);
124+
when(delegate.listStatus(DELEGATE_PATH)).thenReturn(new FileStatus[] {delegateFileStatus});
124125
FileStatus[] fileStatuses = convertingFs.listStatus(PATH);
125126

126-
assertThat(fileStatuses).containsExactly(fileStatus(RETURN_PATH));
127+
assertThat(fileStatuses)
128+
.satisfiesExactly(status ->
129+
// The returned status is the same object returned by the delegate, the path converted in-place
130+
assertThat(status).isEqualTo(fileStatus(RETURN_PATH)).isSameAs(delegateFileStatus));
127131
}
128132

129133
@Test
130134
public void getFileStatus() throws Exception {
131-
when(delegate.getFileStatus(DELEGATE_PATH)).thenReturn(fileStatus(DELEGATE_PATH));
132-
FileStatus fileStatus = convertingFs.getFileStatus(PATH);
135+
FileStatus delegateFileStatus = fileStatus(DELEGATE_PATH);
136+
when(delegate.getFileStatus(DELEGATE_PATH)).thenReturn(delegateFileStatus);
137+
FileStatus convertedFileStatus = convertingFs.getFileStatus(PATH);
133138

134-
assertThat(fileStatus).isEqualTo(fileStatus(RETURN_PATH));
139+
// The returned status is the same object returned by the delegate, the path converted in-place
140+
assertThat(convertedFileStatus).isEqualTo(fileStatus(RETURN_PATH)).isSameAs(delegateFileStatus);
135141
}
136142

137143
@Test

0 commit comments

Comments
 (0)