Fixed crashes on some permissions issues
This commit is contained in:
@ -30,7 +30,7 @@ impl Search {
|
|||||||
///Returns a Search instance, taking the command line input.
|
///Returns a Search instance, taking the command line input.
|
||||||
pub fn build(input: &String) -> std::io::Result<Search> {
|
pub fn build(input: &String) -> std::io::Result<Search> {
|
||||||
|
|
||||||
let search_type = Self::discriminate_search_type(input);
|
let search_type = Self::discriminate_search_type(&input);
|
||||||
|
|
||||||
//Getting cmd and searched string
|
//Getting cmd and searched string
|
||||||
let mut words = input.split(' ').collect::<Vec<&str>>();
|
let mut words = input.split(' ').collect::<Vec<&str>>();
|
||||||
@ -92,23 +92,8 @@ impl Search {
|
|||||||
Ok(t) => t,
|
Ok(t) => t,
|
||||||
Err(_) => (String::new(), String::new()),
|
Err(_) => (String::new(), String::new()),
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
match &self.search_type {
|
return (res, res_lines);
|
||||||
SearchType::FileSearch => {
|
|
||||||
let xxx = &self.search_path.clone().into_os_string().into_string().unwrap();
|
|
||||||
if !&self.local_search && !res.contains(&xxx.as_str()) {
|
|
||||||
let return_val = format!("{} {}{}", &self.command, &self.search_path.display(), res);
|
|
||||||
return(return_val, res_lines);
|
|
||||||
} else {
|
|
||||||
let return_val = format!("{} {}", &self.command, res);
|
|
||||||
return(return_val, res_lines);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
SearchType::CmdSearch => {
|
|
||||||
return (res, res_lines);
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn discriminate_search_type(input: &String) -> SearchType {
|
fn discriminate_search_type(input: &String) -> SearchType {
|
||||||
@ -163,25 +148,37 @@ fn autocomplete_file(search: &Search) -> std::io::Result<(String, String)> {
|
|||||||
|
|
||||||
//if what we found is a folder, we add an / after
|
//if what we found is a folder, we add an / after
|
||||||
let fullpath = format!("{}/{}", &search.search_path.display(), filename);
|
let fullpath = format!("{}/{}", &search.search_path.display(), filename);
|
||||||
let md = fs::metadata(fullpath).unwrap();
|
|
||||||
//Will be added to the end of the result
|
|
||||||
let mut ending = String::new();
|
let mut ending = String::new();
|
||||||
if md.is_dir() {
|
match fs::metadata(fullpath) {
|
||||||
*&mut ending.push_str("/");
|
Ok(e) => {
|
||||||
}
|
//Will be added to the end of the result
|
||||||
|
if e.is_dir() {
|
||||||
|
*&mut ending.push_str("/");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(_) => (),
|
||||||
|
};
|
||||||
*&mut last_found = format!("{}{}", filename, ending);
|
*&mut last_found = format!("{}{}", filename, ending);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Found one or zero, use what has been found directly
|
|
||||||
if nbr_found < 2 {
|
//Handle returning the longest sequence of characters between two or more matching files
|
||||||
|
if nbr_found > 1 {
|
||||||
return Ok((last_found, String::new()));
|
|
||||||
//Otherwise, just display a list and use what all the results have in common
|
|
||||||
} else {
|
|
||||||
let longest = find_common_chars(results);
|
let longest = find_common_chars(results);
|
||||||
return Ok((longest, all_res));
|
*&mut last_found = longest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Handle the path when tabbing in a long path, zsh-like
|
||||||
|
//then return the value
|
||||||
|
let xxx = &search.search_path.clone().into_os_string().into_string().unwrap();
|
||||||
|
if !&search.local_search && !&last_found.contains(&xxx.as_str()) {
|
||||||
|
let return_val = format!("{} {}{}", &search.command, &search.search_path.display(), last_found);
|
||||||
|
return Ok((return_val, all_res));
|
||||||
|
} else {
|
||||||
|
let return_val = format!("{} {}", &search.command, last_found);
|
||||||
|
return Ok((return_val, all_res));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user