From: Nelson Ferreira Date: Fri, 3 Apr 2020 12:11:49 +0000 (-0400) Subject: Fix directory-files{,-recur} detection of symlinks to dirs X-Git-Tag: v22.1.17~7^2~3 X-Git-Url: http://cgit.sxemacs.org/?p=sxemacs;a=commitdiff_plain;h=cedd8dcf8f3a1cdbc417d5ca4dce15993f99b5a2 Fix directory-files{,-recur} detection of symlinks to dirs * src/dired.c(dfr_inner): For the systems without d_type in dirent, the code did not try to detect symlinks to directories, preventing 'subdir from working. Added same logic for that branch as in the case where d_type is present. Signed-off-by: Nelson Ferreira --- diff --git a/src/dired.c b/src/dired.c index 7213fb3..9f78b0e 100644 --- a/src/dired.c +++ b/src/dired.c @@ -269,43 +269,47 @@ dfr_inner(dirent_t *res, } #else /* defined(_DIRENT_HAVE_D_TYPE) && USE_D_TYPE */ statnam = (char*)XSTRING_DATA(fullname); - if (sxemacs_stat(statnam, &st) == 0 && - (st.st_mode & S_IFMT) == S_IFDIR) { - char *canon_name = NULL; - - /* ugly things may happen when a link - * points back to a directory in our recurring - * area, ln -s . foo is a candidate - * now, we canonicalise the filename, i.e. - * resolve all symlinks and afterwards we - * store it to our companion bloom filter - * The ugly things are even worse than in the - * case of D_TYPE, since we !always! have to - * check against the bloom filter. - */ - canon_name = CANONICALISE_FILENAME(statnam); - - if (canon_name) { - /* now, recycle full name */ - fullname = make_ext_string( - canon_name, strlen(canon_name), - Qfile_name); - } - fullname = fname_as_directory(fullname); - - /* now stat statnam */ - if (sxemacs_stat(statnam, &st) == 0 && - (st.st_mode & S_IFMT) == S_IFDIR && - /* does the bloom know about the dir? */ - !NILP(compbf) && - !(bloom_owns_p(XBLOOM(compbf), fullname))) { + if (lstat(statnam, &st) == 0) { + if ((st.st_mode & S_IFMT) == S_IFDIR) { dir_p = 1; - } + } else if ((st.st_mode & S_IFMT) == S_IFLNK && !opts->symlink_file_p) { + char *canon_name = NULL; + + /* ugly things may happen when a link + * points back to a directory in our recurring + * area, ln -s . foo is a candidate + * now, we canonicalise the filename, i.e. + * resolve all symlinks and afterwards we + * store it to our companion bloom filter + * The ugly things are even worse than in the + * case of D_TYPE, since we !always! have to + * check against the bloom filter. + */ + canon_name = CANONICALISE_FILENAME(statnam); + + if (canon_name) { + /* now, recycle full name */ + fullname = make_ext_string( + canon_name, strlen(canon_name), + Qfile_name); + } + fullname = fname_as_directory(fullname); + + /* now stat statnam */ + if (sxemacs_stat(statnam, &st) == 0 && + (st.st_mode & S_IFMT) == S_IFDIR && + /* does the bloom know about the dir? */ + !NILP(compbf) && + !(bloom_owns_p(XBLOOM(compbf), fullname))) { + dir_p = 1; + } - if (canon_name) { - xfree(canon_name); + if (canon_name) { + xfree(canon_name); + } } } + #endif /* defined(_DIRENT_HAVE_D_TYPE) && USE_D_TYPE */ /* argh, here is a design flaw!