-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd_ls.cpp
More file actions
43 lines (43 loc) · 1.14 KB
/
cmd_ls.cpp
File metadata and controls
43 lines (43 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include"inode_helper.h"
#include"path_helper.h"
#include "arg_parser.h"
#include "user_context.h"
class CmdLs:public IRunnable {
public:
int run(int argc, string* argv) override {
INode * inode;
if (argc >= 1) {
string filepath = argv[0];
Dir curDir = Dir(UserContext::cur_dir_id);
PathRoute route;
PathHelper::GetPathRoute(filepath, route);
inode = PathHelper::GetINodeFromPath(curDir, route);
if (inode == 0) {
cerr << filepath << "not exist!";
return -1;
}
}
else {
inode = new Dir(UserContext::cur_dir_id);
}
if (inode->GetType() != INodeType::kDIR) {
cerr << argv[0] << "is not a dir!";
return -1;
}
Dir cur = Dir(*inode);
auto entries = cur.getEntries();
cout << "id\tpermission\towner\tname\tmtime\tatime" << endl;
for (auto entry : entries) {
INode inode = INode(entry.inode_id);
cout << entry.inode_id <<"\t"
<<inode.GetOwnerPermission() << inode.GetGlobalPermission()<<"\t"
<<UserHelper::FindUserByID(inode.GetINode()->owner_id)<<"\t"
<<entry.name << "\t"
<< inode.GetMTime() << "\t"
<< inode.GetATime() << "\t"
<< endl;
}
delete inode;
return 0;
}
};