Skip to content

Commit

Permalink
narlist: don't serialize "executable" if false
Browse files Browse the repository at this point in the history
this brings our nar listing closer to nix
  • Loading branch information
Mic92 committed Nov 3, 2024
1 parent cdd6127 commit 5f5d72b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions harmonia/src/narlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use std::collections::HashMap;
use std::path::PathBuf;
use tokio::fs::symlink_metadata;

fn is_false(b: &bool) -> bool { !b }

#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)]
#[serde(tag = "type")]
enum NarEntry {
Expand All @@ -24,7 +26,8 @@ enum NarEntry {
#[serde(rename = "narOffset")]
nar_offset: Option<u64>,
size: u64,
#[serde(default)]

#[serde(default, skip_serializing_if = "is_false")]
executable: bool,
},
#[serde(rename = "symlink")]
Expand Down Expand Up @@ -236,17 +239,17 @@ mod test {
.unwrap();
let parsed_json: serde_json::Value = serde_json::from_slice(&res2.stdout).unwrap();
let pretty_string = serde_json::to_string_pretty(&parsed_json).unwrap();
println!("{}", pretty_string);
assert!(res2.status.success());
let mut reference_json: NarEntry = serde_json::from_str(&pretty_string).unwrap();


// our posix implementation does not support narOffset
unset_nar_offset(&mut reference_json);

println!("get_nar_list:");
println!("{:?}", json.root);
println!("{}", serde_json::to_string_pretty(&json.root).unwrap());
println!("nix nar ls --json --recursive:");
println!("{:?}", reference_json);
println!("{}", pretty_string);
assert_eq!(json.root, reference_json);

Ok(())
Expand Down

0 comments on commit 5f5d72b

Please sign in to comment.