Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

md5 allow copy if file is missing #532

Merged
merged 1 commit into from
Jul 3, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 15 additions & 18 deletions library/copy
Original file line number Diff line number Diff line change
Expand Up @@ -66,29 +66,26 @@ if src:
if dest:
dest = os.path.expanduser(dest)

md5sum_src = None
# raise an error if there is no src file
if not os.path.exists(src):
exit_kv(rc=1, failed=1, msg="Source %s failed to transfer" % (src))

# raise an error if there is no dest file
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
if not os.access(src, os.R_OK):
exit_kv(rc=1, failed=1, msg="Source %s not readable" % (src))
md5sum_src = md5_sum(src)

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)
except IndexError:
# File doesn't exist yet, so clear to continue
pass
else:
if not os.access(os.path.dirname(dest), os.W_OK):
exit_kv(rc=1, failed=1, msg="Destination %s not writable" % (dest))

if md5sum_src != md5sum_dest:
os.system("cp %s %s" % (src, dest))
Expand All @@ -97,6 +94,6 @@ else:
changed = False

# mission accomplished
#print "md5sum=%s changed=%s" % (md5sum_dest, changed)
exit_kv(dest=dest, src=src, changed="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_src, changed))