ipfs / kubo

An IPFS implementation in Go
https://docs.ipfs.tech/how-to/command-line-quick-start/
Other
16.11k stars 3.01k forks source link

ipfs ls operates on both files and directories #9541

Open aschmahmann opened 1 year ago

aschmahmann commented 1 year ago

Checklist

Location

https://github.com/ipfs/kubo/blob/255e64e49e837afce534555f3451e2cffe9f0dcb/core/commands/ls.go#L50

Description

For some reason ipfs ls works on UnixFS files and lists the blocks and dag sizes linked from a file root. I don't know why but IIUC it's been that way for a while. We should either document this feature or error on it. The current setup is confusing.

TheDiscordian commented 1 year ago

or error on it.

FWIW I use this feature here. With an alternative, I'd be happy to switch to that 😄.

aschmahmann commented 1 year ago

@TheDiscordian any reason you couldn't use ipfs files stat /ipfs/<cid>? Seems like that'd be even better for what you're doing since you wouldn't have to add up the chunks yourself.

TheDiscordian commented 1 year ago

@aschmahmann I believe that endpoint would require me to add the CID to my MFS first, which would retrieve all the blocks, which I don't necessarily want to retrieve (because I'm trying to estimate the total size beforehand).

lidel commented 1 year ago

@TheDiscordian iirc things are bit counterintuitive around these APIs:

hacdias commented 1 year ago

If we reach an agreement on this, I would be more than happy to clean this up. It's just a matter of removing the handler for ErrNotADir.

https://github.com/ipfs/kubo/blob/4e8271b1021f7d31e7b201640e6214a521f328e7/core/coreapi/unixfs.go#L240-L246