From: Jiri Olsa <[email protected]>

Change check_backup() to call rm_rf_perf_data() instead of unlink() to
work over directory paths.

Also move the call earlier in the code, before we fork for file/dir, so
it can backup also directory data.

Signed-off-by: Jiri Olsa <[email protected]>
Cc: Adrian Hunter <[email protected]>
Cc: Alexander Shishkin <[email protected]>
Cc: Alexey Budankov <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
 tools/perf/util/data.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c
index e16d06ed1100..bbf9a299615e 100644
--- a/tools/perf/util/data.c
+++ b/tools/perf/util/data.c
@@ -37,12 +37,15 @@ static int check_backup(struct perf_data *data)
 {
        struct stat st;
 
+       if (perf_data__is_read(data))
+               return 0;
+
        if (!stat(data->path, &st) && st.st_size) {
                /* TODO check errors properly */
                char oldname[PATH_MAX];
                snprintf(oldname, sizeof(oldname), "%s.old",
                         data->path);
-               unlink(oldname);
+               rm_rf_perf_data(oldname);
                rename(data->path, oldname);
        }
 
@@ -95,9 +98,6 @@ static int open_file_write(struct perf_data *data)
        int fd;
        char sbuf[STRERR_BUFSIZE];
 
-       if (check_backup(data))
-               return -1;
-
        fd = open(data->file.path, O_CREAT|O_RDWR|O_TRUNC|O_CLOEXEC,
                  S_IRUSR|S_IWUSR);
 
@@ -141,6 +141,9 @@ int perf_data__open(struct perf_data *data)
        if (!data->path)
                data->path = "perf.data";
 
+       if (check_backup(data))
+               return -1;
+
        return open_file_dup(data);
 }
 
-- 
2.20.1

Reply via email to