-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd_chown.cpp
More file actions
38 lines (38 loc) · 927 Bytes
/
cmd_chown.cpp
File metadata and controls
38 lines (38 loc) · 927 Bytes
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
#include"inode_helper.h"
#include"path_helper.h"
#include "arg_parser.h"
#include "user_context.h"
#include <iostream>
using namespace std;
class CmdChown :public IRunnable {
public:
int run(int argc, string* argv) override {
if (argc >= 2) {
string target = argv[0];
string filepath = argv[1];
Dir curDir = Dir(UserContext::cur_dir_id);
PathRoute route;
PathHelper::GetPathRoute(filepath, route);
INode * inode = PathHelper::GetINodeFromPath(curDir, route);
if (inode == 0) {
cerr << "file is not exist!" << endl;
return -1;
}
if (inode->IsOwner() == false) {
cerr << "permission deny" << endl;
return -1;
}
ID_T user_id = UserHelper::FindUser(target);
if (user_id == 0) {
cerr << "user not exist" << endl;
return -1;
}
inode->GetINode()->owner_id = user_id;
return 0;
}
else {
cerr << "usage: chown USER FILEPATH" << endl;
return -1;
}
}
};