add get nth line function
This commit is contained in:
parent
932fb2827d
commit
d81bac5146
@ -92,16 +92,16 @@ impl UserDBWrite for UserDBLocal {
|
|||||||
|
|
||||||
fn new_user(
|
fn new_user(
|
||||||
&mut self, /*
|
&mut self, /*
|
||||||
username: String,
|
username: String,
|
||||||
enc_password: String,
|
enc_password: String,
|
||||||
uid: u32,
|
uid: u32,
|
||||||
gid: u32,
|
gid: u32,
|
||||||
full_name: String,
|
full_name: String,
|
||||||
room: String,
|
room: String,
|
||||||
phone_work: String,
|
phone_work: String,
|
||||||
phone_home: String,
|
phone_home: String,
|
||||||
other: Option<Vec<String>>,
|
other: Option<Vec<String>>,
|
||||||
home_dir: String,
|
home_dir: String,
|
||||||
shell_path: String,*/
|
shell_path: String,*/
|
||||||
) -> Result<&crate::User, crate::UserLibError> {
|
) -> Result<&crate::User, crate::UserLibError> {
|
||||||
/*if self.users.contains_key(&username) {
|
/*if self.users.contains_key(&username) {
|
||||||
@ -216,6 +216,15 @@ impl UserDBValidation for UserDBLocal {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_nth_line(path: Option<&PathBuf>, n: u32) -> String {
|
||||||
|
let lines = file_to_string(path);
|
||||||
|
let line = lines.lines().nth(n as usize);
|
||||||
|
match line {
|
||||||
|
Some(line) => line.to_owned(),
|
||||||
|
None => "".to_owned(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Parse a file to a string
|
/// Parse a file to a string
|
||||||
fn file_to_string(path: Option<&PathBuf>) -> String {
|
fn file_to_string(path: Option<&PathBuf>) -> String {
|
||||||
let file = File::open(path.expect("Path cannot be None".into()))
|
let file = File::open(path.expect("Path cannot be None".into()))
|
||||||
|
Loading…
Reference in New Issue
Block a user