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

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: default avatarJiri Olsa <jolsa@kernel.org>
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>
Link: http://lkml.kernel.org/r/20190220122800.864-7-jolsa@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent deb83da1
...@@ -120,16 +120,26 @@ int mkdir_p(char *path, mode_t mode) ...@@ -120,16 +120,26 @@ int mkdir_p(char *path, mode_t mode)
int rm_rf(const char *path) int rm_rf(const char *path)
{ {
DIR *dir; DIR *dir;
int ret = 0; int ret;
struct dirent *d; struct dirent *d;
char namebuf[PATH_MAX]; 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); dir = opendir(path);
if (dir == NULL) if (dir == NULL)
return 0; return -1;
while ((d = readdir(dir)) != NULL && !ret) { while ((d = readdir(dir)) != NULL && !ret) {
struct stat statbuf;
if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, "..")) if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
continue; continue;
......
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