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

Atomic copy2 #1038

Merged
merged 3 commits into from
Sep 14, 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
7 changes: 6 additions & 1 deletion library/copy
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import os
import shutil
import time

def main():

Expand Down Expand Up @@ -64,7 +65,11 @@ def main():
if backup:
if os.path.exists(dest):
backup_file = module.backup_local(dest)
shutil.copyfile(src, dest)
#TODO:pid + epoch should avoid most collisions, hostname/mac for those using nfs?
# might be an issue with exceeding path length
dest_tmp = "%s.%s.%s.tmp" % (dest,os.getpid(),time.time())
shutil.copyfile(src, dest_tmp)
shutil.move(dest_tmp, dest)
except shutil.Error:
module.fail_json(msg="failed to copy: %s and %s are the same" % (src, dest))
except IOError:
Expand Down