aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2020-02-23 18:00:39 -0800
committerBruce Hill <bruce@bruce-hill.com>2020-02-23 18:00:39 -0800
commite1338716532199b2b8b300f9b78b0cabbf284796 (patch)
tree128c38e9fa799251005fddafa980c8a0bf938bc8
parent6006e21d9576266f7909df4bb3d9bb9d213f5424 (diff)
Fix for globbing into subdirectories (e.g. `bbcmd glob:"* */*"`)
-rw-r--r--bb.c18
-rw-r--r--bb.h6
2 files changed, 8 insertions, 16 deletions
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;
diff --git a/bb.h b/bb.h
index 80a1452..5a9a86b 100644
--- a/bb.h
+++ b/bb.h
@@ -26,7 +26,7 @@
#include "bterm.h"
// Macros:
-#define BB_VERSION "0.22.0"
+#define BB_VERSION "0.22.1"
#ifndef PATH_MAX
#define PATH_MAX 4096
@@ -41,6 +41,7 @@
#define MIN(a,b) ((a) > (b) ? (b) : (a))
#define IS_SELECTED(p) (((p)->selected.atme) != NULL)
#define IS_VIEWED(p) ((p)->index >= 0)
+#define IS_LOADED(p) ((p)->hash.atme != NULL)
#define LOWERCASE(c) ('A' <= (c) && (c) <= 'Z' ? ((c) + 'a' - 'A') : (c))
#define E_ISDIR(e) (S_ISDIR(S_ISLNK((e)->info.st_mode) ? (e)->linkedmode : (e)->info.st_mode))
#define ONSCREEN (winsize.ws_row - 3)
@@ -83,7 +84,8 @@
#define LL_REMOVE(node, name) do { \
if (((node)->name).next) \
((__typeof__(node))(node)->name.next)->name.atme = ((node)->name).atme; \
- *(((node)->name).atme) = ((node)->name).next; \
+ if (((node)->name).atme) \
+ *(((node)->name).atme) = ((node)->name).next; \
((node)->name).atme = NULL; \
((node)->name).next = NULL; \
} while (0)