comparison svnwrap/svn_swig_wrapper.py @ 66:a31968146f3c

svnwrap: Fix leakage of temp dirs by using try/finally blocks.
author Augie Fackler <durin42@gmail.com>
date Sun, 09 Nov 2008 17:08:09 -0600
parents 2e30b59a9c19
children 49b7cbe4c8e3
comparison
equal deleted inserted replaced
65:b33940d54fe2 66:a31968146f3c
360 if other_path is not None: 360 if other_path is not None:
361 url2 = self.svn_url + '/' + other_path 361 url2 = self.svn_url + '/' + other_path
362 if other_rev is None: 362 if other_rev is None:
363 other_rev = revision - 1 363 other_rev = revision - 1
364 tmpdir = tempfile.mkdtemp('svnwrap_temp') 364 tmpdir = tempfile.mkdtemp('svnwrap_temp')
365 # hot tip: the swig bridge doesn't like StringIO for these bad boys 365 try:
366 out_path = os.path.join(tmpdir, 'diffout') 366 # hot tip: the swig bridge doesn't like StringIO for these bad boys
367 error_path = os.path.join(tmpdir, 'differr') 367 out_path = os.path.join(tmpdir, 'diffout')
368 out = open(out_path, 'w') 368 error_path = os.path.join(tmpdir, 'differr')
369 err = open(error_path, 'w') 369 out = open(out_path, 'w')
370 rev_old = core.svn_opt_revision_t() 370 err = open(error_path, 'w')
371 rev_old.kind = core.svn_opt_revision_number 371 rev_old = core.svn_opt_revision_t()
372 rev_old.value.number = other_rev 372 rev_old.kind = core.svn_opt_revision_number
373 rev_new = core.svn_opt_revision_t() 373 rev_old.value.number = other_rev
374 rev_new.kind = core.svn_opt_revision_number 374 rev_new = core.svn_opt_revision_t()
375 rev_new.value.number = revision 375 rev_new.kind = core.svn_opt_revision_number
376 client.diff3([], url2, rev_old, url, rev_new, True, True, 376 rev_new.value.number = revision
377 deleted, ignore_type, 'UTF-8', out, err, 377 client.diff3([], url2, rev_old, url, rev_new, True, True,
378 self.client_context, self.pool) 378 deleted, ignore_type, 'UTF-8', out, err,
379 out.close() 379 self.client_context, self.pool)
380 err.close() 380 out.close()
381 assert len(open(error_path).read()) == 0 381 err.close()
382 diff = open(out_path).read() 382 assert len(open(error_path).read()) == 0
383 os.chdir(old_cwd) 383 diff = open(out_path).read()
384 shutil.rmtree(tmpdir) 384 os.chdir(old_cwd)
385 return diff 385 return diff
386 finally:
387 shutil.rmtree(tmpdir)
386 388
387 def get_file(self, path, revision): 389 def get_file(self, path, revision):
388 out = cStringIO.StringIO() 390 out = cStringIO.StringIO()
389 tmpdir = tempfile.mkdtemp('svnwrap_temp') 391 tmpdir = tempfile.mkdtemp('svnwrap_temp')
390 # hot tip: the swig bridge doesn't like StringIO for these bad boys 392 try:
391 out_path = os.path.join(tmpdir, 'diffout') 393 # hot tip: the swig bridge doesn't like StringIO for these bad boys
392 out = open(out_path, 'w') 394 out_path = os.path.join(tmpdir, 'diffout')
393 ra.get_file(self.ra, path,revision, out , None) 395 out = open(out_path, 'w')
394 out.close() 396 ra.get_file(self.ra, path,revision, out , None)
395 x = open(out_path).read() 397 out.close()
396 shutil.rmtree(tmpdir) 398 x = open(out_path).read()
397 return x 399 return x
400 finally:
401 shutil.rmtree(tmpdir)
398 402
399 def proplist(self, path, revision, recurse=False): 403 def proplist(self, path, revision, recurse=False):
400 rev = core.svn_opt_revision_t() 404 rev = core.svn_opt_revision_t()
401 rev.kind = core.svn_opt_revision_number 405 rev.kind = core.svn_opt_revision_number
402 rev.value.number = revision 406 rev.value.number = revision