Skip to content

Commit 33ff547

Browse files
committed
Merge pull request #12 from ansoni/feature/cleanupZipArchive
Feature/cleanup zip archive
2 parents d2a1f2d + a48258a commit 33ff547

File tree

1 file changed

+31
-26
lines changed

1 file changed

+31
-26
lines changed

src/main/java/com/amazonaws/codedeploy/AWSCodeDeployPublisher.java

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -244,42 +244,47 @@ private void verifyCodeDeployApplication(AWSClients aws) throws IllegalArgumentE
244244
}
245245

246246
private RevisionLocation zipAndUpload(AWSClients aws, String projectName, FilePath workspace) throws IOException, InterruptedException {
247-
247+
248248
File zipFile = File.createTempFile(projectName + "-", ".zip");
249-
this.logger.println("Zipping workspace into " + zipFile.getAbsolutePath());
249+
String key;
250+
251+
try {
250252

251-
workspace.zip(
252-
new FileOutputStream(zipFile),
253-
new DirScanner.Glob(this.includes, this.excludes)
254-
);
253+
this.logger.println("Zipping workspace into " + zipFile.getAbsolutePath());
254+
workspace.zip(
255+
new FileOutputStream(zipFile),
256+
new DirScanner.Glob(this.includes, this.excludes)
257+
);
255258

256-
String key;
257-
if (this.s3prefix.isEmpty()) {
258-
key = zipFile.getName();
259-
} else {
260-
key = this.s3prefix;
261-
if (this.s3prefix.endsWith("/")) {
262-
key += zipFile.getName();
259+
if (this.s3prefix.isEmpty()) {
260+
key = zipFile.getName();
263261
} else {
264-
key += "/" + zipFile.getName();
262+
key = this.s3prefix;
263+
if (this.s3prefix.endsWith("/")) {
264+
key += zipFile.getName();
265+
} else {
266+
key += "/" + zipFile.getName();
267+
}
265268
}
266-
}
267269

268-
logger.println("Uploading zip to s3://" + this.s3bucket + "/" + key);
269-
PutObjectResult s3result = aws.s3.putObject(this.s3bucket, key, zipFile);
270+
logger.println("Uploading zip to s3://" + this.s3bucket + "/" + key);
271+
PutObjectResult s3result = aws.s3.putObject(this.s3bucket, key, zipFile);
270272

271273

272-
S3Location s3Location = new S3Location();
273-
s3Location.setBucket(this.s3bucket);
274-
s3Location.setKey(key);
275-
s3Location.setBundleType(BundleType.Zip);
276-
s3Location.setETag(s3result.getETag());
274+
S3Location s3Location = new S3Location();
275+
s3Location.setBucket(this.s3bucket);
276+
s3Location.setKey(key);
277+
s3Location.setBundleType(BundleType.Zip);
278+
s3Location.setETag(s3result.getETag());
277279

278-
RevisionLocation revisionLocation = new RevisionLocation();
279-
revisionLocation.setRevisionType(RevisionLocationType.S3);
280-
revisionLocation.setS3Location(s3Location);
280+
RevisionLocation revisionLocation = new RevisionLocation();
281+
revisionLocation.setRevisionType(RevisionLocationType.S3);
282+
revisionLocation.setS3Location(s3Location);
281283

282-
return revisionLocation;
284+
return revisionLocation;
285+
} finally {
286+
zipFile.delete();
287+
}
283288
}
284289

285290
private void registerRevision(AWSClients aws, RevisionLocation revisionLocation) {

0 commit comments

Comments
 (0)