mirror of
https://codeberg.org/YGGverse/psocks.git
synced 2026-03-31 16:35:28 +00:00
implement cache/clean api
This commit is contained in:
parent
0603fdf4a6
commit
461f838cc0
4 changed files with 35 additions and 3 deletions
|
|
@ -49,6 +49,22 @@ impl Cache {
|
|||
}
|
||||
Ok(())
|
||||
}
|
||||
/// Clean `--cache` file collected, return deleted rules
|
||||
pub async fn clean(&self) -> Result<Option<Vec<String>>> {
|
||||
match self.0 {
|
||||
Some(ref p) => {
|
||||
init_file(p).await?;
|
||||
let mut rules = Vec::new();
|
||||
let lines = fs::read_to_string(p).await?;
|
||||
for line in lines.lines() {
|
||||
rules.push(line.into());
|
||||
}
|
||||
fs::write(p, "").await?;
|
||||
Ok(Some(rules))
|
||||
}
|
||||
None => Ok(None),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Make sure that cache file is always exist (e.g. user may remove it when the daemon is running)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue