From 69a8796e474f52b5150ccab7f9b613524dd06b1d Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Tue, 23 Mar 2010 21:21:49 +0300 Subject: [PATCH] Ticket #2121: don't calculate directory size if directory is symlink. Signed-off-by: Andrew Borodin --- src/file.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/file.c b/src/file.c index 072f1a70..1ee568d4 100644 --- a/src/file.c +++ b/src/file.c @@ -1573,10 +1573,24 @@ compute_dir_size (const char *dirname, const void *ui, compute_dir_size_callback cback, off_t *ret_marked, double *ret_total) { + int res; + struct stat s; DIR *dir; struct dirent *dirent; FileProgressStatus ret = FILE_CONT; + res = mc_lstat (dirname, &s); + + if (res != 0) + return ret; + + /* don't scan symlink to directory */ + if (S_ISLNK (s.st_mode)) { + (*ret_marked)++; + *ret_total += s.st_size; + return ret; + } + dir = mc_opendir (dirname); if (dir == NULL) @@ -1584,8 +1598,6 @@ compute_dir_size (const char *dirname, const void *ui, while ((dirent = mc_readdir (dir)) != NULL) { char *fullname; - int res; - struct stat s; ret = (cback != NULL) ? cback (ui, dirname) : FILE_CONT; -- 2.11.4.GIT