From 49d50e52d4f39421d1eb5014889ac28c454f63f8 Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Mon, 10 May 2010 17:21:59 +0200 Subject: [PATCH] QA: Add function create temporary backup file Signed-off-by: Michael Hanselmann <hansmi@google.com> Reviewed-by: Iustin Pop <iustin@google.com> --- qa/qa_utils.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/qa/qa_utils.py b/qa/qa_utils.py index a4af63075..5a2c4e7d6 100644 --- a/qa/qa_utils.py +++ b/qa/qa_utils.py @@ -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. -- GitLab