Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
4506480
fix(node): gate GET /ipfs/{cid} on reachable allowed-set, not deny-se…
Gravirei Jun 30, 2026
3aa7bf0
perf(ipfs): check object existence before allowed-blob walk
Gravirei Jun 30, 2026
63580c7
refactor(ipfs): improve formatting and readability in get_by_cid func…
Gravirei Jun 30, 2026
002f354
refactor(ipfs): streamline object retrieval by separating type and co…
Gravirei Jun 30, 2026
f2c91a8
docs(ipfs): update get_by_cid comment to reflect split object retrieval
Gravirei Jul 1, 2026
0b7c494
Merge remote-tracking branch 'upstream/main'
Gravirei Jul 1, 2026
03ba714
Run cargo fmt on store.rs
Gravirei Jul 1, 2026
03c90f8
Merge remote-tracking branch 'upstream/main'
Gravirei Jul 2, 2026
94bb216
Merge remote-tracking branch 'upstream/main'
Gravirei Jul 3, 2026
79650df
Merge remote-tracking branch 'upstream/main'
Gravirei Jul 5, 2026
26d8d48
Merge remote-tracking branch 'upstream/main'
Gravirei Jul 6, 2026
8c51c63
Merge remote-tracking branch 'upstream/main'
Gravirei Jul 7, 2026
69d64c5
Merge remote-tracking branch 'upstream/main'
Gravirei Jul 9, 2026
8d0f41c
test(gl): add tests for iCaptcha transparent retry flow (#167)
Gravirei Jul 9, 2026
cb8761d
fix(clippy): remove redundant borrow in format! arg
Gravirei Jul 9, 2026
d98e202
fix(review): use runtime GITLAWB_ICAPTCHA_INSECURE flag instead of cf…
Gravirei Jul 9, 2026
41d277e
fix(review): set mock expectations at creation time, tighten insecure…
Gravirei Jul 9, 2026
5698c2e
fix(test): serialize icaptcha integration tests with global Mutex to …
Gravirei Jul 9, 2026
edaf238
fix(icaptcha): compare origins (scheme+host+port) in resolve_solver_u…
Gravirei Jul 10, 2026
2f25fb3
fix(test): save/restore inherited iCaptcha env vars instead of uncond…
Gravirei Jul 10, 2026
58769e7
fix(test): constrain negative send_once mocks with Matcher::Missing s…
Gravirei Jul 10, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor(ipfs): streamline object retrieval by separating type and co…
…ntent reading
  • Loading branch information
Gravirei committed Jun 30, 2026
commit 002f35405874898dc538773f0dcda13bafb56f49
14 changes: 11 additions & 3 deletions crates/gitlawb-node/src/api/ipfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,11 @@ pub async fn get_by_cid(
// Check whether the object exists in this repo before any expensive
// reachability walk. This prevents random-CID spray from triggering
// full-history git walks on repos that don't carry the object.
let object = store::read_object(&repo_path, &sha256_hex);
let (obj_type, content) = match object {
let obj_type = match store::object_type(&repo_path, &sha256_hex) {
Ok(Some(t)) => t,
Ok(None) => continue,
Err(e) => {
tracing::warn!(repo = %repo.name, err = %e, "error reading git object");
tracing::warn!(repo = %repo.name, err = %e, "error checking git object type");
continue;
}
};
Expand Down Expand Up @@ -178,6 +177,15 @@ pub async fn get_by_cid(
}
}

// Now that we've passed the gate, read the content.
let content = match store::read_object_content(&repo_path, &sha256_hex, &obj_type) {
Ok(c) => c,
Err(e) => {
tracing::warn!(repo = %repo.name, err = %e, "error reading git object content");
continue;
}
};

// 3. Return the content with IPFS-style headers
let mut headers = HeaderMap::new();
headers.insert(
Expand Down
34 changes: 25 additions & 9 deletions crates/gitlawb-node/src/git/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,8 @@ pub struct TreeEntry {
/// `/ipfs/<cid>` is computed from these same content bytes via
/// `gitlawb_core::cid::Cid::from_git_object_bytes`.
///
/// Returns `None` if the object does not exist in this repo.
pub fn read_object(repo_path: &Path, sha256_hex: &str) -> Result<Option<(String, Vec<u8>)>> {
// First check if the object exists and get its type
/// Get just the object type. Returns `None` if the object doesn't exist.
pub fn object_type(repo_path: &Path, sha256_hex: &str) -> Result<Option<String>> {
let type_output = Command::new("git")
.args(["cat-file", "-t", sha256_hex])
.current_dir(repo_path)
Expand All @@ -284,13 +283,13 @@ pub fn read_object(repo_path: &Path, sha256_hex: &str) -> Result<Option<(String,
return Ok(None);
}

let obj_type = String::from_utf8_lossy(&type_output.stdout)
.trim()
.to_string();
Ok(Some(String::from_utf8_lossy(&type_output.stdout).trim().to_string()))
}

// Read the raw content bytes
/// Read an object's content if its type is already known.
pub fn read_object_content(repo_path: &Path, sha256_hex: &str, obj_type: &str) -> Result<Vec<u8>> {
let content_output = Command::new("git")
.args(["cat-file", &obj_type, sha256_hex])
.args(["cat-file", obj_type, sha256_hex])
.current_dir(repo_path)
.output()
.context("failed to run git cat-file <type>")?;
Expand All @@ -300,7 +299,24 @@ pub fn read_object(repo_path: &Path, sha256_hex: &str) -> Result<Option<(String,
bail!("git cat-file failed: {stderr}");
}

Ok(Some((obj_type, content_output.stdout)))
Ok(content_output.stdout)
}

/// Read a git object by its SHA-256 hex object ID.
///
/// Returns `(object_type, content_bytes)` where `content_bytes` is the raw
/// object content (without the git framing header). The CID served over
/// `/ipfs/<cid>` is computed from these same content bytes via
/// `gitlawb_core::cid::Cid::from_git_object_bytes`.
///
/// Returns `None` if the object does not exist in this repo.
pub fn read_object(repo_path: &Path, sha256_hex: &str) -> Result<Option<(String, Vec<u8>)>> {
let obj_type = match object_type(repo_path, sha256_hex)? {
Some(t) => t,
None => return Ok(None),
};
let content = read_object_content(repo_path, sha256_hex, &obj_type)?;
Ok(Some((obj_type, content)))
}

/// Get the diff between two branches: changes on source_branch not in target_branch.
Expand Down
Loading