Skip to content

Commit

Permalink
make parsing sl status output more strict
Browse files Browse the repository at this point in the history
Summary: Make parsing more strict about format

Reviewed By: JakobDegen

Differential Revision: D68159083

fbshipit-source-id: a97f8ef180b32e13e0338a41aea0f7f465108ec0
  • Loading branch information
Yury Samkevich authored and facebook-github-bot committed Jan 14, 2025
1 parent c9b5d81 commit 1fd6704
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions app/buck2_file_watcher/src/edenfs/sapling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,14 @@ pub(crate) async fn get_status<D: AsRef<Path>, F: AsRef<str>, S: AsRef<str>>(
// Paths can have spaces, but are not quoted.
fn process_one_status_line(line: &str) -> buck2_error::Result<Option<(SaplingStatus, String)>> {
// Must include a status and at least one char path.
if line.len() >= 3 {
let mut chars = line.chars();
let change = chars.next().unwrap();
let path = chars.skip(1).collect::<String>();
let mut parts = line.split_whitespace();
if let (Some(change), Some(path), None) = (parts.next(), parts.next(), parts.next()) {
Ok(match change {
'M' => Some((SaplingStatus::Modified, path)),
'A' => Some((SaplingStatus::Added, path)),
'R' => Some((SaplingStatus::Removed, path)),
'!' => Some((SaplingStatus::Missing, path)),
'?' => Some((SaplingStatus::NotTracked, path)),
"M" => Some((SaplingStatus::Modified, path.to_owned())),
"A" => Some((SaplingStatus::Added, path.to_owned())),
"R" => Some((SaplingStatus::Removed, path.to_owned())),
"!" => Some((SaplingStatus::Missing, path.to_owned())),
"?" => Some((SaplingStatus::NotTracked, path.to_owned())),
_ => None, // Skip all others
})
} else {
Expand Down Expand Up @@ -206,6 +204,11 @@ mod tests {

assert!(process_one_status_line("NO").is_err());

assert!(
process_one_status_line("M:buck2/app/buck2_file_watcher/src/edenfs/sapling.rs")
.is_err()
);

Ok(())
}
}

0 comments on commit 1fd6704

Please sign in to comment.