示例#1
0
bool CommandCP::execute(FileSystem &fs, UDF& ) {

  int fd = open(arguments[1].c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0644);
  FileEntry *node = fs.getCurrentNode();

  if (fd == -1) {
	std::cerr << "Error: unable to open file" << std::endl;
	return false;
  }

  if (!fs.copy(arguments[0], fd)) {
	return false;
  }

  fs.setCurrentNode(node);
  std::cout << "Command CP executed." << std::endl;
  return true;
}
示例#2
0
int main (const int argc, const char *argv[]){
    try {
        if (argc < 4) {
            std::cout << "Usage: copy root source destination" << std::endl;
        } else {
            FileSystem fs = FileSystem(argv[1]);

            FileEntry source_d = fs.findEntry(argv[2], false);
            FileEntry destination_d = fs.findEntry(argv[3], true, source_d.dir);

            fs.copy(source_d, destination_d);
        }
        return 0;
    } catch (const char *message) {
        std::cerr << message << std::endl;
        return 1;
    } catch (const string msg) {
        std::cerr << msg << std::endl;
        return 1;
    }
}
示例#3
0
文件: shell.cpp 项目: andens/osfs
int main(void) {
	//_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );

    FileSystem fs;

    string userCommand, commandArr[MAXCOMMANDS];
    string user = "******";    // Change this if you want another user to be displayed
    string currentDir = "/";    // current directory, used for output

    bool bRun = true;
	fs.format();
	//HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

    do {
		currentDir = fs.GetCWD();
		string data = "";
		//SetConsoleTextAttribute(hConsole, 10);
		cout << user << " ";
		//SetConsoleTextAttribute(hConsole, 14);
		cout << currentDir << endl;
		//SetConsoleTextAttribute(hConsole, 15);
		cout << "$ ";
        getline(cin, userCommand);

		for (unsigned i = 0; i < MAXCOMMANDS; ++i)
			commandArr[i] = "";

        int nrOfCommands = parseCommandString(userCommand, commandArr);
        if (nrOfCommands > 0) {

            int cIndex = findCommand(commandArr[0]);
            switch(cIndex) {

            case 0: // quit
                bRun = false;
                cout << "Exiting\n";
                break;
            case 1: // format
				fs.format();
                break;
            case 2: // ls
				if (commandArr[1] == "")
					fs.ls();
				else
					fs.ls(commandArr[1]);
                break;
            case 3: // create
				printf("Please Insert Data:\n");
				getline( cin, data );
				fs.create(commandArr[1],data);
                break;
            case 4: // cat
				fs.cat(commandArr[1]);
                break;
            case 5: // createImage
				fs.createImage( commandArr[1] );
                break;
            case 6: // restoreImage
				fs.restoreImage( commandArr[1] );
                break;
            case 7: // rm
				fs.rm(commandArr[1]);
                break;

            case 8: // copy
				fs.copy( commandArr[1], commandArr[2] );
                break;

            case 9: // append
				fs.append( commandArr[1], commandArr[2] );
                break;

            case 10: // rename
				fs.rename( commandArr[1], commandArr[2] );
                break;

            case 11: // mkdir
				fs.mkdir(commandArr[1]);
                break;

            case 12: // cd
				fs.cd(commandArr[1]);
                break;

            case 13: // pwd
				cout << fs.GetCWD() << endl;
                break;

            case 14: // help
                cout << help() << endl;
                break;

			case 15: // rmdir
				fs.rmdir(commandArr[1]);
				break;

			case 16: // chmod
				fs.chmod( atoi( commandArr[1].c_str() ), commandArr[2] );
				break;

            default:
                cout << "Unknown command: " << commandArr[0] << endl;

            }

			cout << endl;
        }
    } while (bRun == true);

    return 0;
}