diff options
author | Masami Hiramatsu <mhiramat@kernel.org> | 2016-06-08 05:29:11 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-06-14 08:29:54 -0400 |
commit | 2a1ef032cfccd8c92f32b86615a0b0151a7cd86f (patch) | |
tree | 16028ea560619381c524f0d6e29d80b53d5b4fc9 /tools/perf/util/util.c | |
parent | 826424cc919529d6d234af12c6ba975b63528a74 (diff) |
perf tools: Fix rm_rf() to handle non-regular files correctly
Fix rm_rf() to handle non-regular files correctly. This fix includes two
changes;
- Fix to use lstat(3) instead of stat(3) since if the target
file is a symbolic link, rm_rf() should unlink the symbolic
link itself, not the file which pointed by the symlink.
- Fix to unlink non-regular files (except for directory),
including symlink.
Even though the first one fixes to stat symlink itself, without second
fix, it still failed because the symlink is not a regular file.
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Ananth N Mavinakayanahalli <ananth@linux.vnet.ibm.com>
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: Hemant Kumar <hemant@linux.vnet.ibm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20160608092911.3116.90929.stgit@devbox
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/util.c')
-rw-r--r-- | tools/perf/util/util.c | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index 23504ad5d6dd..e08b9a092a23 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c | |||
@@ -97,20 +97,17 @@ int rm_rf(char *path) | |||
97 | scnprintf(namebuf, sizeof(namebuf), "%s/%s", | 97 | scnprintf(namebuf, sizeof(namebuf), "%s/%s", |
98 | path, d->d_name); | 98 | path, d->d_name); |
99 | 99 | ||
100 | ret = stat(namebuf, &statbuf); | 100 | /* We have to check symbolic link itself */ |
101 | ret = lstat(namebuf, &statbuf); | ||
101 | if (ret < 0) { | 102 | if (ret < 0) { |
102 | pr_debug("stat failed: %s\n", namebuf); | 103 | pr_debug("stat failed: %s\n", namebuf); |
103 | break; | 104 | break; |
104 | } | 105 | } |
105 | 106 | ||
106 | if (S_ISREG(statbuf.st_mode)) | 107 | if (S_ISDIR(statbuf.st_mode)) |
107 | ret = unlink(namebuf); | ||
108 | else if (S_ISDIR(statbuf.st_mode)) | ||
109 | ret = rm_rf(namebuf); | 108 | ret = rm_rf(namebuf); |
110 | else { | 109 | else |
111 | pr_debug("unknown file: %s\n", namebuf); | 110 | ret = unlink(namebuf); |
112 | ret = -1; | ||
113 | } | ||
114 | } | 111 | } |
115 | closedir(dir); | 112 | closedir(dir); |
116 | 113 | ||