perf record: Rename perf.data to perf.data.old if --force/-f is used
authorArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 14 Dec 2009 22:09:30 +0000 (20:09 -0200)
committerIngo Molnar <mingo@elte.hu>
Tue, 15 Dec 2009 07:50:29 +0000 (08:50 +0100)
Suggested-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260828571-3613-2-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
tools/perf/builtin-record.c

index a66a58d..66979a5 100644 (file)
@@ -421,10 +421,19 @@ static int __cmd_record(int argc, const char **argv)
        signal(SIGINT, sig_handler);
 
        if (!stat(output_name, &st) && st.st_size) {
-               if (!force && !append_file) {
-                       fprintf(stderr, "Error, output file %s exists, use -A to append or -f to overwrite.\n",
-                                       output_name);
-                       exit(-1);
+               if (!force) {
+                       if (!append_file) {
+                               pr_err("Error, output file %s exists, use -A "
+                                      "to append or -f to overwrite.\n",
+                                      output_name);
+                               exit(-1);
+                       }
+               } else {
+                       char oldname[PATH_MAX];
+                       snprintf(oldname, sizeof(oldname), "%s.old",
+                                output_name);
+                       unlink(oldname);
+                       rename(output_name, oldname);
                }
        } else {
                append_file = 0;