Skip to content

Commit

Permalink
Further improve the rsync error logging code.
Browse files Browse the repository at this point in the history
  • Loading branch information
partim committed Jan 15, 2024
1 parent 30e27ce commit 5ebc744
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions src/collector/rsync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,20 +549,7 @@ impl RsyncCommand {
if let Some(mut pipe) = stderr_pipe {
let mut line = Vec::new();
while pipe.read_until(b'\n', &mut line).await? != 0 {
// Drop the delimiter if there is one, don’t
// log an empty line.
let len = line.len();
if len > 0 && line[len - 1] == b'\n' {
let _ = line.pop();
}
if line.is_empty() {
continue
}
warn!(
"{}: {}",
source,
String::from_utf8_lossy(&line)
);
Self::log_err_line(source, &mut line);
}
}
Ok(())
Expand Down Expand Up @@ -700,6 +687,33 @@ impl RsyncCommand {
}
Ok(destination)
}

/// Logs the line in the buffer.
fn log_err_line(
source: &Module,
line: &mut Vec<u8>,
) {
let mut len = line.len();
if len > 0 && line[len - 1] == b'\n' {
len -= 1;
}

// On Windows, we may now have a \r at the end.
#[cfg(windows)]
if len > 0 && line[len - 1] == b'\r' {
len -= 1;
}

if len > 0 {
warn!(
"{}: {}",
source,
String::from_utf8_lossy(&line[..len])
);
}

line.clear();
}
}


Expand Down

0 comments on commit 5ebc744

Please sign in to comment.