From 31f77aea957f603c982f41acadf1023166fad509 Mon Sep 17 00:00:00 2001 From: Bartlomiej Grzelewski Date: Thu, 28 Apr 2016 15:06:46 +0200 Subject: [PATCH] Fix implementation of filesystem.cpp The function getFilesFromDirectory should not follow links. It should return the list of files in directlry. Change-Id: I142f8e0bc3a992da2f14d69e758426aff5df2ab6 --- src/common/filesystem.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) 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)) { -- 2.7.4