summaryrefslogtreecommitdiffstats
path: root/filedistribution
diff options
context:
space:
mode:
authorHarald Musum <musum@verizonmedia.com>2021-06-14 21:36:40 +0200
committerHarald Musum <musum@verizonmedia.com>2021-06-14 21:36:40 +0200
commitb1dd14ea957917cb0221edae84fb3963ca22c8c5 (patch)
tree84ed453ed83195e6174e9acf9139b0cd8a97717e /filedistribution
parent335c9cbe5ef2c593b201420583ca528df9dda77a (diff)
Remove unnecessary checks for directory, throw if more than 1 file found
Diffstat (limited to 'filedistribution')
-rw-r--r--filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileDownloader.java26
1 files changed, 13 insertions, 13 deletions
diff --git a/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileDownloader.java b/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileDownloader.java
index 1a964fa2d71..292674497ed 100644
--- a/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileDownloader.java
+++ b/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileDownloader.java
@@ -89,22 +89,22 @@ public class FileDownloader implements AutoCloseable {
return downloadDirectory;
}
- // Files are moved atomically, so if file reference exists and is accessible we can use it
private Optional<File> getFileFromFileSystem(FileReference fileReference) {
File[] files = new File(downloadDirectory, fileReference.value()).listFiles();
- if (downloadDirectory.exists() && downloadDirectory.isDirectory() && files != null && files.length > 0) {
- File file = files[0];
- if (!file.exists()) {
- throw new RuntimeException("File reference '" + fileReference.value() + "' does not exist");
- } else if (!file.canRead()) {
- throw new RuntimeException("File reference '" + fileReference.value() + "' exists, but unable to read it");
- } else {
- log.log(Level.FINE, () -> "File reference '" + fileReference.value() + "' found: " + file.getAbsolutePath());
- downloads.setDownloadStatus(fileReference, 1.0);
- return Optional.of(file);
- }
+ if (files == null) return Optional.empty();
+ if (files.length == 0) return Optional.empty();
+ if (files.length > 1) throw new RuntimeException("More than one file reference found for " + fileReference);
+
+ File file = files[0];
+ if (!file.exists()) {
+ throw new RuntimeException("File reference '" + fileReference.value() + "' does not exist");
+ } else if (!file.canRead()) {
+ throw new RuntimeException("File reference '" + fileReference.value() + "' exists, but unable to read it");
+ } else {
+ log.log(Level.FINE, () -> "File reference '" + fileReference.value() + "' found: " + file.getAbsolutePath());
+ downloads.setDownloadStatus(fileReference, 1.0);
+ return Optional.of(file);
}
- return Optional.empty();
}
boolean isDownloading(FileReference fileReference) {