本文整理汇总了C++中inode_state::getCwd方法的典型用法代码示例。如果您正苦于以下问题:C++ inode_state::getCwd方法的具体用法?C++ inode_state::getCwd怎么用?C++ inode_state::getCwd使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类inode_state
的用法示例。
在下文中一共展示了inode_state::getCwd方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fn_make
void fn_make (inode_state& state, const wordvec& words){
DEBUGF ('c', state);
DEBUGF ('c', words);
if (words.size() <= 0){
cout << "mkdir: missing operand" << endl;
return;
}
wordvec newData(words.begin()+2, words.end());
wordvec pathvec = split (words[1], "/");
string fullpath = "";
string filename = *(pathvec.end()-1);
for (auto it = pathvec.begin(); it != pathvec.end()-1; ++it)
fullpath += (*it + "/");
inode_ptr res = resolvePath(fullpath, state.getCwd()); //resulting path before filename
if (res == nullptr) return;
inode_ptr file = res->getContents()->getNode(filename); //search directory for filename if existing
if (file != nullptr && res != nullptr) {
if(file->isDirectory()) //getContents()->getNode(words[1])
return;
file->getContents()->writefile(newData);
return;
}
res->getContents()->mkfile(filename);
res->getContents()->getNode(filename)->getContents()->writefile(newData);
inode_ptr ogcwd = state.getCwd();
//inode_ptr newFile = state.getCwd()->getContents()->mkfile(words[1]);
//wordvec newData(words.begin()+2, words.end());
//newFile->getContents()->writefile(newData);
}
示例2: fn_cat
void fn_cat (inode_state& state, const wordvec& words){
DEBUGF ('c', state);
DEBUGF ('c', words);
string filename = *(words.end()-1);
inode_ptr ogcwd = state.getCwd();
inode_ptr res = resolvePath(words[1], state.getCwd());
if (res == nullptr){
throw command_error ("cat: " + filename + ": file does not exist");
return; }
if (res->isDirectory()) return; //error here
cout << res->getContents()->readfile() << endl;
}
示例3: fn_cd
void fn_cd (inode_state& state, const wordvec& words){
DEBUGF ('c', state);
DEBUGF ('c', words);
inode_ptr ogcwd = state.getCwd();
if (words.size() == 1){
state.setCwd(state.getRoot()->getContents()->getNode("/"));
return;
}
if (words.size() > 2) return;
if (ogcwd == state.getRoot()->getContents()->getNode("/") && words[1] == "..") return;
inode_ptr res = resolvePath(words[1], state.getCwd());
if (res == nullptr) return;
if (!res->isDirectory()) return;
state.setCwd(res);
}
示例4: fn_ls
void fn_ls (inode_state& state, const wordvec& words){
DEBUGF ('c', state);
DEBUGF ('c', words);
inode_ptr ogcwd = state.getCwd();
inode_ptr res = ogcwd;
if(words.size() > 1)
res = resolvePath(words[1], state.getCwd());
if (res == nullptr) return;
auto pathList = res->getContents()->getAllPaths();
state.setCwd(res);
fn_pwd(state, words);
for (size_t i = 0; i < pathList.size(); i++){
cout << pathList[i] << endl;
}
state.setCwd(ogcwd);
}
示例5: fn_rm
void fn_rm (inode_state& state, const wordvec& words){
DEBUGF ('c', state);
DEBUGF ('c', words);
if (words.size() <= 0) return; //error here?
wordvec pathvec = split(words[1],"/");
string fullpath = "";
string name = *(pathvec.end()-1);
for (auto it = pathvec.begin(); it != pathvec.end()-1; ++it)
fullpath += (*it + "/");
inode_ptr res = resolvePath(fullpath,state.getCwd());
if (res == nullptr) return; //error
inode_ptr rmfile = res->getContents()->getNode(name);
if (res != nullptr && rmfile != nullptr){
if(rmfile->isDirectory()){
if(rmfile->getContents()->getAllPaths().size() <= 2){
res->getContents()->remove(name);
return;
} else { return; /* not empty */ }}
res->getContents()->remove(name);
return;
}
/*
for (auto it = words.begin()+1; it != words.end(); ++it){
state.getCwd()->getContents()->remove(*it);
}
*/
}
示例6: fn_lsr
void fn_lsr (inode_state& state, const wordvec& words){
DEBUGF ('c', state);
DEBUGF ('c', words);
inode_ptr ogcwd = state.getCwd();
inode_ptr newCwd = ogcwd;
if (words.size() > 0){
newCwd = resolvePath(words[1], state.getCwd());
state.setCwd(newCwd);
}
auto pathList = newCwd->getContents()->getAllDirs();
wordvec ls {"ls"};
fn_ls(state, ls);
for(int i = 0; i < pathList.size(); i++){
DFS(pathList[i], state);
}
state.setCwd(ogcwd);
}
示例7: fn_mkdir
void fn_mkdir (inode_state& state, const wordvec& words){
DEBUGF ('c', state);
DEBUGF ('c', words);
if (words.size() <= 0){
cout << "mkdir: missing operand" << endl;
return;
}
//root case?
if (words[1] == "/"){
inode_ptr ogcwd = state.getCwd();
auto root = state.getCwd()->getContents()->mkdir(words[1]);
root->getContents()->setPath("..", ogcwd);
root->getContents()->setPath(".", root);
return;
}
wordvec pathvec = split(words[1], "/");
string dirname = *(pathvec.end()-1);
string fullpath = "";
for (auto it = pathvec.begin(); it != pathvec.end()-1; ++it)
fullpath += (*it + "/");
inode_ptr res = resolvePath(fullpath,state.getCwd());
if (res == nullptr) return;
inode_ptr directory = res->getContents()->getNode(dirname);
if (directory != nullptr && res != nullptr) //if filename exists and path exists
//dont overwrite anything (ie file or directory)
return;
inode_ptr dir = res->getContents()->mkdir(dirname);
dir->getContents()->setPath("..", res);
dir->getContents()->setPath(".",res->getContents()->getNode(dirname));
/*if (state.getCwd()->getContents()->getNode(filename) != nullptr)
return; */
/*
inode_ptr ogcwd = state.getCwd();
for (auto it = words.begin()+1; it != words.end(); ++it){
auto newDir = state.getCwd()->getContents()->mkdir(*it);
newDir->getContents()->setPath("..", ogcwd);
newDir->getContents()->setPath(".", newDir);
}
*/
}
示例8: fn_pwd
void fn_pwd (inode_state& state, const wordvec& words){
DEBUGF ('c', state);
DEBUGF ('c', words);
string pwd = state.getCwd()->getContents()->getPwd();
if (pwd.length() == 2){
cout << "/" << endl;
} else {
pwd = pwd.substr(2, pwd.length()-2);
cout << pwd << endl;
}
}
示例9: DFS
void DFS(string s, inode_state& state){
wordvec newLs {"ls", s};
fn_ls(state, newLs);
auto dirList = state.getCwd()->getContents()->getAllDirs();
if (dirList.size() == 0)
return;
map<string, int> disc;
for (int i = 0; i < dirList.size(); i++){
disc[dirList[i]] = 0;
}
for (auto it = disc.begin(); it != disc.end(); ++it){
if (it->second == 0){
disc[it->first] = 1;
inode_ptr ogcwd = state.getCwd();
state.setCwd(state.getCwd()->getContents()->getNode(it->first));
DFS(it->first, state);
state.setCwd(ogcwd);
}
}
}