Ejemplo n.º 1
0
/*
* Определя какъв е адреса и го обхожда име по име.
* Ако намери директория която не съществува я създава.
* @return - търсената директория, ако поради някакви причини не се е създала връща root.
*/
Directory* CommandPrompt::createNestedDirectories(string path) {
	string currentName;
	Directory* result = NULL;
	Directory* tempDir = fs.getRoot();
	if (path.find('/') == string::npos) {
		if ((tempDir = tempDir->findDirByName(path)) == NULL) {
			result = new Directory(currentDir->getFSysPath(),
				fs.getNextNumber(),
				path,
				currentDir);
			currentDir->addChild(result);
			return result;
		}
			return tempDir;
	}
	else {
		for (int i = 0; i <= path.size(); i++) {
			if ((path[i] == '/' || i == path.size()) && !currentName.empty()) {	
				if (tempDir->findDirByName(currentName) == NULL) {
					result = new Directory(tempDir->getFSysPath(),
						fs.getNextNumber(),
						currentName,
						tempDir);
					tempDir->addChild(result);
				}
				tempDir = tempDir->findDirByName(currentName);
				currentName = "";
			}
			else if(path[i] != '/') {
				currentName += path[i];
			}
		}
	}
	if (result == NULL)
		return tempDir;
	return result;
}