Skip to content

Commit

Permalink
perf tools: Make rm_rf() remove single file
Browse files Browse the repository at this point in the history
Let rm_rf() remove a file if it's provided by path, not just
directories.

Signed-off-by: Jiri 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.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Jiri Olsa authored and Arnaldo Carvalho de Melo committed Feb 20, 2019
1 parent deb83da commit b4409ae
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions tools/perf/util/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit b4409ae

Please sign in to comment.