diff options
author | Florian Klink <flokli@flokli.de> | 2024-08-17T14·40+0300 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2024-08-18T16·49+0000 |
commit | 96832c04116fb5a3be2d314659e701a3669ec65d (patch) | |
tree | fca0c6fae125dabba212be6b8ebb2de10224c223 /tvix/castore/src/fixtures.rs | |
parent | 76839683a7ab0453afcdc3374a5cc80cca2f9510 (diff) |
feat(tvix/castore): add Directory::try_from_iter() r/8511
This provides a batched variant to construct a Directory, which reuses the previously calculated size. Checking and inserting code is factored out into a check_insert_node function, taking the current size as a parameter and returning the new size. Change-Id: Ia6c2970a0c12181b7c40e63cf7ce8c93298ea37c Reviewed-on: https://cl.tvl.fyi/c/depot/+/12225 Autosubmit: flokli <flokli@flokli.de> Reviewed-by: edef <edef@edef.eu> Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/castore/src/fixtures.rs')
-rw-r--r-- | tvix/castore/src/fixtures.rs | 85 |
1 files changed, 37 insertions, 48 deletions
diff --git a/tvix/castore/src/fixtures.rs b/tvix/castore/src/fixtures.rs index 00cf3682d194..05bad916d55f 100644 --- a/tvix/castore/src/fixtures.rs +++ b/tvix/castore/src/fixtures.rs @@ -31,85 +31,74 @@ lazy_static! { pub static ref BLOB_B_DIGEST: B3Digest = blake3::hash(&BLOB_B).as_bytes().into(); // Directories - pub static ref DIRECTORY_WITH_KEEP: Directory = { - let mut dir = Directory::new(); - dir.add( - ".keep".try_into().unwrap(), - Node::File{ - digest: EMPTY_BLOB_DIGEST.clone(), - size: 0, - executable: false - }).unwrap(); - - dir - }; - pub static ref DIRECTORY_COMPLICATED: Directory = { - let mut dir = Directory::new(); - dir.add( + pub static ref DIRECTORY_WITH_KEEP: Directory = Directory::try_from_iter([( + ".keep".try_into().unwrap(), + Node::File{ + digest: EMPTY_BLOB_DIGEST.clone(), + size: 0, + executable: false + })]).unwrap(); + pub static ref DIRECTORY_COMPLICATED: Directory = Directory::try_from_iter([ + ( "keep".try_into().unwrap(), Node::Directory{ digest: DIRECTORY_WITH_KEEP.digest(), size: DIRECTORY_WITH_KEEP.size() - }).unwrap(); - dir.add( + } + ), + ( ".keep".try_into().unwrap(), Node::File{ digest: EMPTY_BLOB_DIGEST.clone(), size: 0, executable: false - }).unwrap(); - dir.add( + } + ), + ( "aa".try_into().unwrap(), Node::Symlink{ target: "/nix/store/somewhereelse".try_into().unwrap() - }).unwrap(); - - dir - }; + } + ) + ]).unwrap(); pub static ref DIRECTORY_A: Directory = Directory::new(); - pub static ref DIRECTORY_B: Directory = { - let mut dir = Directory::new(); - dir.add( + pub static ref DIRECTORY_B: Directory = Directory::try_from_iter([( "a".try_into().unwrap(), Node::Directory{ digest: DIRECTORY_A.digest(), size: DIRECTORY_A.size(), - }).unwrap(); - - dir - }; - pub static ref DIRECTORY_C: Directory = { - let mut dir = Directory::new(); - dir.add( + } + )]).unwrap(); + pub static ref DIRECTORY_C: Directory = Directory::try_from_iter([ + ( "a".try_into().unwrap(), Node::Directory{ digest: DIRECTORY_A.digest(), size: DIRECTORY_A.size(), - }).unwrap(); - dir.add( + } + ), + ( "a'".try_into().unwrap(), Node::Directory{ digest: DIRECTORY_A.digest(), size: DIRECTORY_A.size(), - }).unwrap(); - - dir - }; - pub static ref DIRECTORY_D: Directory = { - let mut dir = Directory::new(); - dir.add( + } + ) + ]).unwrap(); + pub static ref DIRECTORY_D: Directory = Directory::try_from_iter([ + ( "a".try_into().unwrap(), Node::Directory{ digest: DIRECTORY_A.digest(), size: DIRECTORY_A.size(), - }).unwrap(); - dir.add( + } + ), + ( "b".try_into().unwrap(), Node::Directory{ digest: DIRECTORY_B.digest(), size: DIRECTORY_B.size(), - }).unwrap(); - - dir - }; + } + ) + ]).unwrap(); } |