misc: add flexibility and move_file
Add preserve_perms argument to move_file to make the preservation of
permissions optional. This makes move_file usable if the target
file does not yet exist.
@@ -550,13 +550,17 @@ def copy_file(from_remote, from_path, to_remote, to_path=None):
])
-def move_file(remote, from_path, to_path, sudo=False):
+def move_file(remote, from_path, to_path, sudo=False, preserve_perms=True):
"""
Move a file from one path to another on a remote site
- The file needs to be stat'ed first, to make sure we
- maintain the same permissions
+ If preserve_perms is true, the contents of the destination file (to_path,
+ which must already exist in this case) are replaced with the contents of the
+ source file (from_path) and the permissions of to_path are preserved. If
+ preserve_perms is false, to_path does not need to exist, and is simply
+ clobbered if it does.
"""
+ if preserve_perms:
args = []
if sudo:
args.append('sudo')
@@ -586,6 +590,7 @@ def move_file(remote, from_path, to_path, sudo=False):
stdout=StringIO(),
)
+ if preserve_perms:
# reset the file back to the original permissions
args = []
if sudo:
@@ -603,7 +608,8 @@ def move_file(remote, from_path, to_path, sudo=False):
def delete_file(remote, path, sudo=False, force=False):
"""
- rm a file on a remote site.
+ rm a file on a remote site. Use force=True if the call should succeed even
+ if the file is absent or rm path would otherwise fail.
"""
args = []
if sudo:
