Skip to content

Commit 03e139c

Browse files
committed
Actually stop writing blob files
The previous commit that removed `write_blob` didn't actually accomplish much because blobs were mostly being written with `write_object`. There is now a debug assertion in `write_object` to prevent writing blobs. Once this was in place, the tests starting revealing all the places that were still writing blobs, and then all the places that didn't work anymore when blobs don't exist. This commit redefines some terminology used in the API. Previously an "object" could include blob objects and their digests could be used interchangeably with payload digests. Now payloads are not considered to be an "object" and methods that operate on object digests do not work for payloads. Some method names have been changed to make this more apparent. The term "item" is used for things (digests) that can be either an object of a payload. A "ref" can be a digest and it is expected that it is still possible to interact with payloads via a ref. A tag can refer to a payload as well. The 'find_digests' operation used to return digests for blob objects so absent blobs it has been changed to return both object digests and payload digests. Signed-off-by: J Robert Ray <[email protected]>
1 parent 259efeb commit 03e139c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+877
-614
lines changed

crates/spfs-cli/main/src/cmd_check.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,29 +90,29 @@ impl CmdCheck {
9090
drop(checker); // clean up progress bars
9191
let spfs::check::CheckSummary {
9292
missing_tags,
93-
checked_tags,
93+
valid_tags,
9494
missing_objects,
9595
repaired_objects,
96-
checked_objects,
96+
valid_objects,
9797
missing_payloads,
9898
repaired_payloads,
99-
checked_payloads,
100-
checked_payload_bytes,
99+
valid_payloads,
100+
valid_payload_bytes,
101101
} = summary;
102102
let missing_objects = missing_objects.len();
103103
let missing_payloads = missing_payloads.len();
104104

105105
println!("{} after {duration:.0?}:", "Finished".bold());
106106
let missing = "missing".red().italic();
107107
let repaired = "repaired".cyan().italic();
108-
println!("{checked_tags:>12} tags visited ({missing_tags} {missing})");
108+
println!("{valid_tags:>12} tags visited ({missing_tags} {missing})");
109109
println!(
110-
"{checked_objects:>12} objects visited ({missing_objects} {missing}, {repaired_objects} {repaired})",
110+
"{valid_objects:>12} objects visited ({missing_objects} {missing}, {repaired_objects} {repaired})",
111111
);
112112
println!(
113-
"{checked_payloads:>12} payloads visited ({missing_payloads} {missing}, {repaired_payloads} {repaired})",
113+
"{valid_payloads:>12} payloads visited ({missing_payloads} {missing}, {repaired_payloads} {repaired})",
114114
);
115-
let human_bytes = match NumberPrefix::binary(checked_payload_bytes as f64) {
115+
let human_bytes = match NumberPrefix::binary(valid_payload_bytes as f64) {
116116
NumberPrefix::Standalone(amt) => format!("{amt} bytes"),
117117
NumberPrefix::Prefixed(p, amt) => format!("{amt:.2} {}B", p.symbol()),
118118
};

crates/spfs-cli/main/src/cmd_info.rs

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ use spfs::find_path::ObjectPathEntry;
1313
use spfs::graph::Annotation;
1414
use spfs::io::{self, DigestFormat, Pluralize};
1515
use spfs::prelude::*;
16-
use spfs::{self};
16+
use spfs::{
17+
Error,
18+
{self},
19+
};
1720
use spfs_cli_common as cli;
1821

1922
#[cfg(test)]
@@ -73,9 +76,21 @@ impl CmdInfo {
7376
self.pretty_print_file(&reference, &repo, self.logging.verbose as usize)
7477
.await?;
7578
} else {
76-
let item = repo.read_ref(reference.as_str()).await?;
77-
self.pretty_print_ref(item, &repo, self.logging.verbose as usize)
78-
.await?;
79+
match repo.read_ref(reference.as_str()).await {
80+
Ok(item) => {
81+
self.pretty_print_ref(item, &repo, self.logging.verbose as usize)
82+
.await?;
83+
}
84+
Err(Error::UnknownObject(_)) => {
85+
let digest = repo.resolve_ref(reference.as_str()).await?;
86+
let payload_size = repo.payload_size(digest).await?;
87+
self.pretty_print_payload(digest, payload_size, &repo)
88+
.await?;
89+
}
90+
Err(err) => {
91+
return Err(err.into());
92+
}
93+
}
7994
}
8095
if !self.to_process.is_empty() {
8196
println!();
@@ -220,6 +235,31 @@ impl CmdInfo {
220235
Ok(())
221236
}
222237

238+
/// Display the spfs payload information
239+
async fn pretty_print_payload(
240+
&mut self,
241+
digest: spfs::encoding::Digest,
242+
payload_size: u64,
243+
repo: &spfs::storage::RepositoryHandle,
244+
) -> Result<()> {
245+
println!(
246+
"{}:\n {}:",
247+
self.format_digest(digest, repo).await?,
248+
"blob".green()
249+
);
250+
println!(
251+
" {} {}",
252+
"digest:".bright_blue(),
253+
self.format_digest(digest, repo).await?
254+
);
255+
println!(
256+
" {} {}",
257+
"size:".bright_blue(),
258+
spfs::io::format_size(payload_size)
259+
);
260+
Ok(())
261+
}
262+
223263
/// Display the status of the current runtime.
224264
async fn print_global_info(&self, repo: &spfs::storage::RepositoryHandle) -> Result<()> {
225265
let runtime = spfs::active_runtime().await?;

crates/spfs-cli/main/src/cmd_pull.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use clap::Args;
66
use miette::Result;
7+
use spfs::sync::reporter::Summary;
78
use spfs_cli_common as cli;
89

910
/// Pull one or more objects to the local repository

crates/spfs-cli/main/src/cmd_push.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use clap::Args;
66
use miette::Result;
7+
use spfs::sync::reporter::Summary;
78
use spfs_cli_common as cli;
89

910
/// Push one or more objects to a remote repository

crates/spfs-cli/main/src/cmd_read.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,27 @@ pub struct CmdRead {
3030

3131
impl CmdRead {
3232
pub async fn run(&mut self, config: &spfs::Config) -> Result<i32> {
33+
use spfs::graph::object::Enum;
34+
3335
let repo =
3436
spfs::config::open_repository_from_string(config, self.repos.remote.as_ref()).await?;
3537

3638
#[cfg(feature = "sentry")]
3739
tracing::info!(target: "sentry", "using repo: {}", repo.address());
3840

39-
let item = repo.read_ref(&self.reference.to_string()).await?;
40-
use spfs::graph::object::Enum;
41-
let digest = match item.to_enum() {
42-
Enum::Blob(blob) => *blob.digest(),
43-
_ => {
41+
let digest = match repo.read_ref(&self.reference.to_string()).await.map(|fb| {
42+
let fb_enum = fb.to_enum();
43+
(fb, fb_enum)
44+
}) {
45+
Ok((_, Enum::Blob(blob))) => *blob.digest(),
46+
Ok((obj, _)) => {
4447
let path = match &self.path {
4548
None => {
46-
miette::bail!("PATH must be given to read from {:?}", item.kind());
49+
miette::bail!("PATH must be given to read from {:?}", obj.kind());
4750
}
4851
Some(p) => p.strip_prefix("/spfs").unwrap_or(p).to_string(),
4952
};
50-
let manifest = spfs::compute_object_manifest(item, &repo).await?;
53+
let manifest = spfs::compute_object_manifest(obj, &repo).await?;
5154
let entry = match manifest.get_path(&path) {
5255
Some(e) => e,
5356
None => {
@@ -61,6 +64,10 @@ impl CmdRead {
6164
}
6265
entry.object
6366
}
67+
Err(Error::UnknownObject(digest)) => digest,
68+
Err(err) => {
69+
return Err(err.into());
70+
}
6471
};
6572

6673
let (mut payload, filename) = repo.open_payload(digest).await?;

crates/spfs-encoding/src/hash.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,10 @@ impl Decodable for String {
259259
}
260260
}
261261

262-
/// The first N bytes of a digest that may still be unambiguous as a reference
262+
/// The first N bytes of a digest that may still be unambiguous as a reference.
263+
///
264+
/// This type can represent a full digest, but it does not require that an item
265+
/// exists with that digest or what type of item it is.
263266
#[derive(Deserialize, Debug, Hash, Eq, PartialEq, Ord, PartialOrd, Clone)]
264267
pub struct PartialDigest(Vec<u8>);
265268

0 commit comments

Comments
 (0)