diff options
| author | Jiri Olsa <[email protected]> | 2019-02-20 12:28:00 +0000 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <[email protected]> | 2019-02-20 20:09:28 +0000 |
| commit | b4409ae112caa6315f6ee678e953b9fc93e6919c (patch) | |
| tree | 02414271cef0931689a94445bc151049217c2e77 | |
| parent | perf cpumap: Increase debug level for cpu_map__snprint verbose output (diff) | |
| download | kernel-b4409ae112caa6315f6ee678e953b9fc93e6919c.tar.gz kernel-b4409ae112caa6315f6ee678e953b9fc93e6919c.zip | |
perf tools: Make rm_rf() remove single file
Let rm_rf() remove a file if it's provided by path, not just
directories.
Signed-off-by: Jiri Olsa <[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]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
| -rw-r--r-- | tools/perf/util/util.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index 320b0fef249a..3ee410fc047a 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c @@ -120,16 +120,26 @@ int mkdir_p(char *path, mode_t mode) int rm_rf(const char *path) { DIR *dir; - int ret = 0; + int ret; struct dirent *d; char namebuf[PATH_MAX]; + struct stat statbuf; + /* Do not fail if there's no file. */ + ret = lstat(path, &statbuf); + if (ret) + return 0; + + /* Try to remove any file we get. */ + if (!(statbuf.st_mode & S_IFDIR)) + return unlink(path); + + /* We have directory in path. */ dir = opendir(path); if (dir == NULL) - return 0; + return -1; while ((d = readdir(dir)) != NULL && !ret) { - struct stat statbuf; if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, "..")) continue; |
