mirror of
https://github.com/kestra-io/kestra.git
synced 2025-12-19 18:05:41 -05:00
fix(core): handle not found on Storage.size
This commit is contained in:
@@ -6,6 +6,7 @@ import org.apache.commons.lang3.tuple.Pair;
|
||||
import java.io.*;
|
||||
import java.net.URI;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.NoSuchFileException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Comparator;
|
||||
@@ -30,7 +31,6 @@ public class LocalStorage implements StorageInterface {
|
||||
return Paths.get(config.getBasePath().toAbsolutePath().toString(), uri.toString());
|
||||
}
|
||||
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
private void createDirectory(URI append) {
|
||||
File file;
|
||||
|
||||
@@ -57,22 +57,26 @@ public class LocalStorage implements StorageInterface {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long size(URI uri) throws IOException {
|
||||
return Files.size(getPath(URI.create(uri.getPath())));
|
||||
public Long size(URI uri) throws FileNotFoundException {
|
||||
try {
|
||||
return Files.size(getPath(URI.create(uri.getPath())));
|
||||
} catch (NoSuchFileException e) {
|
||||
throw new FileNotFoundException("Unable to find file at '" + uri + "'");
|
||||
} catch (IOException e) {
|
||||
throw new FileNotFoundException("Unable to find file at '" + uri + "' with message '" + e.getMessage() + "'");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI put(URI uri, InputStream data) throws IOException {
|
||||
this.createDirectory(uri);
|
||||
|
||||
try (OutputStream outStream = new FileOutputStream(getPath(uri).toFile())) {
|
||||
try (data; OutputStream outStream = new FileOutputStream(getPath(uri).toFile())) {
|
||||
byte[] buffer = new byte[8 * 1024];
|
||||
int bytesRead;
|
||||
while ((bytesRead = data.read(buffer)) != -1) {
|
||||
outStream.write(buffer, 0, bytesRead);
|
||||
}
|
||||
} finally {
|
||||
data.close();
|
||||
}
|
||||
|
||||
return URI.create("kestra://" + uri.getPath());
|
||||
|
||||
@@ -69,6 +69,10 @@ class LocalStorageTest {
|
||||
|
||||
assertThat(storageInterface.size(new URI("/file/storage/put.yml")), is(77L));
|
||||
|
||||
assertThrows(FileNotFoundException.class, () -> {
|
||||
assertThat(storageInterface.size(new URI("/file/storage/muissing.yml")), is(76L));
|
||||
});
|
||||
|
||||
boolean delete = storageInterface.delete(put);
|
||||
assertThat(delete, is(true));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user