Skip to content

Commit

Permalink
ignore icon patterns for directories
Browse files Browse the repository at this point in the history
Otherwise a directory /path/tol/dir.jpg/ would have the icon for images
just because it ends in ".jpg" (which is a bad name for directories, in
any case).
  • Loading branch information
phillbush committed Apr 5, 2023
1 parent d373325 commit 2936002
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion defaults.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,5 @@ struct {
size_t ndeffileicons = NTYPES;

size_t defdirtype = dir;

size_t defupdirtype = up_dir;
size_t deffiletype = file;
12 changes: 8 additions & 4 deletions xfiles.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@ sizefmt(off_t size)
static int
isdir(char **entry)
{
size_t len;
char *s;

len = strlen(entry[ITEM_PATH]);
return len > 0 && entry[ITEM_PATH][len-1] == '/';
s = strrchr(entry[ITEM_PATH], '/');
return s != NULL && s[1] == '\0';
}

static int
Expand Down Expand Up @@ -283,6 +283,8 @@ checkicon(struct FM *fm, char **entry, char *patt)
if (patt[0] == '~' || strchr(patt, '/') != NULL) {
flags = FNM_CASEFOLD | FNM_PATHNAME | FNM_LEADING_DIR;
s = entry[ITEM_PATH];
} else if (isdir(entry)) {
return FALSE;
} else {
flags = FNM_CASEFOLD;
s = entry[ITEM_NAME];
Expand All @@ -303,12 +305,14 @@ checkicon(struct FM *fm, char **entry, char *patt)
static char *
geticon(struct FM *fm, char **entry)
{
extern size_t defdirtype;
extern size_t defdirtype, defupdirtype;
extern char *deffiletypes[];
extern struct { char *patt; int type; } deffilepatts[];
size_t i;
char *patt;

if (strcmp(entry[ITEM_NAME], "..") == 0)
return deffiletypes[defupdirtype];
for (i = 0; i < fm->nfiletypes; i++) {
patt = fm->filetypes[i].patt;
if (checkicon(fm, entry, patt)) {
Expand Down

0 comments on commit 2936002

Please sign in to comment.