Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

perf tools: Add depth checking to rm_rf

Adding depth argument to rm_rf (and renaming it to rm_rf_depth) to
specify the depth we will go searching for files to remove.

It will be used to specify single depth for perf.data directory removal
in following patch.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
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>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/20190224190656.30163-2-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
05a48659 2d4f2799

+12 -2
+12 -2
tools/perf/util/util.c
··· 117 117 return (stat(path, &st) && mkdir(path, mode)) ? -1 : 0; 118 118 } 119 119 120 - int rm_rf(const char *path) 120 + /* 121 + * The depth specify how deep the removal will go. 122 + * 0 - will remove only files under the 'path' directory 123 + * 1 .. x - will dive in x-level deep under the 'path' directory 124 + */ 125 + static int rm_rf_depth(const char *path, int depth) 121 126 { 122 127 DIR *dir; 123 128 int ret; ··· 160 155 } 161 156 162 157 if (S_ISDIR(statbuf.st_mode)) 163 - ret = rm_rf(namebuf); 158 + ret = depth ? rm_rf_depth(namebuf, depth - 1) : 0; 164 159 else 165 160 ret = unlink(namebuf); 166 161 } ··· 170 165 return ret; 171 166 172 167 return rmdir(path); 168 + } 169 + 170 + int rm_rf(const char *path) 171 + { 172 + return rm_rf_depth(path, INT_MAX); 173 173 } 174 174 175 175 /* A filter which removes dot files */