node: Add track/untrack support

Signed-off-by: Slack Coder <slackcoder@server.ky>
This commit is contained in:
Slack Coder
2022-09-13 10:16:05 +02:00
committed by Alexis Sellier
parent 8fbcb51963
commit d273cd0247
5 changed files with 117 additions and 7 deletions
+28
View File
@@ -60,8 +60,36 @@ enum DrainError {
fn drain<H: Handle>(stream: &UnixStream, handle: &H) -> Result<(), DrainError> {
let mut reader = BufReader::new(stream);
// TODO: refactor to include helper
for line in reader.by_ref().lines().flatten() {
match line.split_once(' ') {
Some(("fetch", arg)) => {
if let Ok(id) = arg.parse() {
if let Err(e) = handle.fetch(id) {
return Err(DrainError::Client(e));
}
} else {
return Err(DrainError::InvalidCommandArg(arg.to_owned()));
}
}
Some(("track", arg)) => {
if let Ok(id) = arg.parse() {
if let Err(e) = handle.track(id) {
return Err(DrainError::Client(e));
}
} else {
return Err(DrainError::InvalidCommandArg(arg.to_owned()));
}
}
Some(("untrack", arg)) => {
if let Ok(id) = arg.parse() {
if let Err(e) = handle.untrack(id) {
return Err(DrainError::Client(e));
}
} else {
return Err(DrainError::InvalidCommandArg(arg.to_owned()));
}
}
Some(("update", arg)) => {
if let Ok(id) = arg.parse() {
if let Err(e) = handle.updated(id) {