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

3918: Added checking of attributes size for 0. Added unit test #4304

Merged
merged 1 commit into from
Jan 9, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,12 @@ public <A extends BasicFileAttributes> A readAttributes(
}
CloudStorageObjectAttributes ret;
ret = new CloudStorageObjectAttributes(blobInfo);
// if size is 0 it could be a folder
if (ret.size() == 0 && cloudPath.seemsLikeADirectoryAndUsePseudoDirectories(storage)) {
@SuppressWarnings("unchecked")
A result = (A) new CloudStoragePseudoDirectoryAttributes(cloudPath);
return result;
}
@SuppressWarnings("unchecked")
A result = (A) ret;
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
public class CloudStorageFileAttributesTest {

private static final byte[] HAPPY = "(✿◕ ‿◕ )ノ".getBytes(UTF_8);
private static final byte[] EMPTY = "".getBytes(UTF_8);

private Path path;
private Path dir;
Expand Down Expand Up @@ -104,6 +105,14 @@ public void testIsDirectory() throws IOException {
assertThat(Files.readAttributes(dir, CloudStorageFileAttributes.class).isDirectory()).isTrue();
}

@Test
public void testIsPseudoDirectory() throws IOException {
Files.write(path, EMPTY);
assertThat(Files.readAttributes(path, CloudStorageFileAttributes.class).isDirectory())
.isFalse();
assertThat(Files.readAttributes(dir, CloudStorageFileAttributes.class).isDirectory()).isTrue();
}

@Test
public void testIsRegularFile() throws IOException {
Files.write(path, HAPPY);
Expand Down