Fallback to lstat() if readdir() fails to give type in reference checking 22/67822/3
authorTomasz Iwanek <t.iwanek@samsung.com>
Thu, 28 Apr 2016 09:13:09 +0000 (11:13 +0200)
committersangwan kwon <sangwan.kwon@samsung.com>
Wed, 11 May 2016 09:51:01 +0000 (02:51 -0700)
Some filesytem types may not set d_type field to indicate
the type of directory entry. This code adds workaround to
try to stat file if directory entry type is unknown.

This will be basicly needed to check file references when
we are using tzip filesystem for storing tizen package
files. Although tzip implements readdir(), it is not
setting d_type. Correct behaviour of caller is to handle
value DT_UNKNOWN.

Change-Id: I45642ae5d50a3d3f3fbc09e41f54e4a118037e1d

vcore/vcore/ReferenceValidator.cpp
vcore/vcore/ReferenceValidator.h

index 3b59682..509ba1b 100644 (file)
@@ -28,6 +28,8 @@
 #include <memory>
 #include <unistd.h>
 #include <limits.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 
 #include <pcrecpp.h>
 
@@ -177,6 +179,21 @@ ReferenceValidator::Result ReferenceValidator::Impl::dfsCheckDirectories(
             continue;
         }
 
+        if (result->d_type == DT_UNKNOWN) {
+            // try to stat inode when readdir is not returning known type
+            std::string path = currentDir + "/" + result->d_name;
+            struct stat s;
+            if (lstat(path.c_str(), &s) != 0) {
+                closedir(dirp);
+                return ERROR_LSTAT;
+            }
+            if (S_ISREG(s.st_mode)) {
+                result->d_type = DT_REG;
+            } else if (S_ISDIR(s.st_mode)) {
+                result->d_type = DT_DIR;
+            }
+        }
+
         if (currentDir == m_dirpath && result->d_type == DT_REG &&
             !strcmp(result->d_name, SPECIAL_SYMBOL_AUTHOR_SIGNATURE_FILE) &&
             isAuthorSignature)
index cd819c3..f604b42 100644 (file)
@@ -41,7 +41,8 @@ class ReferenceValidator : VcoreDPL::Noncopyable
         ERROR_REFERENCE_NOT_FOUND,
         ERROR_DECODING_URL,
         ERROR_OUTBOUND_LNK,
-        ERROR_READING_LNK
+        ERROR_READING_LNK,
+        ERROR_LSTAT
     };
 
     ReferenceValidator(const std::string &dirpath);