switch to shutil.copy rather than os.system(cp)
This commit is contained in:
parent
25504e1ae3
commit
76cd590df4
1 changed files with 12 additions and 5 deletions
11
library/copy
11
library/copy
|
@ -21,6 +21,7 @@
|
|||
import sys
|
||||
import os
|
||||
import shlex
|
||||
import shutil
|
||||
import syslog
|
||||
|
||||
# ===========================================
|
||||
|
@ -85,10 +86,16 @@ if os.path.exists(dest):
|
|||
md5sum_dest = md5_sum(dest)
|
||||
else:
|
||||
if not os.access(os.path.dirname(dest), os.W_OK):
|
||||
exit_kv(rc=1, failed=1, msg="Destination %s not writable" % (dest))
|
||||
exit_kv(rc=1, failed=1, msg="Destination %s not writable" % (os.path.dirname(dest)))
|
||||
|
||||
if md5sum_src != md5sum_dest:
|
||||
os.system("cp %s %s" % (src, dest))
|
||||
# was os.system("cp %s %s" % (src, dest))
|
||||
try:
|
||||
shutil.copyfile(src, dest)
|
||||
except shutil.Error:
|
||||
exit_kv(rc=1, failed=1, msg="failed to copy: %s and %s are the same" % (src, dest))
|
||||
except IOError:
|
||||
exit_kv(rc=1, failed=1, msg="failed to copy: %s to %s" % (src, dest))
|
||||
changed = True
|
||||
else:
|
||||
changed = False
|
||||
|
|
Loading…
Reference in a new issue