perf record: Rename perf.data to perf.data.old if --force/-f is used
[deliverable/linux.git] / tools / perf / builtin-record.c
index a66a58d52818b971822f05b6db71493bf72f86a4..66979a5553b8897b3f454d420db27a2dfa114980 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;
This page took 0.024935 seconds and 5 git commands to generate.