-
Notifications
You must be signed in to change notification settings - Fork 0
/
CPCommand.cpp
30 lines (28 loc) · 881 Bytes
/
CPCommand.cpp
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
#include "CPCommand.h"
#include<iostream>
#include <sstream>
using namespace std;
CPCommand::CPCommand(AbstractFileSystem* fileSys) : fs(fileSys) {}
int CPCommand::execute(std::string& CWD, std::string options) {
istringstream ss(options);
string file_name, des_path;
ss >> file_name;
ss >> des_path;
string curr_path = CWD + '/' + file_name;
AbstractFile* curr_file = fs->openFile(curr_path);
vector<char> path = curr_file->read();
AbstractFile* copy_file = curr_file->clone();
path = copy_file->read();
fs->closeFile(curr_file);
des_path += "/" + file_name;
int result = fs->addFile(des_path, copy_file);
if (result != success) {
cout << "failed to copy file to file system" << endl;
return failedtocopy;
}
return result;
}
void CPCommand::displayInfo() {
cout << "copy file" << endl;
cout << "Usage: cp <file to copy><full_path_to_destination>" << endl;
}