From e1338716532199b2b8b300f9b78b0cabbf284796 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 23 Feb 2020 18:00:39 -0800 Subject: Fix for globbing into subdirectories (e.g. `bbcmd glob:"* */*"`) --- bb.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'bb.c') diff --git a/bb.c b/bb.c index dc48729..1be0085 100644 --- a/bb.c +++ b/bb.c @@ -291,16 +291,8 @@ entry_t* load_entry(bb_t *bb, const char *path) struct stat linkedstat, filestat; if (!path || !path[0]) return NULL; if (lstat(path, &filestat) == -1) return NULL; - char pbuf[PATH_MAX] = {0}; - char *slash = strrchr(path, '/'); - if (slash) { - strncpy(pbuf, path, (size_t)(slash - path)); - normalize_path(bb->path, pbuf, pbuf); - strcat(pbuf, slash); - } else { - strcpy(pbuf, bb->path); - strcat(pbuf, path); - } + char pbuf[PATH_MAX]; + sprintf(pbuf, "%s%s", bb->path, path); if (pbuf[strlen(pbuf)-1] == '/' && pbuf[1]) pbuf[strlen(pbuf)-1] = '\0'; @@ -330,9 +322,7 @@ entry_t* load_entry(bb_t *bb, const char *path) if (strcmp(entry->fullname, "/") == 0) { entry->name = entry->fullname; } else { - entry->name = strrchr(entry->fullname, '/'); - if (!entry->name) err("No slash found in '%s' from '%s'", entry->fullname, path); - ++entry->name; + entry->name = &entry->fullname[strlen(bb->path)]; } if (S_ISLNK(filestat.st_mode)) entry->linkedmode = linkedstat.st_mode; @@ -1141,7 +1131,7 @@ void set_title(bb_t *bb) */ int try_free_entry(entry_t *e) { - if (IS_SELECTED(e) || IS_VIEWED(e)) return 0; + if (IS_SELECTED(e) || IS_VIEWED(e) || !IS_LOADED(e)) return 0; LL_REMOVE(e, hash); free(e); return 1; -- cgit v1.2.3