comparison mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java @ 478:0a33f3dbd261 Faradi-7.1.x

Ensure temp dirs are deleted
author Dmitry Neverov <dmitry.neverov@jetbrains.com>
date Wed, 26 Sep 2012 14:58:55 +0400
parents 6b447cd40492
children 774229a5fcd2 a3dc94c399d4
comparison
equal deleted inserted replaced
476:aa19481a91c3 478:0a33f3dbd261
36 import java.io.File; 36 import java.io.File;
37 import java.io.FileFilter; 37 import java.io.FileFilter;
38 import java.io.FileInputStream; 38 import java.io.FileInputStream;
39 import java.io.IOException; 39 import java.io.IOException;
40 import java.util.*; 40 import java.util.*;
41
42 import static jetbrains.buildServer.buildTriggers.vcs.mercurial.HgFileUtil.deleteDir;
41 43
42 /** 44 /**
43 * Mercurial VCS plugin for TeamCity works as follows: 45 * Mercurial VCS plugin for TeamCity works as follows:
44 * <ul> 46 * <ul>
45 * <li>clones repository to internal storage 47 * <li>clones repository to internal storage
176 try { 178 try {
177 return FileUtil.loadFileBytes(file); 179 return FileUtil.loadFileBytes(file);
178 } catch (IOException e) { 180 } catch (IOException e) {
179 throw new VcsException("Failed to load content of file " + filePath + " at revision " + version, e); 181 throw new VcsException("Failed to load content of file " + filePath + " at revision " + version, e);
180 } finally { 182 } finally {
181 deleteTmpDir(parentDir); 183 deleteDir(parentDir, Loggers.VCS);
182 } 184 }
183 } 185 }
184 186
185 @NotNull 187 @NotNull
186 public String getName() { 188 public String getName() {
304 is.close(); 306 is.close();
305 } 307 }
306 } 308 }
307 } 309 }
308 } finally { 310 } finally {
309 deleteTmpDir(parentDir); 311 deleteDir(parentDir, Loggers.VCS);
310 }
311 }
312
313 private void deleteTmpDir(File parentDir) {
314 boolean dirDeleted = FileUtil.delete(parentDir);
315 if (!dirDeleted) {
316 Loggers.VCS.warn("Can not delete directory \"" + parentDir.getAbsolutePath() + "\"");
317 } 312 }
318 } 313 }
319 314
320 // builds patch by exporting files using specified version 315 // builds patch by exporting files using specified version
321 private void buildFullPatch(@NotNull final HgVcsRoot root, 316 private void buildFullPatch(@NotNull final HgVcsRoot root,
341 Loggers.VCS.debug("Repository '" + root.getRepository() + "' doesn't have submodules at revision " + toVer.getId() + ", use 'hg archive' to build clean patch"); 336 Loggers.VCS.debug("Repository '" + root.getRepository() + "' doesn't have submodules at revision " + toVer.getId() + ", use 'hg archive' to build clean patch");
342 repo.archive().revision(toVer).toDir(tempDir).call(); 337 repo.archive().revision(toVer).toDir(tempDir).call();
343 buildPatchFromDirectory(builder, tempDir, checkoutRules, myAcceptAllFilter); 338 buildPatchFromDirectory(builder, tempDir, checkoutRules, myAcceptAllFilter);
344 } 339 }
345 } finally { 340 } finally {
346 FileUtil.delete(tempDir); 341 deleteDir(tempDir, Loggers.VCS);
347 } 342 }
348 } 343 }
349 344
350 private void buildPatchFromDirectory(final PatchBuilder builder, final File repRoot, final CheckoutRules checkoutRules, @NotNull final FileFilter filter) throws IOException { 345 private void buildPatchFromDirectory(final PatchBuilder builder, final File repRoot, final CheckoutRules checkoutRules, @NotNull final FileFilter filter) throws IOException {
351 buildPatchFromDirectory(repRoot, builder, repRoot, checkoutRules, filter); 346 buildPatchFromDirectory(repRoot, builder, repRoot, checkoutRules, filter);
715 .call(); 710 .call();
716 711
717 repo.push().toRepository(hgRoot.getRepository()).call(); 712 repo.push().toRepository(hgRoot.getRepository()).call();
718 return fixedTagname; 713 return fixedTagname;
719 } finally { 714 } finally {
720 if (tmpDir != null) 715 deleteDir(tmpDir, Loggers.VCS);
721 FileUtil.delete(tmpDir);
722 } 716 }
723 } 717 }
724 718
725 private String fixTagName(final String label) { 719 private String fixTagName(final String label) {
726 // according to Mercurial documentation http://hgbook.red-bean.com/hgbookch8.html#x12-1570008 720 // according to Mercurial documentation http://hgbook.red-bean.com/hgbookch8.html#x12-1570008