Skip to content

Commit

Permalink
Replace remove lazy artifact with insert
Browse files Browse the repository at this point in the history
  • Loading branch information
kylewlacy committed Jan 20, 2024
1 parent 54de81f commit 9f098b1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
9 changes: 5 additions & 4 deletions crates/brioche/src/brioche/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ pub enum LazyArtifact {
path: BString,
},
#[serde(rename_all = "camelCase")]
Remove {
Insert {
directory: Box<WithMeta<LazyArtifact>>,
#[serde_as(as = "Vec<UrlEncoded>")]
paths: Vec<BString>,
#[serde_as(as = "UrlEncoded")]
path: BString,
artifact: Option<Box<WithMeta<LazyArtifact>>>,
},
#[serde(rename_all = "camelCase")]
SetPermissions {
Expand Down Expand Up @@ -528,7 +529,7 @@ impl TryFrom<LazyArtifact> for CompleteArtifact {
| LazyArtifact::Merge { .. }
| LazyArtifact::Peel { .. }
| LazyArtifact::Get { .. }
| LazyArtifact::Remove { .. }
| LazyArtifact::Insert { .. }
| LazyArtifact::SetPermissions { .. }
| LazyArtifact::Proxy { .. } => Err(ArtifactIncomplete),
}
Expand Down
26 changes: 21 additions & 5 deletions crates/brioche/src/brioche/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,14 +336,30 @@ async fn resolve_inner(

Ok(result.value)
}
LazyArtifact::Remove { directory, paths } => {
let result = resolve(brioche, *directory).await?;
let CompleteArtifact::Directory(mut directory) = result.value else {
LazyArtifact::Insert {
directory,
path,
artifact,
} => {
let (directory, artifact) =
tokio::try_join!(resolve(brioche, *directory), async move {
match artifact {
Some(artifact) => Ok(Some(resolve(brioche, *artifact).await?)),
None => Ok(None),
}
})?;

let CompleteArtifact::Directory(mut directory) = directory.value else {
anyhow::bail!("tried removing item from non-directory artifact");
};

for path in paths {
directory.remove(&path)?;
match artifact {
Some(artifact) => {
directory.insert(&path, artifact)?;
}
None => {
directory.remove(&path)?;
}
}

Ok(CompleteArtifact::Directory(directory))
Expand Down

0 comments on commit 9f098b1

Please sign in to comment.