diff options
-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) | |||
120 | int rm_rf(const char *path) | 120 | int rm_rf(const char *path) |
121 | { | 121 | { |
122 | DIR *dir; | 122 | DIR *dir; |
123 | int ret = 0; | 123 | int ret; |
124 | struct dirent *d; | 124 | struct dirent *d; |
125 | char namebuf[PATH_MAX]; | 125 | char namebuf[PATH_MAX]; |
126 | struct stat statbuf; | ||
126 | 127 | ||
128 | /* Do not fail if there's no file. */ | ||
129 | ret = lstat(path, &statbuf); | ||
130 | if (ret) | ||
131 | return 0; | ||
132 | |||
133 | /* Try to remove any file we get. */ | ||
134 | if (!(statbuf.st_mode & S_IFDIR)) | ||
135 | return unlink(path); | ||
136 | |||
137 | /* We have directory in path. */ | ||
127 | dir = opendir(path); | 138 | dir = opendir(path); |
128 | if (dir == NULL) | 139 | if (dir == NULL) |
129 | return 0; | 140 | return -1; |
130 | 141 | ||
131 | while ((d = readdir(dir)) != NULL && !ret) { | 142 | while ((d = readdir(dir)) != NULL && !ret) { |
132 | struct stat statbuf; | ||
133 | 143 | ||
134 | if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, "..")) | 144 | if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, "..")) |
135 | continue; | 145 | continue; |