Skip to content

Commit

Permalink
Rename BlobId fields in File/Directory for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
kylewlacy committed Jan 27, 2024
1 parent 5240090 commit 8c1e861
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 36 deletions.
6 changes: 3 additions & 3 deletions crates/brioche/benches/brioche_bench/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub async fn blob(brioche: &Brioche, content: impl AsRef<[u8]> + std::marker::Un

pub fn lazy_file(blob: BlobId, executable: bool) -> brioche::brioche::artifact::LazyArtifact {
brioche::brioche::artifact::LazyArtifact::File {
data: blob,
content_blob: blob,
executable,
resources: Box::new(WithMeta::without_meta(
brioche::brioche::artifact::LazyArtifact::Directory(Directory::default()),
Expand All @@ -56,7 +56,7 @@ pub fn lazy_file(blob: BlobId, executable: bool) -> brioche::brioche::artifact::

pub fn file(blob: BlobId, executable: bool) -> brioche::brioche::artifact::CompleteArtifact {
brioche::brioche::artifact::CompleteArtifact::File(File {
data: blob,
content_blob: blob,
executable,
resources: Directory::default(),
})
Expand All @@ -68,7 +68,7 @@ pub fn file_with_resources(
resources: brioche::brioche::artifact::Directory,
) -> brioche::brioche::artifact::CompleteArtifact {
brioche::brioche::artifact::CompleteArtifact::File(File {
data: blob,
content_blob: blob,
executable,
resources,
})
Expand Down
24 changes: 12 additions & 12 deletions crates/brioche/src/brioche/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use super::{
pub enum LazyArtifact {
#[serde(rename_all = "camelCase")]
File {
data: BlobId,
content_blob: BlobId,
executable: bool,
resources: Box<WithMeta<LazyArtifact>>,
},
Expand All @@ -54,7 +54,7 @@ pub enum LazyArtifact {
#[serde(rename_all = "camelCase")]
CreateFile {
#[serde_as(as = "UrlEncoded")]
data: BString,
content: BString,
executable: bool,
resources: Box<WithMeta<LazyArtifact>>,
},
Expand Down Expand Up @@ -334,7 +334,7 @@ impl CompleteArtifact {
#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct File {
pub data: BlobId,
pub content_blob: BlobId,
pub executable: bool,
pub resources: Directory,
}
Expand All @@ -343,7 +343,7 @@ pub struct File {
#[derive(Debug, Default, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Directory {
pub tree: Option<BlobId>,
pub listing_blob: Option<BlobId>,
}

impl Directory {
Expand All @@ -359,16 +359,16 @@ impl Directory {
);
listing.serialize(&mut serializer)?;

let tree_blob_id =
let listing_blob =
blob::save_blob(brioche, &listing_json, blob::SaveBlobOptions::default()).await?;

Ok(Self {
tree: Some(tree_blob_id),
listing_blob: Some(listing_blob),
})
}

pub async fn listing(&self, brioche: &Brioche) -> anyhow::Result<DirectoryListing> {
match self.tree {
match self.listing_blob {
Some(tree_blob_id) => {
let blob_path = blob::blob_path(brioche, tree_blob_id);
let listing_json = tokio::fs::read(&blob_path).await?;
Expand All @@ -380,7 +380,7 @@ impl Directory {
}

pub fn is_empty(&self) -> bool {
self.tree.is_none()
self.listing_blob.is_none()
}
}

Expand Down Expand Up @@ -576,7 +576,7 @@ impl TryFrom<LazyArtifact> for CompleteArtifact {
fn try_from(value: LazyArtifact) -> Result<Self, Self::Error> {
match value {
LazyArtifact::File {
data,
content_blob: data,
executable,
resources,
} => {
Expand All @@ -585,7 +585,7 @@ impl TryFrom<LazyArtifact> for CompleteArtifact {
return Err(ArtifactIncomplete);
};
Ok(CompleteArtifact::File(File {
data,
content_blob: data,
executable,
resources,
}))
Expand Down Expand Up @@ -616,11 +616,11 @@ impl From<CompleteArtifact> for LazyArtifact {
fn from(value: CompleteArtifact) -> Self {
match value {
CompleteArtifact::File(File {
data,
content_blob: data,
executable,
resources,
}) => Self::File {
data,
content_blob: data,
executable,
resources: Box::new(WithMeta::without_meta(LazyArtifact::Directory(resources))),
},
Expand Down
2 changes: 1 addition & 1 deletion crates/brioche/src/brioche/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ pub async fn create_input(

Ok(WithMeta::new(
CompleteArtifact::File(File {
data: blob_id,
content_blob: blob_id,
executable,
resources,
}),
Expand Down
4 changes: 2 additions & 2 deletions crates/brioche/src/brioche/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub async fn create_output<'a: 'async_recursion>(
) -> anyhow::Result<()> {
match artifact {
CompleteArtifact::File(File {
data,
content_blob,
executable,
resources,
}) => {
Expand All @@ -45,7 +45,7 @@ pub async fn create_output<'a: 'async_recursion>(
.await?;
}

let blob_path = super::blob::blob_path(brioche, *data);
let blob_path = super::blob::blob_path(brioche, *content_blob);
tokio::fs::copy(&blob_path, options.output_path)
.await
.with_context(|| {
Expand Down
10 changes: 5 additions & 5 deletions crates/brioche/src/brioche/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ async fn resolve_inner(
) -> anyhow::Result<CompleteArtifact> {
match artifact {
LazyArtifact::File {
data,
content_blob,
executable,
resources,
} => {
Expand All @@ -198,7 +198,7 @@ async fn resolve_inner(
anyhow::bail!("file resources resolved to non-directory value");
};
Ok(CompleteArtifact::File(File {
data,
content_blob,
executable,
resources,
}))
Expand Down Expand Up @@ -230,12 +230,12 @@ async fn resolve_inner(
Ok(result)
}
LazyArtifact::CreateFile {
data,
content,
executable,
resources,
} => {
let blob_id =
super::blob::save_blob(brioche, &data, super::blob::SaveBlobOptions::default())
super::blob::save_blob(brioche, &content, super::blob::SaveBlobOptions::default())
.await?;

let resources = resolve(brioche, *resources).await?;
Expand All @@ -244,7 +244,7 @@ async fn resolve_inner(
};

Ok(CompleteArtifact::File(File {
data: blob_id,
content_blob: blob_id,
executable,
resources,
}))
Expand Down
2 changes: 1 addition & 1 deletion crates/brioche/src/brioche/resolve/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub async fn resolve_download(
);

Ok(File {
data: blob_id,
content_blob: blob_id,
executable: false,
resources: Directory::default(),
})
Expand Down
8 changes: 6 additions & 2 deletions crates/brioche/src/brioche/resolve/unpack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ pub async fn resolve_unpack(
unpack: UnpackArtifact,
) -> anyhow::Result<Directory> {
let file = super::resolve(brioche, *unpack.file).await?;
let CompleteArtifact::File(File { data: blob_id, .. }) = file.value else {
let CompleteArtifact::File(File {
content_blob: blob_id,
..
}) = file.value
else {
anyhow::bail!("expected archive to be a file");
};

Expand Down Expand Up @@ -62,7 +66,7 @@ pub async fn resolve_unpack(
let executable = entry_mode & 0o100 != 0;

CompleteArtifact::File(File {
data: entry_blob_id,
content_blob: entry_blob_id,
executable,
resources: Directory::default(),
})
Expand Down
12 changes: 6 additions & 6 deletions crates/brioche/tests/artifact_hash_stable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async fn test_artifact_hash_stable_file() -> anyhow::Result<()> {
)
.hash()
.to_string(),
"4ffde3f046dfb46f4d7e7c794799dfe81b452683fd90bc18659dccd792c4a400",
"47bb5f180d0206135e843e3aa81f12106124851e8f48f0143e7d6a35053c6f6e",
));
asserts.push((
brioche_test::lazy_file_with_resources(
Expand All @@ -79,7 +79,7 @@ async fn test_artifact_hash_stable_file() -> anyhow::Result<()> {
)
.hash()
.to_string(),
"551c9204afe0b6fe0438b84b889df3c76d19368e2c3ed0a4c13ebde8fadf6dfe",
"3ded790822fdddc49a48fef5ec466d4cfa5b36629799e732be561dad7cad1cef",
));

let left: Vec<_> = asserts.iter().map(|(left, _)| left).collect();
Expand Down Expand Up @@ -118,7 +118,7 @@ async fn test_artifact_hash_stable_directory() -> anyhow::Result<()> {
.await
.hash()
.to_string(),
"e741c7f33e7845f3f659c0484bb889645daf338677d2a3209a472e4406eae404",
"773e23ae9256d18dbea707c79f6d2d2c018b910a992b6c75e71ef26dd7a32233",
));
asserts.push((
LazyArtifact::from(
Expand All @@ -130,7 +130,7 @@ async fn test_artifact_hash_stable_directory() -> anyhow::Result<()> {
)
.hash()
.to_string(),
"e741c7f33e7845f3f659c0484bb889645daf338677d2a3209a472e4406eae404",
"773e23ae9256d18dbea707c79f6d2d2c018b910a992b6c75e71ef26dd7a32233",
));

asserts.push((
Expand All @@ -148,7 +148,7 @@ async fn test_artifact_hash_stable_directory() -> anyhow::Result<()> {
.await
.hash()
.to_string(),
"02360a3026e4c5623a29b0437b5f7ca21fc23810befdc20c3ce5915dce96ba17",
"04155278894583935b64b9fe655e6d865ac3aff93fa790bcff4bbe9710ebe08b",
));
asserts.push((
LazyArtifact::from(
Expand All @@ -170,7 +170,7 @@ async fn test_artifact_hash_stable_directory() -> anyhow::Result<()> {
)
.hash()
.to_string(),
"02360a3026e4c5623a29b0437b5f7ca21fc23810befdc20c3ce5915dce96ba17",
"04155278894583935b64b9fe655e6d865ac3aff93fa790bcff4bbe9710ebe08b",
));

asserts.push((
Expand Down
8 changes: 4 additions & 4 deletions crates/brioche/tests/brioche_test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub async fn blob(brioche: &Brioche, content: impl AsRef<[u8]> + std::marker::Un

pub fn lazy_file(blob: BlobId, executable: bool) -> brioche::brioche::artifact::LazyArtifact {
brioche::brioche::artifact::LazyArtifact::File {
data: blob,
content_blob: blob,
executable,
resources: Box::new(WithMeta::without_meta(
brioche::brioche::artifact::LazyArtifact::Directory(Directory::default()),
Expand All @@ -72,15 +72,15 @@ pub fn lazy_file_with_resources(
resources: brioche::brioche::artifact::LazyArtifact,
) -> brioche::brioche::artifact::LazyArtifact {
brioche::brioche::artifact::LazyArtifact::File {
data: blob,
content_blob: blob,
executable,
resources: Box::new(WithMeta::without_meta(resources)),
}
}

pub fn file(blob: BlobId, executable: bool) -> brioche::brioche::artifact::CompleteArtifact {
brioche::brioche::artifact::CompleteArtifact::File(File {
data: blob,
content_blob: blob,
executable,
resources: Directory::default(),
})
Expand All @@ -92,7 +92,7 @@ pub fn file_with_resources(
resources: brioche::brioche::artifact::Directory,
) -> brioche::brioche::artifact::CompleteArtifact {
brioche::brioche::artifact::CompleteArtifact::File(File {
data: blob,
content_blob: blob,
executable,
resources,
})
Expand Down

0 comments on commit 8c1e861

Please sign in to comment.