Skip to content

Commit 54c44b9

Browse files
chore: cleanup manifest target saving logic
Signed-off-by: Andrew Lilley Brinker <alilleybrinker@gmail.com>
1 parent 9f4d427 commit 54c44b9

File tree

5 files changed

+23
-13
lines changed

5 files changed

+23
-13
lines changed

omnibor-cli/src/cmd/store/add.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,26 @@ use omnibor::{hash_algorithm::Sha256, storage::Storage, InputManifest};
99
pub async fn run(app: &App, args: &StoreAddArgs) -> Result<()> {
1010
let mut storage = app.storage()?;
1111

12-
let manifest =
12+
let mut manifest =
1313
InputManifest::<Sha256>::from_path(&args.manifest).map_err(Error::UnableToReadManifest)?;
1414

15-
let manifest_aid = storage
15+
let target_aid = match &args.target {
16+
Some(targetable) => {
17+
let target_aid = targetable
18+
.clone()
19+
.into_artifact_id()
20+
.map_err(Error::IdFailed)?;
21+
22+
Some(target_aid)
23+
}
24+
None => None,
25+
};
26+
27+
manifest.set_target(target_aid);
28+
29+
storage
1630
.write_manifest(&manifest)
1731
.map_err(Error::FailedToAddManifest)?;
1832

19-
if let Some(target) = args.target.clone() {
20-
let target_aid = target.into_artifact_id().map_err(Error::IdFailed)?;
21-
storage
22-
.update_target_for_manifest(manifest_aid, target_aid)
23-
.map_err(Error::FailedToUpdateTarget)?;
24-
}
25-
2633
Ok(())
2734
}

omnibor-cli/src/error.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,6 @@ pub enum Error {
117117

118118
#[error("unable to read manifest")]
119119
UnableToReadManifest(#[source] InputManifestError),
120-
121-
#[error("failed to update target")]
122-
FailedToUpdateTarget(#[source] InputManifestError),
123120
}
124121

125122
pub type Result<T> = StdResult<T, Error>;

omnibor/src/input_manifest/input_manifest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl<H: HashAlgorithm> InputManifest<H> {
7272
}
7373

7474
/// Set a new target.
75-
pub(crate) fn set_target(&mut self, target: Option<ArtifactId<H>>) -> &mut Self {
75+
pub fn set_target(&mut self, target: Option<ArtifactId<H>>) -> &mut Self {
7676
self.target = target;
7777
self
7878
}

omnibor/src/storage/file_system_storage.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ impl<H: HashAlgorithm, P: HashProvider<H>> Storage<H> for FileSystemStorage<H, P
225225
InputManifestError::CantWriteManifest(path.clone_as_boxstr(), Box::new(source))
226226
})?;
227227

228+
if let Some(target_aid) = manifest.target() {
229+
self.update_target_for_manifest(manifest_aid, target_aid)?;
230+
}
231+
228232
Ok(manifest_aid)
229233
}
230234

omnibor/src/storage/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ pub trait Storage<H: HashAlgorithm> {
3535
) -> Result<Option<InputManifest<H>>, InputManifestError>;
3636

3737
/// Write a manifest to the storage.
38+
///
39+
/// If the manifest has a target attached, update any indices.
3840
fn write_manifest(
3941
&mut self,
4042
manifest: &InputManifest<H>,

0 commit comments

Comments
 (0)