Skip to content

Subpath access fetches flat bytes, not directory structure #265

@lthibault

Description

@lthibault

Problem

When opening /ipfs/<CID>/sub/file.txt, open_ipfs fetches the entire CID as a flat byte blob via cache.fetch(), writes it to staging/<CID>, then tries to open staging/<CID>/sub/file.txt.

This only works if the staged content is a directory tree. But Kubo's cat API returns flat bytes (concatenated file content). For UnixFS directories, you need the get API which returns a tarball, then unpack it.

Current behavior: subpath requests on directory CIDs will return NoEntry because the nested path doesn't exist on disk after writing the flat blob. The integration tests pass because mock pinners return whatever bytes you give them.

Fix

For CIDs that are UnixFS directories:

  1. Use a get-style API that preserves directory structure (e.g., Kubo's /api/v0/get)
  2. Unpack the returned tarball into the staging directory
  3. Then open the subpath from the unpacked tree

Alternatively, resolve subpaths at the IPFS layer: fetch <CID>/sub/file.txt directly rather than fetching the root CID and navigating locally.

Context

Found by adversarial review on #263. The Pinner::fetch trait method returns Vec<u8> which is fine for single files but doesn't preserve directory structure.

Severity

High — subpath access is a documented feature but doesn't work for real IPFS directories.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High — fix before next milestonebugSomething isn't workingtrack:ipfs-cacheIPFS cache + filesystem interceptor track

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions