-
Notifications
You must be signed in to change notification settings - Fork 126
fix: only traverse relevant part of HAMT #448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
import { logger } from '@libp2p/logger' | ||
import { exporter } from 'ipfs-unixfs-exporter' | ||
import findShardCid from 'ipfs-unixfs-exporter/dist/src/utils/find-cid-in-shard.js' | ||
import { DoesNotExistError, InvalidParametersError } from '../../errors.js' | ||
import { addLink } from './add-link.js' | ||
import { cidToDirectory } from './cid-to-directory.js' | ||
import { cidToPBLink } from './cid-to-pblink.js' | ||
import type { AbortOptions } from '@libp2p/interface' | ||
import type { Blockstore } from 'interface-blockstore' | ||
import type { CID } from 'multiformats/cid' | ||
import type { PBNode } from '@ipld/dag-pb/dist/src/interface.js' | ||
|
||
const log = logger('helia:unixfs:components:utils:resolve') | ||
|
||
|
@@ -32,6 +34,12 @@ export interface ResolveResult { | |
segments?: Segment[] | ||
} | ||
|
||
const findLinkCid = (node: PBNode, name: string): CID | undefined => { | ||
const link = node.Links.find(link => link.Name === name) | ||
|
||
return link?.Hash | ||
} | ||
|
||
export async function resolve (cid: CID, path: string | undefined, blockstore: Blockstore, options: AbortOptions): Promise<ResolveResult> { | ||
if (path == null || path === '') { | ||
return { cid } | ||
|
@@ -61,11 +69,11 @@ export async function resolve (cid: CID, path: string | undefined, blockstore: B | |
} else if (result.type === 'directory') { | ||
let dirCid: CID | undefined | ||
|
||
for await (const entry of result.content()) { | ||
if (entry.name === part) { | ||
dirCid = entry.cid | ||
break | ||
} | ||
if (result.unixfs?.type === 'hamt-sharded-directory') { | ||
// special case - unixfs v1 hamt shards | ||
dirCid = await findShardCid(result.node, part, blockstore) | ||
} else { | ||
dirCid = findLinkCid(result.node, part) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code is straight-up copy-pasted from https://github.com/ipfs/js-ipfs-unixfs/blob/4749d9a7c1eddd86b8fc42c3fa47f88c7b1b75ae/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/index.ts#L59 which makes me wonder why we can't just use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think using |
||
} | ||
|
||
if (dirCid == null) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't right. We could copy-paste or export the code if needed, but wonder if we could use more of the resolver code from ipfs-unixfs-exporter as-is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW you can't do deep imports of files like this any more, it's prevented by the
exports
map in the module'spackage.json
which defines what's importable from a module and what isn't.