diff options
author | Harald Musum <musum@oath.com> | 2018-05-22 09:06:41 +0200 |
---|---|---|
committer | Harald Musum <musum@oath.com> | 2018-05-22 09:06:41 +0200 |
commit | 1486c90bd20d4f2d7ac7d59a89551efdbca6b43b (patch) | |
tree | 4255e0374326e237d997f13ad0df7ca3619f463e | |
parent | da543305317e887582315c1e4f25b080edcca430 (diff) |
Delete temp dir when exception happens
-rw-r--r-- | configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java b/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java index 28718ee7154..bf4cdce1348 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java @@ -154,7 +154,8 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye public PrepareResult deploy(CompressedApplicationInputStream in, PrepareParams prepareParams, boolean ignoreLockFailure, boolean ignoreSessionStaleFailure, Instant now) { File tempDir = Files.createTempDir(); - return deploy(decompressApplication(in, tempDir), prepareParams, ignoreLockFailure, ignoreSessionStaleFailure, now); + File applicationPackage = decompressApplication(in, tempDir); + return deploy(applicationPackage, prepareParams, ignoreLockFailure, ignoreSessionStaleFailure, now); } public PrepareResult deploy(File applicationPackage, PrepareParams prepareParams) { @@ -163,10 +164,8 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye public PrepareResult deploy(File applicationPackage, PrepareParams prepareParams, boolean ignoreLockFailure, boolean ignoreSessionStaleFailure, Instant now) { - File tempDir = Files.createTempDir(); ApplicationId applicationId = prepareParams.getApplicationId(); long sessionId = createSession(applicationId, prepareParams.getTimeoutBudget(), applicationPackage); - cleanupApplicationDirectory(tempDir, logger); Tenant tenant = tenantRepository.getTenant(applicationId.tenant()); return prepareAndActivate(tenant, sessionId, prepareParams, ignoreLockFailure, ignoreSessionStaleFailure, now); } @@ -352,9 +351,7 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye public long createSession(ApplicationId applicationId, TimeoutBudget timeoutBudget, InputStream in, String contentType) { File tempDir = Files.createTempDir(); - long sessionId = createSession(applicationId, timeoutBudget, decompressApplication(in, contentType, tempDir)); - cleanupApplicationDirectory(tempDir, logger); - return sessionId; + return createSession(applicationId, timeoutBudget, decompressApplication(in, contentType, tempDir)); } public long createSession(ApplicationId applicationId, TimeoutBudget timeoutBudget, File applicationDirectory) { @@ -450,6 +447,7 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye CompressedApplicationInputStream.createFromCompressedStream(in, contentType)) { return decompressApplication(application, tempDir); } catch (IOException e) { + cleanupTempDirectory(tempDir, logger); throw new IllegalArgumentException("Unable to decompress data in body", e); } } @@ -458,6 +456,7 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye try { return in.decompress(tempDir); } catch (IOException e) { + cleanupTempDirectory(tempDir, logger); throw new IllegalArgumentException("Unable to decompress stream", e); } } @@ -467,7 +466,7 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye return applicationRepo.listApplications(); } - private static void cleanupApplicationDirectory(File tempDir, DeployLogger logger) { + private static void cleanupTempDirectory(File tempDir, DeployLogger logger) { logger.log(LogLevel.DEBUG, "Deleting tmp dir '" + tempDir + "'"); if (!IOUtils.recursiveDeleteDir(tempDir)) { logger.log(LogLevel.WARNING, "Not able to delete tmp dir '" + tempDir + "'"); |