Added an S_ISDIR check before opendir() to work on hfsplus volumes (?)
authorFrancois Fleuret <francois@fleuret.org>
Sat, 19 Jun 2010 09:53:32 +0000 (11:53 +0200)
committerFrancois Fleuret <francois@fleuret.org>
Sat, 19 Jun 2010 09:53:32 +0000 (11:53 +0200)
dus.c

diff --git a/dus.c b/dus.c
index 326abeb..03bd980 100644 (file)
--- a/dus.c
+++ b/dus.c
@@ -106,20 +106,22 @@ size_sum_t entry_size(const char *name) {
     return 0;
   }
 
-  dir = opendir(name);
-
-  if(dir) {
-    while((dir_e = readdir(dir))) {
-      if(!ignore_entry(dir_e->d_name)) {
-        snprintf(subname, PATH_MAX, "%s/%s", name, dir_e->d_name);
-        result += entry_size(subname);
+  if(S_ISDIR(dummy.st_mode)) {
+    dir = opendir(name);
+    if(dir) {
+      while((dir_e = readdir(dir))) {
+        if(!ignore_entry(dir_e->d_name)) {
+          snprintf(subname, PATH_MAX, "%s/%s", name, dir_e->d_name);
+          result += entry_size(subname);
+        }
       }
+      closedir(dir);
+    } else {
+      fprintf(stderr, "Can not open directory %s: %s\n", name, strerror(errno));
+      exit(EXIT_FAILURE);
     }
-    closedir(dir);
-  } else {
-    if(S_ISREG(dummy.st_mode)) {
-      result += dummy.st_size;
-    }
+  } else if(S_ISREG(dummy.st_mode)) {
+    result += dummy.st_size;
   }
 
   return result;