NFSStorageProvider when list storage by path and path is file - just return it as result, previously empty response was returned
@@ -198,11 +198,19 @@ public class NFSStorageProvider implements StorageProvider<NFSDataStorage> {
@Override
public DataStorageListing getItems(final NFSDataStorage dataStorage, final String path,
final Boolean showVersion, final Integer pageSize, final String marker) {
- File dataStorageRoot = nfsStorageMounter.mount(dataStorage);
- File dir = path != null ? new File(dataStorageRoot, path) : dataStorageRoot;
+ final File dataStorageRoot = nfsStorageMounter.mount(dataStorage);
+ final File startingPath = path != null ? new File(dataStorageRoot, path) : dataStorageRoot;
+
+ // If we list file - just return it as result
+ if (startingPath.isFile()) {
+ return new DataStorageListing(
+ null,
+ Collections.singletonList(mapFileToDataStorageFile(dataStorageRoot, startingPath))
+ );
+ }
long offset = StringUtils.isNumeric(marker) ? Long.parseLong(marker) : 1;
- try (Stream<Path> dirStream = Files.walk(dir.toPath(), 1)) {
+ try (Stream<Path> dirStream = Files.walk(startingPath.toPath(), 1)) {
final int effectivePageSize = Optional.ofNullable(pageSize).orElse(Integer.MAX_VALUE);
List<AbstractDataStorageItem> dataStorageItems = dirStream
.sorted()
@@ -234,7 +242,7 @@ public class NFSStorageProvider implements StorageProvider<NFSDataStorage> {
listing.setResults(dataStorageItems);
Long nextOffset = offset + effectivePageSize;
- try (Stream<Path> nextStream = Files.walk(dir.toPath(), 1)) {
+ try (Stream<Path> nextStream = Files.walk(startingPath.toPath(), 1)) {
if (nextStream.skip(nextOffset).findFirst().isPresent()) {
listing.setNextPageMarker(nextOffset.toString());
}
@@ -253,14 +261,7 @@ public class NFSStorageProvider implements StorageProvider<NFSDataStorage> {
final File dataStorageRoot = nfsStorageMounter.mount(dataStorage);
return Optional.of(new File(dataStorageRoot, path))
.filter(File::exists)
- .map(file -> {
- final DataStorageFile item = new DataStorageFile();
- item.setSize(file.length());
- item.setChanged(S3Constants.getAwsDateFormat().format(new Date(file.lastModified())));
- item.setName(file.getName());
- item.setPath(dataStorageRoot.toURI().relativize(file.toURI()).getPath());
- return item;
- });
+ .map(file -> mapFileToDataStorageFile(dataStorageRoot, file));
}
@Override
@@ -551,4 +552,13 @@ public class NFSStorageProvider implements StorageProvider<NFSDataStorage> {
throw new IllegalArgumentException(e);
}
}
+
+ private static DataStorageFile mapFileToDataStorageFile(final File dataStorageRoot, final File file) {
+ final DataStorageFile dataStorageFile = new DataStorageFile();
+ dataStorageFile.setSize(file.length());
+ dataStorageFile.setChanged(S3Constants.getAwsDateFormat().format(new Date(file.lastModified())));
+ dataStorageFile.setName(file.getName());
+ dataStorageFile.setPath(dataStorageRoot.toURI().relativize(file.toURI()).getPath());
+ return dataStorageFile;
+ }
}
