lkml.org 
[lkml]   [2019]   [Feb]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 01/14] perf tools: Make rm_rf to remove single file
Date
Let rm_rf remove file if it's provided by path.

Link: http://lkml.kernel.org/n/tip-whhp3ej5795l9dc86xfyyp74@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
tools/perf/util/util.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index 320b0fef249a..58b8d6a8bfbc 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -125,8 +125,14 @@ int rm_rf(const char *path)
char namebuf[PATH_MAX];

dir = opendir(path);
- if (dir == NULL)
- return 0;
+ if (dir == NULL) {
+ /*
+ * The path does not exist or is not directory,
+ * so there's no harm to try remove it. This way
+ * rm_rf will work over single file.
+ */
+ return unlink(path);
+ }

while ((d = readdir(dir)) != NULL && !ret) {
struct stat statbuf;
--
2.17.2
\
 
 \ /
  Last update: 2019-02-03 16:31    [W:0.177 / U:0.596 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site