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
master
Chris Allegretta 2001-03-28 13:04:08 +00:00
parent 49805175e3
commit 0876dc9860
3 changed files with 25 additions and 10 deletions

5
BUGS
View File

@ -103,9 +103,10 @@
the first fail if no string is entered (56) [FIXED]. the first fail if no string is entered (56) [FIXED].
- Page down on a file of editwinrows fails (again). Reported by Ryan - Page down on a file of editwinrows fails (again). Reported by Ryan
Krebs (57) [FIXED]. Krebs (57) [FIXED].
- File browser aborts on Solaris in qsort() call. (Reported by
Matthias Andree) (58) [FIXED by Matthias Andree].
** Open BUGS ** ** Open BUGS **
- File browser aborts on Solaris in qsort() call. (Reported by
Matthias Andree) (58).
$Id$ $Id$

View File

@ -5,8 +5,13 @@ CVS -
- Fixed typo in section 6.1 (discovered by Bob Farmer). - Fixed typo in section 6.1 (discovered by Bob Farmer).
- files.c: - files.c:
diralphasort() diralphasort()
- Changed stat calls to lstat to stop abort on symlinks, otherwise - Stop abort on symlinks (Matthias Andree)
return 0. (Matthias Andree, fixes bug #58) 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 nano-1.0.0 - 03/22/2001
- General - General

19
files.c
View File

@ -993,7 +993,7 @@ char *input_tab(char *buf, int place, int *lastWasTab, int *newplace)
struct stat filestat(const char *path) { struct stat filestat(const char *path) {
struct stat st; struct stat st;
lstat(path, &st); stat(path, &st);
return st; return st;
} }
@ -1005,7 +1005,7 @@ int diralphasort(const void *va, const void *vb) {
char *a = *(char **)va, *b = *(char **)vb; char *a = *(char **)va, *b = *(char **)vb;
int answer = 0; 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. /* 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 if b is a dir and a isn't, return 0.
Else return a < b */ Else return a < b */
@ -1285,13 +1285,22 @@ char *do_browser(char *inpath)
col += strlen(foo); col += strlen(foo);
/* Put file info in the string also */ /* 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)) if (S_ISDIR(st.st_mode))
strcpy(foo + longest - 5, "(dir)"); strcpy(foo + longest - 5, "(dir)");
else { else {
if (S_ISLNK(st.st_mode)) 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, "--"); strcpy(foo + longest - 2, "--");
else if (st.st_size < 1024) /* less than 1 K */ } else if (st.st_size < 1024) /* less than 1 K */
sprintf(foo + longest - 7, "%4d B", (int) st.st_size); sprintf(foo + longest - 7, "%4d B", (int) st.st_size);
else if (st.st_size > 1073741824) /* at least 1 gig */ else if (st.st_size > 1073741824) /* at least 1 gig */
sprintf(foo + longest - 7, "%4d GB", (int) st.st_size / 1073741824); sprintf(foo + longest - 7, "%4d GB", (int) st.st_size / 1073741824);