recursion bug: don't follow symlinks
authorMarkus Bröker <mbroeker@largo.dyndns.tv>
Sun, 24 Oct 2010 20:56:59 +0200
changeset 150 75133486ba7e
parent 149 5acf77b9b7a0
child 151 a8c2649cf277
recursion bug: don't follow symlinks committer: Markus Bröker <mbroeker@largo.homelinux.org>
lsflib/include/lsf/lsf.h
lsflib/src/getdir.c
lsflib/src/md5recursive.c
--- a/lsflib/include/lsf/lsf.h
+++ b/lsflib/include/lsf/lsf.h
@@ -27,9 +27,12 @@
 /* isDir returns true, if a fd points to a dir */
 int isDir (char *);
 
-/* isDir returns true, if a fd points to a file */
+/* isFile returns true, if a fd points to a file */
 int isFile (char *);
 
+/* isLink returns true, if a fd points to a link */
+int isLink(char *);
+
 /* getdir prints a dir hierarchy */
 void getdir (char *, int);
 
--- a/lsflib/src/getdir.c
+++ b/lsflib/src/getdir.c
@@ -17,7 +17,7 @@
 {
     struct stat buf;
 
-    if (!stat (filename, &buf))
+    if (!lstat (filename, &buf))
         return (S_ISDIR (buf.st_mode));
 
     return 0;
@@ -27,12 +27,22 @@
 {
     struct stat buf;
 
-    if (!stat (filename, &buf))
+    if (!lstat (filename, &buf))
         return (S_ISREG (buf.st_mode));
 
     return 0;
 }
 
+int isLink (char *filename)
+{
+    struct stat buf;
+
+    if (!lstat (filename, &buf))
+        return (S_ISLNK (buf.st_mode));
+
+    return 0;
+}
+
 void getdir (char *root, int recursive)
 {
     struct dirent *entry;
--- a/lsflib/src/md5recursive.c
+++ b/lsflib/src/md5recursive.c
@@ -38,6 +38,7 @@
 
         if (isDir (list)) {
             fprintf (stderr, "Directory: %s\n", list);
+
             if (recursive) {
                 md5recursive (list, recursive);
             }