diff options
author | Harald Musum <musum@verizonmedia.com> | 2020-07-17 09:15:51 +0200 |
---|---|---|
committer | Harald Musum <musum@verizonmedia.com> | 2020-07-17 09:15:51 +0200 |
commit | 06228c4cc5907e097d399d0bf917f077802b5bb8 (patch) | |
tree | c9e226824e6d9076267b5f1c726456f103e56a5e /configserver/src/main | |
parent | bc2c2241cfb7980ec122050f693de68052ad8b2d (diff) |
Clean up temp dir in case of failures
Diffstat (limited to 'configserver/src/main')
-rw-r--r-- | configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java index 0f6ba37cf51..00e4005e771 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java @@ -571,11 +571,18 @@ public class SessionRepository { throw new IllegalArgumentException(sourceDir.getAbsolutePath() + " is not a directory"); // Copy app atomically: Copy to a temp dir and move to destination - java.nio.file.Path tempDestinationDir = Files.createTempDirectory(destinationDir.getParentFile().toPath(), "app-package"); - log.log(Level.FINE, "Copying dir " + sourceDir.getAbsolutePath() + " to " + tempDestinationDir.toFile().getAbsolutePath()); - IOUtils.copyDirectory(sourceDir, tempDestinationDir.toFile()); - log.log(Level.FINE, "Moving " + tempDestinationDir + " to " + destinationDir.getAbsolutePath()); - Files.move(tempDestinationDir, destinationDir.toPath(), StandardCopyOption.ATOMIC_MOVE); + java.nio.file.Path tempDestinationDir = null; + try { + tempDestinationDir = Files.createTempDirectory(destinationDir.getParentFile().toPath(), "app-package"); + log.log(Level.FINE, "Copying dir " + sourceDir.getAbsolutePath() + " to " + tempDestinationDir.toFile().getAbsolutePath()); + IOUtils.copyDirectory(sourceDir, tempDestinationDir.toFile()); + log.log(Level.FINE, "Moving " + tempDestinationDir + " to " + destinationDir.getAbsolutePath()); + Files.move(tempDestinationDir, destinationDir.toPath(), StandardCopyOption.ATOMIC_MOVE); + } finally { + // In case some of the operations above fail + if (tempDestinationDir != null) + IOUtils.recursiveDeleteDir(tempDestinationDir.toFile()); + } } /** |