diff options
Diffstat (limited to 'src/dir_scan.c')
-rw-r--r-- | src/dir_scan.c | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/dir_scan.c b/src/dir_scan.c index 03a582b..9629f32 100644 --- a/src/dir_scan.c +++ b/src/dir_scan.c @@ -57,6 +57,7 @@ static uint64_t curdev; /* current device we're scanning on */ /* scratch space */ static struct dir *buf_dir; static struct dir_ext buf_ext[1]; +static unsigned int buf_nlink; #if HAVE_LINUX_MAGIC_H && HAVE_SYS_STATFS_H && HAVE_STATFS @@ -120,8 +121,11 @@ static void stat_to_dir(struct stat *fs) { else if(S_ISDIR(fs->st_mode)) buf_dir->flags |= FF_DIR; - if(!S_ISDIR(fs->st_mode) && fs->st_nlink > 1) + if(!S_ISDIR(fs->st_mode) && fs->st_nlink > 1) { buf_dir->flags |= FF_HLNKC; + buf_nlink = fs->st_nlink; + } else + buf_nlink = 0; if(dir_scan_smfs && curdev != buf_dir->dev) buf_dir->flags |= FF_OTHFS; @@ -193,7 +197,7 @@ static int dir_scan_recurse(const char *name) { if(chdir(name)) { dir_setlasterr(dir_curpath); buf_dir->flags |= FF_ERR; - if(dir_output.item(buf_dir, name, buf_ext) || dir_output.item(NULL, 0, NULL)) { + if(dir_output.item(buf_dir, name, buf_ext, buf_nlink) || dir_output.item(NULL, 0, NULL, 0)) { dir_seterr("Output error: %s", strerror(errno)); return 1; } @@ -203,7 +207,7 @@ static int dir_scan_recurse(const char *name) { if((dir = dir_read(&fail)) == NULL) { dir_setlasterr(dir_curpath); buf_dir->flags |= FF_ERR; - if(dir_output.item(buf_dir, name, buf_ext) || dir_output.item(NULL, 0, NULL)) { + if(dir_output.item(buf_dir, name, buf_ext, buf_nlink) || dir_output.item(NULL, 0, NULL, 0)) { dir_seterr("Output error: %s", strerror(errno)); return 1; } @@ -218,12 +222,12 @@ static int dir_scan_recurse(const char *name) { if(fail) buf_dir->flags |= FF_ERR; - if(dir_output.item(buf_dir, name, buf_ext)) { + if(dir_output.item(buf_dir, name, buf_ext, buf_nlink)) { dir_seterr("Output error: %s", strerror(errno)); return 1; } fail = dir_walk(dir); - if(dir_output.item(NULL, 0, NULL)) { + if(dir_output.item(NULL, 0, NULL, 0)) { dir_seterr("Output error: %s", strerror(errno)); return 1; } @@ -308,11 +312,11 @@ static int dir_scan_item(const char *name) { if(buf_dir->flags & FF_DIR && !(buf_dir->flags & (FF_ERR|FF_EXL|FF_OTHFS|FF_KERNFS|FF_FRMLNK))) fail = dir_scan_recurse(name); else if(buf_dir->flags & FF_DIR) { - if(dir_output.item(buf_dir, name, buf_ext) || dir_output.item(NULL, 0, NULL)) { + if(dir_output.item(buf_dir, name, buf_ext, 0) || dir_output.item(NULL, 0, NULL, 0)) { dir_seterr("Output error: %s", strerror(errno)); fail = 1; } - } else if(dir_output.item(buf_dir, name, buf_ext)) { + } else if(dir_output.item(buf_dir, name, buf_ext, buf_nlink)) { dir_seterr("Output error: %s", strerror(errno)); fail = 1; } @@ -333,6 +337,7 @@ static int dir_walk(char *dir) { dir_curpath_enter(cur); memset(buf_dir, 0, offsetof(struct dir, name)); memset(buf_ext, 0, sizeof(struct dir_ext)); + buf_nlink = 0; fail = dir_scan_item(cur); dir_curpath_leave(); } @@ -350,6 +355,7 @@ static int process(void) { memset(buf_dir, 0, offsetof(struct dir, name)); memset(buf_ext, 0, sizeof(struct dir_ext)); + buf_nlink = 0; if((path = path_real(dir_curpath)) == NULL) dir_seterr("Error obtaining full path: %s", strerror(errno)); @@ -376,13 +382,13 @@ static int process(void) { buf_dir->flags |= FF_ERR; stat_to_dir(&fs); - if(dir_output.item(buf_dir, dir_curpath, buf_ext)) { + if(dir_output.item(buf_dir, dir_curpath, buf_ext, buf_nlink)) { dir_seterr("Output error: %s", strerror(errno)); fail = 1; } if(!fail) fail = dir_walk(dir); - if(!fail && dir_output.item(NULL, 0, NULL)) { + if(!fail && dir_output.item(NULL, 0, NULL, 0)) { dir_seterr("Output error: %s", strerror(errno)); fail = 1; } |