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
#include <memory>
#include <unistd.h>
#include <limits.h>
+#include <sys/types.h>
+#include <sys/stat.h>
#include <pcrecpp.h>
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)
ERROR_REFERENCE_NOT_FOUND,
ERROR_DECODING_URL,
ERROR_OUTBOUND_LNK,
- ERROR_READING_LNK
+ ERROR_READING_LNK,
+ ERROR_LSTAT
};
ReferenceValidator(const std::string &dirpath);