md5 allow copy if file is missing
This commit is contained in:
parent
c5d10330f0
commit
3350868093
1 changed files with 15 additions and 18 deletions
33
library/copy
33
library/copy
|
@ -66,29 +66,26 @@ if src:
|
||||||
if dest:
|
if dest:
|
||||||
dest = os.path.expanduser(dest)
|
dest = os.path.expanduser(dest)
|
||||||
|
|
||||||
|
md5sum_src = None
|
||||||
# raise an error if there is no src file
|
# raise an error if there is no src file
|
||||||
if not os.path.exists(src):
|
if not os.path.exists(src):
|
||||||
exit_kv(rc=1, failed=1, msg="Source %s failed to transfer" % (src))
|
exit_kv(rc=1, failed=1, msg="Source %s failed to transfer" % (src))
|
||||||
|
if not os.access(src, os.R_OK):
|
||||||
# raise an error if there is no dest file
|
exit_kv(rc=1, failed=1, msg="Source %s not readable" % (src))
|
||||||
if not os.path.exists(dest):
|
|
||||||
exit_kv(rc=1, failed=1, msg="Destination %s does not exist" % (dest))
|
|
||||||
|
|
||||||
# raise an error if copy has no permission on dest
|
|
||||||
if not os.access(dest, os.W_OK):
|
|
||||||
exit_kv(rc=1, failed=1, msg="Destination %s not writable" % (dest))
|
|
||||||
elif not os.access(dest, os.R_OK):
|
|
||||||
exit_kv(rc=1, failed=1, msg="Destination %s not readable" % (dest))
|
|
||||||
|
|
||||||
md5sum_src = None
|
|
||||||
md5sum_src = md5_sum(src)
|
md5sum_src = md5_sum(src)
|
||||||
|
|
||||||
md5sum_dest = None
|
md5sum_dest = None
|
||||||
try:
|
# check if there is no dest file
|
||||||
|
if os.path.exists(dest):
|
||||||
|
# raise an error if copy has no permission on dest
|
||||||
|
if not os.access(dest, os.W_OK):
|
||||||
|
exit_kv(rc=1, failed=1, msg="Destination %s not writable" % (dest))
|
||||||
|
if not os.access(dest, os.R_OK):
|
||||||
|
exit_kv(rc=1, failed=1, msg="Destination %s not readable" % (dest))
|
||||||
md5sum_dest = md5_sum(dest)
|
md5sum_dest = md5_sum(dest)
|
||||||
except IndexError:
|
else:
|
||||||
# File doesn't exist yet, so clear to continue
|
if not os.access(os.path.dirname(dest), os.W_OK):
|
||||||
pass
|
exit_kv(rc=1, failed=1, msg="Destination %s not writable" % (dest))
|
||||||
|
|
||||||
if md5sum_src != md5sum_dest:
|
if md5sum_src != md5sum_dest:
|
||||||
os.system("cp %s %s" % (src, dest))
|
os.system("cp %s %s" % (src, dest))
|
||||||
|
@ -97,6 +94,6 @@ else:
|
||||||
changed = False
|
changed = False
|
||||||
|
|
||||||
# mission accomplished
|
# mission accomplished
|
||||||
#print "md5sum=%s changed=%s" % (md5sum_dest, changed)
|
#print "md5sum=%s changed=%s" % (md5sum_src, changed)
|
||||||
exit_kv(dest=dest, src=src, changed="md5sum=%s changed=%s" % (md5sum_dest, changed))
|
exit_kv(dest=dest, src=src, changed="md5sum=%s changed=%s" % (md5sum_src, changed))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue