diff options
author | Harald Musum <musum@oath.com> | 2018-05-24 11:32:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-24 11:32:30 +0200 |
commit | 41a901adfb7eacf9dc476f3d23dd711b739b4815 (patch) | |
tree | bda7eee3fd9647c649442bdd88ca451b6e6eca44 /configserver | |
parent | 02a4167c6faec51d72ca02d78c2ff6807ac58912 (diff) | |
parent | 51b215102eedcf41e36efaaf8e3de44fd5cbd0d6 (diff) |
Merge pull request #5925 from vespa-engine/hmusum/cleanup-temp-dir-2
Cleanup properly
Diffstat (limited to 'configserver')
-rw-r--r-- | configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java | 28 |
1 files changed, 20 insertions, 8 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 549af4d1f64..cef59809248 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 @@ -153,7 +153,14 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye public PrepareResult deploy(CompressedApplicationInputStream in, PrepareParams prepareParams, boolean ignoreLockFailure, boolean ignoreSessionStaleFailure, Instant now) { - return deploy(decompressApplication(in), prepareParams, ignoreLockFailure, ignoreSessionStaleFailure, now); + File tempDir = Files.createTempDir(); + PrepareResult prepareResult; + try { + prepareResult = deploy(decompressApplication(in, tempDir), prepareParams, ignoreLockFailure, ignoreSessionStaleFailure, now); + } finally { + cleanupTempDirectory(tempDir); + } + return prepareResult; } public PrepareResult deploy(File applicationPackage, PrepareParams prepareParams) { @@ -349,7 +356,14 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye } public long createSession(ApplicationId applicationId, TimeoutBudget timeoutBudget, InputStream in, String contentType) { - return createSession(applicationId, timeoutBudget, decompressApplication(in, contentType)); + File tempDir = Files.createTempDir(); + long sessionId; + try { + sessionId = createSession(applicationId, timeoutBudget, decompressApplication(in, contentType, tempDir)); + } finally { + cleanupTempDirectory(tempDir); + } + return sessionId; } public long createSession(ApplicationId applicationId, TimeoutBudget timeoutBudget, File applicationDirectory) { @@ -440,21 +454,19 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye return currentActiveApplicationSet; } - private File decompressApplication(InputStream in, String contentType) { + private File decompressApplication(InputStream in, String contentType, File tempDir) { try (CompressedApplicationInputStream application = CompressedApplicationInputStream.createFromCompressedStream(in, contentType)) { - return decompressApplication(application); + return decompressApplication(application, tempDir); } catch (IOException e) { throw new IllegalArgumentException("Unable to decompress data in body", e); } } - private File decompressApplication(CompressedApplicationInputStream in) { - File tempDir = Files.createTempDir(); + private File decompressApplication(CompressedApplicationInputStream in, File tempDir) { try { return in.decompress(tempDir); } catch (IOException e) { - cleanupTempDirectory(tempDir, logger); throw new IllegalArgumentException("Unable to decompress stream", e); } } @@ -464,7 +476,7 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye return applicationRepo.listApplications(); } - private static void cleanupTempDirectory(File tempDir, DeployLogger logger) { + private void cleanupTempDirectory(File tempDir) { logger.log(LogLevel.DEBUG, "Deleting tmp dir '" + tempDir + "'"); if (!IOUtils.recursiveDeleteDir(tempDir)) { logger.log(LogLevel.WARNING, "Not able to delete tmp dir '" + tempDir + "'"); |