From c38a74402d41347acd089e191cf3e584b56a5786 Mon Sep 17 00:00:00 2001 From: Michael Uleysky Date: Wed, 2 Oct 2024 12:20:10 +1000 Subject: [PATCH] Added nofollow flag (true by default) for ReadLocalFileList function --- include/mirrorfuncs.h | 4 ++-- src/mirrorfuncs.cpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/mirrorfuncs.h b/include/mirrorfuncs.h index ab16eda..6091b66 100644 --- a/include/mirrorfuncs.h +++ b/include/mirrorfuncs.h @@ -7,9 +7,9 @@ #include #include +using michlib::Error; using michlib::MDateTime; using michlib::RetVal; -using michlib::Error; class DIRRAIIDT { @@ -52,7 +52,7 @@ inline MString FileName(const MString& name) bool MakePath(const MString& dname); // Get local file list -RetVal> ReadLocalFileList(const MString& dir, const MString& path = ""); +RetVal> ReadLocalFileList(const MString& dir, const bool nofollow = true, const MString& path = ""); // Download file to the local mirror Error DownloadFile(const CURLRAII& chandle, const struct FileInfo& rinfo, const MString& root); diff --git a/src/mirrorfuncs.cpp b/src/mirrorfuncs.cpp index 72c5f2b..d0efc2c 100644 --- a/src/mirrorfuncs.cpp +++ b/src/mirrorfuncs.cpp @@ -27,7 +27,7 @@ bool MakePath(const MString& dname) return true; } -RetVal> ReadLocalFileList(const MString& dir, const MString& path) +RetVal> ReadLocalFileList(const MString& dir, const bool nofollow, const MString& path) { const static MString pref = "ReadLocalFileList"; @@ -48,11 +48,11 @@ RetVal> ReadLocalFileList(const MString& dir, const do { if(dent->d_name[0] != '.') { - int ret = fstatat(dfd, dent->d_name, &st, AT_SYMLINK_NOFOLLOW); + int ret = fstatat(dfd, dent->d_name, &st, nofollow ? AT_SYMLINK_NOFOLLOW : 0); if(ret != 0) return {pref, "Can't stat " + path + "/" + dir + "/" + dent->d_name}; if(S_ISDIR(st.st_mode)) // Directory, recurse { - auto list = ReadLocalFileList(dir + "/" + dent->d_name, path + (path.Exist() ? "/" : "") + dent->d_name); + auto list = ReadLocalFileList(dir + "/" + dent->d_name, nofollow, path + (path.Exist() ? "/" : "") + dent->d_name); if(!list) return list; out.insert(out.end(), list.Value().begin(), list.Value().end()); }