diff options
author | Harald Musum <musum@yahooinc.com> | 2021-12-10 15:05:31 +0100 |
---|---|---|
committer | Harald Musum <musum@yahooinc.com> | 2021-12-10 15:05:31 +0100 |
commit | 1e961d3ed99b01cfa105e6cf2f1b925066fb5030 (patch) | |
tree | db7e56f303698d8372390146a2d3519a96c7235c /filedistribution | |
parent | c99b914f967b392cc72cba021f47fc18aea3f009 (diff) |
Make sure to always delete temp file/dir
Diffstat (limited to 'filedistribution')
-rw-r--r-- | filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileReceiver.java | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileReceiver.java b/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileReceiver.java index 89a77599909..a2c5fee1e51 100644 --- a/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileReceiver.java +++ b/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/FileReceiver.java @@ -131,9 +131,7 @@ public class FileReceiver { throw new RuntimeException("Failed writing file: ", e); } finally { try { - if (inprogressFile.exists()) { - Files.delete(inprogressFile.toPath()); - } + Files.deleteIfExists(inprogressFile.toPath()); } catch (IOException e) { log.log(Level.SEVERE, "Failed deleting " + inprogressFile.getAbsolutePath() + ": " + e.getMessage(), e); } @@ -191,13 +189,14 @@ public class FileReceiver { } catch (FileAlreadyExistsException e) { // Don't fail if it already exists (we might get the file from several config servers when retrying, servers are down etc. // so it might be written already). Delete temp file/dir in that case, to avoid filling the disk. - log.log(Level.FINE, () -> "Failed moving file '" + tempFile.getAbsolutePath() + "' to '" + destination.getAbsolutePath() + - "', '" + destination.getAbsolutePath() + "' already exists"); - deleteFileOrDirectory(tempFile); + log.log(Level.FINE, () -> "Failed moving file '" + tempFile.getAbsolutePath() + "' to '" + + destination.getAbsolutePath() + "', it already exists"); } catch (IOException e) { String message = "Failed moving file '" + tempFile.getAbsolutePath() + "' to '" + destination.getAbsolutePath() + "'"; log.log(Level.SEVERE, message, e); throw new RuntimeException(message, e); + } finally { + deleteFileOrDirectory(tempFile); } } |