mirror of
https://github.com/radareorg/radare2.git
synced 2025-01-25 23:34:57 +00:00
Fix #2116
This commit is contained in:
parent
ec1ba93468
commit
775a780b43
@ -85,11 +85,14 @@ static void showfile(const int nth, const char *fpath, const char *name, int pri
|
||||
// TODO: Move into r_util .. r_print maybe? r_cons dep is anoying
|
||||
R_API void r_core_syscmd_ls(const char *input) {
|
||||
const char *path = ".";
|
||||
char *p, *d = NULL;
|
||||
char *pattern = NULL;
|
||||
int printfmt = 0;
|
||||
RListIter *iter;
|
||||
RList *files;
|
||||
char *name;
|
||||
char *dir;
|
||||
int off;
|
||||
if (r_sandbox_enable (0)) {
|
||||
eprintf ("Sandbox forbids listing directories\n");
|
||||
return;
|
||||
@ -104,6 +107,20 @@ R_API void r_core_syscmd_ls(const char *input) {
|
||||
}
|
||||
} else path = input+2;
|
||||
}
|
||||
if (!r_file_is_directory (path)){
|
||||
p = strrchr(path, '/');
|
||||
if (p){
|
||||
off = p - path;
|
||||
d = (char *) calloc (1, off);
|
||||
if (!d) return;
|
||||
memcpy (d, path, off);
|
||||
path = (const char *)d;
|
||||
pattern = strdup (p+1);
|
||||
}else {
|
||||
pattern = strdup (path);
|
||||
path = ".";
|
||||
}
|
||||
} else pattern = strdup ("*");
|
||||
if (r_file_is_regular (path)) {
|
||||
showfile (0, path, path, printfmt);
|
||||
return;
|
||||
@ -119,12 +136,16 @@ R_API void r_core_syscmd_ls(const char *input) {
|
||||
r_list_foreach (files, iter, name) {
|
||||
char *n = r_str_concat (strdup (dir), name);
|
||||
if (!n) break;
|
||||
if (*n) showfile (nth, n, name, printfmt);
|
||||
if (r_str_glob(name, pattern)){
|
||||
if (*n) showfile (nth, n, name, printfmt);
|
||||
nth++;
|
||||
}
|
||||
free (n);
|
||||
nth++;
|
||||
}
|
||||
if (printfmt == FMT_JSON) r_cons_printf ("]");
|
||||
free (dir);
|
||||
if (d) free (d);
|
||||
free (pattern);
|
||||
r_list_free (files);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user