Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PathConvertingFileSystem converts FileStatus objects in-place #638

Merged
merged 3 commits into from
Dec 4, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog/@unreleased/pr-638.v2.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Comment on lines +157 to 160
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a test case that covers the behavior we want here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, PathConvertingFileSystemTest covers the conversion here:

@Test
public void listStatus() throws Exception {
when(delegate.listStatus(DELEGATE_PATH)).thenReturn(new FileStatus[] {fileStatus(DELEGATE_PATH)});
FileStatus[] fileStatuses = convertingFs.listStatus(PATH);
assertThat(fileStatuses).containsExactly(fileStatus(RETURN_PATH));
}
@Test
public void getFileStatus() throws Exception {
when(delegate.getFileStatus(DELEGATE_PATH)).thenReturn(fileStatus(DELEGATE_PATH));
FileStatus fileStatus = convertingFs.getFileStatus(PATH);
assertThat(fileStatus).isEqualTo(fileStatus(RETURN_PATH));
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also testing e.g. the object reference felt too much like an implementation detail. But can add.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On further thought testing the new behavior makes sense: added in 410ff78.

}