Browse Source

Added nofollow flag (true by default) for ReadLocalFileList function

master
Michael Uleysky 1 month ago
parent
commit
c38a74402d
  1. 4
      include/mirrorfuncs.h
  2. 6
      src/mirrorfuncs.cpp

4
include/mirrorfuncs.h

@ -7,9 +7,9 @@
#include <sys/types.h> #include <sys/types.h>
#include <vector> #include <vector>
using michlib::Error;
using michlib::MDateTime; using michlib::MDateTime;
using michlib::RetVal; using michlib::RetVal;
using michlib::Error;
class DIRRAIIDT class DIRRAIIDT
{ {
@ -52,7 +52,7 @@ inline MString FileName(const MString& name)
bool MakePath(const MString& dname); bool MakePath(const MString& dname);
// Get local file list // Get local file list
RetVal<std::vector<struct FileInfo>> ReadLocalFileList(const MString& dir, const MString& path = ""); RetVal<std::vector<struct FileInfo>> ReadLocalFileList(const MString& dir, const bool nofollow = true, const MString& path = "");
// Download file to the local mirror // Download file to the local mirror
Error DownloadFile(const CURLRAII& chandle, const struct FileInfo& rinfo, const MString& root); Error DownloadFile(const CURLRAII& chandle, const struct FileInfo& rinfo, const MString& root);

6
src/mirrorfuncs.cpp

@ -27,7 +27,7 @@ bool MakePath(const MString& dname)
return true; return true;
} }
RetVal<std::vector<struct FileInfo>> ReadLocalFileList(const MString& dir, const MString& path) RetVal<std::vector<struct FileInfo>> ReadLocalFileList(const MString& dir, const bool nofollow, const MString& path)
{ {
const static MString pref = "ReadLocalFileList"; const static MString pref = "ReadLocalFileList";
@ -48,11 +48,11 @@ RetVal<std::vector<struct FileInfo>> ReadLocalFileList(const MString& dir, const
do { do {
if(dent->d_name[0] != '.') 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(ret != 0) return {pref, "Can't stat " + path + "/" + dir + "/" + dent->d_name};
if(S_ISDIR(st.st_mode)) // Directory, recurse 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; if(!list) return list;
out.insert(out.end(), list.Value().begin(), list.Value().end()); out.insert(out.end(), list.Value().begin(), list.Value().end());
} }

Loading…
Cancel
Save