Fix handling of symlinks (closes #2)
This commit is contained in:
@@ -310,7 +310,6 @@ public:
|
|||||||
|
|
||||||
std::ostringstream listStream;
|
std::ostringstream listStream;
|
||||||
for(const auto& p : fs::directory_iterator(resolved,
|
for(const auto& p : fs::directory_iterator(resolved,
|
||||||
fs::directory_options::follow_directory_symlink |
|
|
||||||
fs::directory_options::skip_permission_denied)) {
|
fs::directory_options::skip_permission_denied)) {
|
||||||
|
|
||||||
struct stat fstat;
|
struct stat fstat;
|
||||||
@@ -318,7 +317,7 @@ public:
|
|||||||
time_t rawtime;
|
time_t rawtime;
|
||||||
char timebuff[80];
|
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"};
|
fd.error = file_error{FilerStatusCodes::NoPermission, "Unable to stat file"};
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -330,11 +329,12 @@ public:
|
|||||||
|
|
||||||
// God should've smitten me before I wrote such attrocities.
|
// God should've smitten me before I wrote such attrocities.
|
||||||
char* line;
|
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(
|
asprintf(
|
||||||
&line,
|
&line,
|
||||||
"%c%c%c%c%c%c%c%c%c%c %4u %4u %4u %12u %s %s\r\n",
|
"%c%c%c%c%c%c%c%c%c%c %4u %4u %4u %12u %s %s%s\r\n",
|
||||||
p.is_directory()?'d':'-',
|
is_link?'l':(p.is_directory()?'d':'-'),
|
||||||
(fperms & fs::perms::owner_read) != fs::perms::none?'r':'-',
|
(fperms & fs::perms::owner_read) != fs::perms::none?'r':'-',
|
||||||
(fperms & fs::perms::owner_write) != fs::perms::none?'w':'-',
|
(fperms & fs::perms::owner_write) != fs::perms::none?'w':'-',
|
||||||
(fperms & fs::perms::owner_exec) != fs::perms::none?'x':'-',
|
(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_read) != fs::perms::none?'r':'-',
|
||||||
(fperms & fs::perms::others_write) != fs::perms::none?'w':'-',
|
(fperms & fs::perms::others_write) != fs::perms::none?'w':'-',
|
||||||
(fperms & fs::perms::others_exec) != fs::perms::none?'x':'-',
|
(fperms & fs::perms::others_exec) != fs::perms::none?'x':'-',
|
||||||
fs::hard_link_count(p),
|
fstat.st_nlink,
|
||||||
fstat.st_uid,
|
fstat.st_uid,
|
||||||
fstat.st_gid,
|
fstat.st_gid,
|
||||||
fstat.st_size,
|
fstat.st_size,
|
||||||
timebuff,
|
timebuff,
|
||||||
p.path().filename().c_str()
|
p.path().filename().c_str(),
|
||||||
|
is_link?(" -> " + fs::read_symlink(p).string()).c_str():""
|
||||||
);
|
);
|
||||||
|
|
||||||
listStream << std::string(line);
|
listStream << std::string(line);
|
||||||
|
|||||||
Reference in New Issue
Block a user