diff options
author | Jiri Olsa <jolsa@kernel.org> | 2019-02-24 14:06:42 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2019-02-25 08:35:19 -0500 |
commit | 5021fc4e8c7c3be6f8735eff76fb2520485fcec4 (patch) | |
tree | f32c501ac9f3605027e17c8fe1a64103ab66eae2 /tools/perf/util/data.c | |
parent | c69e4c37b37c816c7dbd307a6e7d2d2a5cfe8788 (diff) |
perf data: Make check_backup work over directories
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 <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexey Budankov <alexey.budankov@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/20190224190656.30163-7-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/data.c')
-rw-r--r-- | tools/perf/util/data.c | 11 |
1 files 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) | |||
37 | { | 37 | { |
38 | struct stat st; | 38 | struct stat st; |
39 | 39 | ||
40 | if (perf_data__is_read(data)) | ||
41 | return 0; | ||
42 | |||
40 | if (!stat(data->path, &st) && st.st_size) { | 43 | if (!stat(data->path, &st) && st.st_size) { |
41 | /* TODO check errors properly */ | 44 | /* TODO check errors properly */ |
42 | char oldname[PATH_MAX]; | 45 | char oldname[PATH_MAX]; |
43 | snprintf(oldname, sizeof(oldname), "%s.old", | 46 | snprintf(oldname, sizeof(oldname), "%s.old", |
44 | data->path); | 47 | data->path); |
45 | unlink(oldname); | 48 | rm_rf_perf_data(oldname); |
46 | rename(data->path, oldname); | 49 | rename(data->path, oldname); |
47 | } | 50 | } |
48 | 51 | ||
@@ -95,9 +98,6 @@ static int open_file_write(struct perf_data *data) | |||
95 | int fd; | 98 | int fd; |
96 | char sbuf[STRERR_BUFSIZE]; | 99 | char sbuf[STRERR_BUFSIZE]; |
97 | 100 | ||
98 | if (check_backup(data)) | ||
99 | return -1; | ||
100 | |||
101 | fd = open(data->file.path, O_CREAT|O_RDWR|O_TRUNC|O_CLOEXEC, | 101 | fd = open(data->file.path, O_CREAT|O_RDWR|O_TRUNC|O_CLOEXEC, |
102 | S_IRUSR|S_IWUSR); | 102 | S_IRUSR|S_IWUSR); |
103 | 103 | ||
@@ -141,6 +141,9 @@ int perf_data__open(struct perf_data *data) | |||
141 | if (!data->path) | 141 | if (!data->path) |
142 | data->path = "perf.data"; | 142 | data->path = "perf.data"; |
143 | 143 | ||
144 | if (check_backup(data)) | ||
145 | return -1; | ||
146 | |||
144 | return open_file_dup(data); | 147 | return open_file_dup(data); |
145 | } | 148 | } |
146 | 149 | ||