From: Bartlomiej Grzelewski Date: Thu, 28 Apr 2016 13:06:46 +0000 (+0200) Subject: Fix implementation of filesystem.cpp X-Git-Tag: accepted/tizen/common/20160504.125034~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F33%2F67833%2F1;p=platform%2Fcore%2Fsecurity%2Fsecurity-manager.git Fix implementation of filesystem.cpp The function getFilesFromDirectory should not follow links. It should return the list of files in directlry. Change-Id: I142f8e0bc3a992da2f14d69e758426aff5df2ab6 --- diff --git a/src/common/filesystem.cpp b/src/common/filesystem.cpp index b278ef1..5ad5232 100644 --- a/src/common/filesystem.cpp +++ b/src/common/filesystem.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -46,7 +47,7 @@ FileNameVector getFilesFromDirectory(const std::string &path) FileNameVector result; dirent tmp, *ptr; int err; - std::unique_ptr> dir(opendir(path.c_str()), closedir); + std::unique_ptr dir(opendir(path.c_str()), closedir); if (!dir.get()) { err = errno; @@ -63,10 +64,8 @@ FileNameVector getFilesFromDirectory(const std::string &path) break; struct stat finfo; - std::string filepath = path + "/" + ptr->d_name; - if (0 > stat(filepath.c_str(), &finfo)) { - ThrowMsg(FS::Exception::FileError, "Error reading: " << filepath); - continue; + if (0 > fstatat(dirfd(dir.get()), ptr->d_name, &finfo, AT_SYMLINK_NOFOLLOW)) { + ThrowMsg(FS::Exception::FileError, "Error reading: " << ptr->d_name); } if (S_ISREG(finfo.st_mode)) {