2024-08-16 01:24:12 +02:00
|
|
|
use crate::{B3Digest, Directory, Node};
|
2023-09-21 21:32:44 +02:00
|
|
|
use lazy_static::lazy_static;
|
|
|
|
|
|
|
|
pub const HELLOWORLD_BLOB_CONTENTS: &[u8] = b"Hello World!";
|
|
|
|
pub const EMPTY_BLOB_CONTENTS: &[u8] = b"";
|
|
|
|
|
|
|
|
lazy_static! {
|
|
|
|
pub static ref DUMMY_DIGEST: B3Digest = {
|
2023-10-27 03:12:26 +02:00
|
|
|
let u = [0u8; 32];
|
|
|
|
(&u).into()
|
2023-09-21 21:32:44 +02:00
|
|
|
};
|
|
|
|
pub static ref DUMMY_DIGEST_2: B3Digest = {
|
2023-10-27 03:12:26 +02:00
|
|
|
let mut u = [0u8; 32];
|
|
|
|
u[0] = 0x10;
|
|
|
|
(&u).into()
|
2023-09-21 21:32:44 +02:00
|
|
|
};
|
|
|
|
pub static ref DUMMY_DATA_1: bytes::Bytes = vec![0x01, 0x02, 0x03].into();
|
|
|
|
pub static ref DUMMY_DATA_2: bytes::Bytes = vec![0x04, 0x05].into();
|
|
|
|
|
|
|
|
pub static ref HELLOWORLD_BLOB_DIGEST: B3Digest =
|
|
|
|
blake3::hash(HELLOWORLD_BLOB_CONTENTS).as_bytes().into();
|
|
|
|
pub static ref EMPTY_BLOB_DIGEST: B3Digest =
|
|
|
|
blake3::hash(EMPTY_BLOB_CONTENTS).as_bytes().into();
|
|
|
|
|
|
|
|
// 2 bytes
|
|
|
|
pub static ref BLOB_A: bytes::Bytes = vec![0x00, 0x01].into();
|
|
|
|
pub static ref BLOB_A_DIGEST: B3Digest = blake3::hash(&BLOB_A).as_bytes().into();
|
|
|
|
|
|
|
|
// 1MB
|
|
|
|
pub static ref BLOB_B: bytes::Bytes = (0..255).collect::<Vec<u8>>().repeat(4 * 1024).into();
|
|
|
|
pub static ref BLOB_B_DIGEST: B3Digest = blake3::hash(&BLOB_B).as_bytes().into();
|
|
|
|
|
|
|
|
// Directories
|
2024-08-17 16:40:01 +02:00
|
|
|
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([
|
|
|
|
(
|
2024-08-16 16:32:20 +02:00
|
|
|
"keep".try_into().unwrap(),
|
2024-08-16 01:24:12 +02:00
|
|
|
Node::Directory{
|
|
|
|
digest: DIRECTORY_WITH_KEEP.digest(),
|
|
|
|
size: DIRECTORY_WITH_KEEP.size()
|
2024-08-17 16:40:01 +02:00
|
|
|
}
|
|
|
|
),
|
|
|
|
(
|
2024-08-16 16:32:20 +02:00
|
|
|
".keep".try_into().unwrap(),
|
2024-08-16 01:24:12 +02:00
|
|
|
Node::File{
|
|
|
|
digest: EMPTY_BLOB_DIGEST.clone(),
|
|
|
|
size: 0,
|
|
|
|
executable: false
|
2024-08-17 16:40:01 +02:00
|
|
|
}
|
|
|
|
),
|
|
|
|
(
|
2024-08-16 16:32:20 +02:00
|
|
|
"aa".try_into().unwrap(),
|
2024-08-16 01:24:12 +02:00
|
|
|
Node::Symlink{
|
|
|
|
target: "/nix/store/somewhereelse".try_into().unwrap()
|
2024-08-17 16:40:01 +02:00
|
|
|
}
|
|
|
|
)
|
|
|
|
]).unwrap();
|
refactor(tvix/castore): use Directory struct separate from proto one
This uses our own data type to deal with Directories in the castore model.
It makes some undesired states unrepresentable, removing the need for conversions and checking in various places:
- In the protobuf, blake3 digests could have a wrong length, as proto doesn't know fixed-size fields. We now use `B3Digest`, which makes cloning cheaper, and removes the need to do size-checking everywhere.
- In the protobuf, we had three different lists for `files`, `symlinks` and `directories`. This was mostly a protobuf size optimization, but made interacting with them a bit awkward. This has now been replaced with a list of enums, and convenience iterators to get various nodes, and add new ones.
Change-Id: I7b92691bb06d77ff3f58a5ccea94a22c16f84f04
Reviewed-on: https://cl.tvl.fyi/c/depot/+/12057
Tested-by: BuildkiteCI
Reviewed-by: flokli <flokli@flokli.de>
2024-07-29 14:34:50 +02:00
|
|
|
pub static ref DIRECTORY_A: Directory = Directory::new();
|
2024-08-17 16:40:01 +02:00
|
|
|
pub static ref DIRECTORY_B: Directory = Directory::try_from_iter([(
|
2024-08-16 16:32:20 +02:00
|
|
|
"a".try_into().unwrap(),
|
2024-08-16 01:24:12 +02:00
|
|
|
Node::Directory{
|
|
|
|
digest: DIRECTORY_A.digest(),
|
|
|
|
size: DIRECTORY_A.size(),
|
2024-08-17 16:40:01 +02:00
|
|
|
}
|
|
|
|
)]).unwrap();
|
|
|
|
pub static ref DIRECTORY_C: Directory = Directory::try_from_iter([
|
|
|
|
(
|
2024-08-16 16:32:20 +02:00
|
|
|
"a".try_into().unwrap(),
|
2024-08-16 01:24:12 +02:00
|
|
|
Node::Directory{
|
|
|
|
digest: DIRECTORY_A.digest(),
|
|
|
|
size: DIRECTORY_A.size(),
|
2024-08-17 16:40:01 +02:00
|
|
|
}
|
|
|
|
),
|
|
|
|
(
|
2024-08-16 16:32:20 +02:00
|
|
|
"a'".try_into().unwrap(),
|
2024-08-16 01:24:12 +02:00
|
|
|
Node::Directory{
|
|
|
|
digest: DIRECTORY_A.digest(),
|
|
|
|
size: DIRECTORY_A.size(),
|
2024-08-17 16:40:01 +02:00
|
|
|
}
|
|
|
|
)
|
|
|
|
]).unwrap();
|
|
|
|
pub static ref DIRECTORY_D: Directory = Directory::try_from_iter([
|
|
|
|
(
|
2024-08-16 16:32:20 +02:00
|
|
|
"a".try_into().unwrap(),
|
2024-08-16 01:24:12 +02:00
|
|
|
Node::Directory{
|
|
|
|
digest: DIRECTORY_A.digest(),
|
|
|
|
size: DIRECTORY_A.size(),
|
2024-08-17 16:40:01 +02:00
|
|
|
}
|
|
|
|
),
|
|
|
|
(
|
2024-08-16 16:32:20 +02:00
|
|
|
"b".try_into().unwrap(),
|
2024-08-16 01:24:12 +02:00
|
|
|
Node::Directory{
|
|
|
|
digest: DIRECTORY_B.digest(),
|
|
|
|
size: DIRECTORY_B.size(),
|
2024-08-17 16:40:01 +02:00
|
|
|
}
|
|
|
|
)
|
|
|
|
]).unwrap();
|
2023-09-21 21:32:44 +02:00
|
|
|
}
|