virtual int main();
private:
- Row create_row(const string &, const FS::Stat &);
+ Row create_row(const string &, const FS::Stat &, const string & = string());
void print_rows(const vector<Row> &);
};
for(const string &fn: files)
{
if(long_format)
- rows.push_back(create_row(fn, FS::lstat(path/fn)));
+ {
+ FS::Path file_path = path/fn;
+ FS::Stat file_stat = FS::lstat(file_path);
+ rows.push_back(create_row(fn, file_stat, (file_stat.is_symlink() ? readlink(file_path).str() : string())));
+ }
else
{
Row r;
return 0;
}
-Ls::Row Ls::create_row(const string &name, const FS::Stat &st)
+Ls::Row Ls::create_row(const string &name, const FS::Stat &st, const string &link_target)
{
Row result;
if(st.is_regular())
result.push_back(format("%d", st.get_size()));
result.push_back(Time::DateTime(st.get_modify_time()).format("%Y-%m-%d %H:%M:%S"));
result.push_back(name);
+ if(!link_target.empty())
+ result.back() += format(" -> %s", link_target);
return result;
}
if(j==3)
line += string(padding, ' ');
line += row[j];
- if(j!=3)
+ if(j!=3 && j+1<row.size())
line += string(padding, ' ');
}
line += '\n';