Commit 49d50e52 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

QA: Add function create temporary backup file


Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent dfc8ad25
......@@ -150,6 +150,7 @@ def UploadFile(node, src):
Caller needs to remove the returned file on the node when it's not needed
anymore.
"""
# Make sure nobody else has access to it while preserving local permissions
mode = os.stat(src).st_mode & 0700
......@@ -171,6 +172,22 @@ def UploadFile(node, src):
f.close()
def BackupFile(node, path):
"""Creates a backup of a file on the node and returns the filename.
Caller needs to remove the returned file on the node when it's not needed
anymore.
"""
cmd = ("tmp=$(tempfile --prefix .gnt --directory=$(dirname %s)) && "
"[[ -f \"$tmp\" ]] && "
"cp %s $tmp && "
"echo $tmp") % (utils.ShellQuote(path), utils.ShellQuote(path))
# Return temporary filename
return GetCommandOutput(node, cmd).strip()
def _ResolveName(cmd, key):
"""Helper function.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment