From 55dcccebc93fef5f580a920411d18cd68ae3d744 Mon Sep 17 00:00:00 2001 From: Wirlaburla Date: Tue, 31 Dec 2024 15:40:11 -0600 Subject: [PATCH] Fix handling of symlinks (closes #2) --- src/plugins/filer_local/filer_local.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/plugins/filer_local/filer_local.cpp b/src/plugins/filer_local/filer_local.cpp index a4eb678..11897e3 100644 --- a/src/plugins/filer_local/filer_local.cpp +++ b/src/plugins/filer_local/filer_local.cpp @@ -310,7 +310,6 @@ public: std::ostringstream listStream; for(const auto& p : fs::directory_iterator(resolved, - fs::directory_options::follow_directory_symlink | fs::directory_options::skip_permission_denied)) { struct stat fstat; @@ -318,7 +317,7 @@ public: time_t rawtime; char timebuff[80]; - if (stat(p.path().c_str(), &fstat) == -1) { + if (lstat(p.path().c_str(), &fstat) == -1) { fd.error = file_error{FilerStatusCodes::NoPermission, "Unable to stat file"}; break; } @@ -330,11 +329,12 @@ public: // God should've smitten me before I wrote such attrocities. char* line; - fs::perms fperms = fs::status(p).permissions(); + fs::perms fperms = fs::symlink_status(p).permissions(); + bool is_link = S_ISLNK(fstat.st_mode); asprintf( &line, - "%c%c%c%c%c%c%c%c%c%c %4u %4u %4u %12u %s %s\r\n", - p.is_directory()?'d':'-', + "%c%c%c%c%c%c%c%c%c%c %4u %4u %4u %12u %s %s%s\r\n", + is_link?'l':(p.is_directory()?'d':'-'), (fperms & fs::perms::owner_read) != fs::perms::none?'r':'-', (fperms & fs::perms::owner_write) != fs::perms::none?'w':'-', (fperms & fs::perms::owner_exec) != fs::perms::none?'x':'-', @@ -344,12 +344,13 @@ public: (fperms & fs::perms::others_read) != fs::perms::none?'r':'-', (fperms & fs::perms::others_write) != fs::perms::none?'w':'-', (fperms & fs::perms::others_exec) != fs::perms::none?'x':'-', - fs::hard_link_count(p), + fstat.st_nlink, fstat.st_uid, fstat.st_gid, fstat.st_size, timebuff, - p.path().filename().c_str() + p.path().filename().c_str(), + is_link?(" -> " + fs::read_symlink(p).string()).c_str():"" ); listStream << std::string(line);