##// END OF EJS Templates
util: add copyfile function
Matt Mackall -
r3629:4cfb72bc default
parent child Browse files
Show More
@@ -8,7 +8,7 b''
8 8 from demandload import demandload
9 9 from node import *
10 10 from i18n import gettext as _
11 demandload(globals(), "os re sys signal shutil imp urllib pdb shlex")
11 demandload(globals(), "os re sys signal imp urllib pdb shlex")
12 12 demandload(globals(), "fancyopts ui hg util lock revlog templater bundlerepo")
13 13 demandload(globals(), "difflib patch tempfile time")
14 14 demandload(globals(), "traceback errno version atexit sets bz2")
@@ -1004,14 +1004,11 b' def docopy(ui, repo, pats, opts, wlock):'
1004 1004 repo.undelete([abstarget], wlock)
1005 1005 try:
1006 1006 if not opts.get('dry_run'):
1007 shutil.copyfile(relsrc, reltarget)
1008 shutil.copymode(relsrc, reltarget)
1007 util.copyfile(relsrc, reltarget)
1009 1008 restore = False
1010 1009 finally:
1011 1010 if restore:
1012 1011 repo.remove([abstarget], wlock)
1013 except shutil.Error, inst:
1014 raise util.Abort(str(inst))
1015 1012 except IOError, inst:
1016 1013 if inst.errno == errno.ENOENT:
1017 1014 ui.warn(_('%s: deleted in working copy\n') % relsrc)
@@ -2419,8 +2416,7 b' def revert(ui, repo, *pats, **opts):'
2419 2416 ui.note(_('saving current version of %s as %s\n') %
2420 2417 (rel, bakname))
2421 2418 if not opts.get('dry_run'):
2422 shutil.copyfile(rel, bakname)
2423 shutil.copymode(rel, bakname)
2419 util.copyfile(rel, bakname)
2424 2420 if ui.verbose or not exact:
2425 2421 ui.status(xlist[1] % rel)
2426 2422 for table, hitlist, misslist, backuphit, backupmiss in disptable:
@@ -26,11 +26,8 b' def copyfile(src, dst, basedir=None):'
26 26 targetdir = os.path.dirname(absdst)
27 27 if not os.path.isdir(targetdir):
28 28 os.makedirs(targetdir)
29 try:
30 shutil.copyfile(abssrc, absdst)
31 shutil.copymode(abssrc, absdst)
32 except shutil.Error, inst:
33 raise util.Abort(str(inst))
29
30 util.copyfile(abssrc, absdst)
34 31
35 32 # public functions
36 33
@@ -460,6 +460,14 b' def unlink(f):'
460 460 except OSError:
461 461 pass
462 462
463 def copyfile(src, dest):
464 "copy a file, preserving mode"
465 try:
466 shutil.copyfile(src, dest)
467 shutil.copymode(src, dest)
468 except shutil.Error, inst:
469 raise util.Abort(str(inst))
470
463 471 def copyfiles(src, dst, hardlink=None):
464 472 """Copy a directory tree using hardlinks if possible"""
465 473
General Comments 0
You need to be logged in to leave comments. Login now