mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-19 09:35:15 -04:00
Avoid doing commands without verifying parameters
This commit is contained in:
parent
a8bd3ba78f
commit
30ef57f41c
@ -173,6 +173,20 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator==(const basic_string& rhs) const {
|
||||
if(size() != rhs.size()){
|
||||
return false;
|
||||
}
|
||||
|
||||
for(size_t i = 0; i < size(); ++i){
|
||||
if(_data[i] != rhs._data[i]){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//Iterators
|
||||
|
||||
iterator begin(){
|
||||
|
@ -499,6 +499,18 @@ void pwd_command(const vector<string>&){
|
||||
k_print_line();
|
||||
}
|
||||
|
||||
bool directory_exists(const string& name){
|
||||
auto files = disks::ls();
|
||||
|
||||
for(auto& file : files){
|
||||
if(file.directory && file.file_name == name){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void cd_command(const vector<string>& params){
|
||||
if(!disks::mounted_partition() || !disks::mounted_disk()){
|
||||
k_print_line("Nothing is mounted");
|
||||
@ -515,11 +527,28 @@ void cd_command(const vector<string>& params){
|
||||
disks::current_directory().pop_back();
|
||||
}
|
||||
} else {
|
||||
disks::current_directory().push_back(params[1]);
|
||||
if(directory_exists(params[1])){
|
||||
disks::current_directory().push_back(params[1]);
|
||||
} else {
|
||||
k_print("cd: No such file or directory: ");
|
||||
k_print_line(params[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool file_exists(const string& name){
|
||||
auto files = disks::ls();
|
||||
|
||||
for(auto& file : files){
|
||||
if(!file.directory && file.file_name == name){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void cat_command(const vector<string>& params){
|
||||
if(!disks::mounted_partition() || !disks::mounted_disk()){
|
||||
k_print_line("Nothing is mounted");
|
||||
@ -530,9 +559,13 @@ void cat_command(const vector<string>& params){
|
||||
if(params.size() == 1){
|
||||
k_print_line("No file provided");
|
||||
} else {
|
||||
auto content = disks::read_file(params[1]);
|
||||
|
||||
k_print(content);
|
||||
if(file_exists(params[1])){
|
||||
auto content = disks::read_file(params[1]);
|
||||
k_print(content);
|
||||
} else {
|
||||
k_print("cd: No such file or directory: ");
|
||||
k_print_line(params[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user