Commit 5021fc4e authored by Jiri Olsa's avatar Jiri Olsa Committed by Arnaldo Carvalho de Melo

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: default avatarJiri 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.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent c69e4c37
...@@ -37,12 +37,15 @@ static int check_backup(struct perf_data *data) ...@@ -37,12 +37,15 @@ static int check_backup(struct perf_data *data)
{ {
struct stat st; struct stat st;
if (perf_data__is_read(data))
return 0;
if (!stat(data->path, &st) && st.st_size) { if (!stat(data->path, &st) && st.st_size) {
/* TODO check errors properly */ /* TODO check errors properly */
char oldname[PATH_MAX]; char oldname[PATH_MAX];
snprintf(oldname, sizeof(oldname), "%s.old", snprintf(oldname, sizeof(oldname), "%s.old",
data->path); data->path);
unlink(oldname); rm_rf_perf_data(oldname);
rename(data->path, oldname); rename(data->path, oldname);
} }
...@@ -95,9 +98,6 @@ static int open_file_write(struct perf_data *data) ...@@ -95,9 +98,6 @@ static int open_file_write(struct perf_data *data)
int fd; int fd;
char sbuf[STRERR_BUFSIZE]; char sbuf[STRERR_BUFSIZE];
if (check_backup(data))
return -1;
fd = open(data->file.path, O_CREAT|O_RDWR|O_TRUNC|O_CLOEXEC, fd = open(data->file.path, O_CREAT|O_RDWR|O_TRUNC|O_CLOEXEC,
S_IRUSR|S_IWUSR); S_IRUSR|S_IWUSR);
...@@ -141,6 +141,9 @@ int perf_data__open(struct perf_data *data) ...@@ -141,6 +141,9 @@ int perf_data__open(struct perf_data *data)
if (!data->path) if (!data->path)
data->path = "perf.data"; data->path = "perf.data";
if (check_backup(data))
return -1;
return open_file_dup(data); return open_file_dup(data);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment