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 <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>
This commit is contained in:
parent
deb83da16c
commit
b4409ae112
@ -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;
|
||||||
|
|
||||||
dir = opendir(path);
|
/* Do not fail if there's no file. */
|
||||||
if (dir == NULL)
|
ret = lstat(path, &statbuf);
|
||||||
|
if (ret)
|
||||||
return 0;
|
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 -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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user