From 0876dc9860f7ba09c12dfc9dced0649c828b7917 Mon Sep 17 00:00:00 2001 From: Chris Allegretta Date: Wed, 28 Mar 2001 13:04:08 +0000 Subject: [PATCH] Change some lstats to stats, check file via lstat first, then stat() if it's a link in the browser git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@579 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- BUGS | 5 +++-- ChangeLog | 9 +++++++-- files.c | 21 +++++++++++++++------ 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/BUGS b/BUGS index 5f47aab0..4b46ca29 100644 --- a/BUGS +++ b/BUGS @@ -103,9 +103,10 @@ the first fail if no string is entered (56) [FIXED]. - Page down on a file of editwinrows fails (again). Reported by Ryan Krebs (57) [FIXED]. -- File browser aborts on Solaris in qsort() call. (Reported by - Matthias Andree) (58) [FIXED by Matthias Andree]. ** Open BUGS ** +- File browser aborts on Solaris in qsort() call. (Reported by + Matthias Andree) (58). + $Id$ diff --git a/ChangeLog b/ChangeLog index 6a1e4453..0e6d5149 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,8 +5,13 @@ CVS - - Fixed typo in section 6.1 (discovered by Bob Farmer). - files.c: diralphasort() - - Changed stat calls to lstat to stop abort on symlinks, otherwise - return 0. (Matthias Andree, fixes bug #58) + - Stop abort on symlinks (Matthias Andree) + fielstat(), do_browse() + - Changed lstat calls to stat, which fixes the browser not + following links to directories. We only use lstat() when + printing the details of the file, and if it is a link, then + check via lstat() for link to a directory. If it is + a directory, display (dir), else use the normal "--". nano-1.0.0 - 03/22/2001 - General diff --git a/files.c b/files.c index 63d8fd6b..df907ff8 100644 --- a/files.c +++ b/files.c @@ -993,7 +993,7 @@ char *input_tab(char *buf, int place, int *lastWasTab, int *newplace) struct stat filestat(const char *path) { struct stat st; - lstat(path, &st); + stat(path, &st); return st; } @@ -1005,7 +1005,7 @@ int diralphasort(const void *va, const void *vb) { char *a = *(char **)va, *b = *(char **)vb; int answer = 0; - if ((lstat(a, &file1info) != -1) && (lstat(b, &file2info) != -1)) { + if ((stat(a, &file1info) != -1) && (stat(b, &file2info) != -1)) { /* If is a is a dir and b isn't, return -1. Else if b is a dir and a isn't, return 0. Else return a < b */ @@ -1285,13 +1285,22 @@ char *do_browser(char *inpath) col += strlen(foo); /* Put file info in the string also */ - st = filestat(filelist[j]); + /* We use lstat here to detect links, then if we find a + symlink we examine it via stat() to see if it is a + directory or just a file symlink */ + lstat(filelist[j], &st); if (S_ISDIR(st.st_mode)) strcpy(foo + longest - 5, "(dir)"); else { - if (S_ISLNK(st.st_mode)) - strcpy(foo + longest - 2, "--"); - else if (st.st_size < 1024) /* less than 1 K */ + if (S_ISLNK(st.st_mode)) { + /* Aha! It's a symlink! Now, is it a dir? If so, + mark it as such */ + st = filestat(filelist[j]); + if (S_ISDIR(st.st_mode)) + strcpy(foo + longest - 5, "(dir)"); + else + strcpy(foo + longest - 2, "--"); + } else if (st.st_size < 1024) /* less than 1 K */ sprintf(foo + longest - 7, "%4d B", (int) st.st_size); else if (st.st_size > 1073741824) /* at least 1 gig */ sprintf(foo + longest - 7, "%4d GB", (int) st.st_size / 1073741824); -- 2.39.5