Fix handling of symlinks (closes #2)
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user