ipfs / js-ipfs-unixfs

JavaScript implementation of IPFS' unixfs (a Unix FileSystem representation on top of a MerkleDAG)
Other
87 stars 33 forks source link

Difference of paths between recursive and normal calls #43

Open AuHau opened 4 years ago

AuHau commented 4 years ago

As part of https://github.com/ipfs/js-ipfs/pull/2540 I was digging why there are different link.depth when ipfs ls is called recursively and non-recursively. I have tracked the inconsistency to how this exporter returns paths when called recursively and non-recursively.

When called using /ipfs/Qmaj2NmcyAXT8dFmZRRytE12wpcaHADzbChKToMEjBsj5Z/init-docs recursivelly, the result paths are:

When called using /ipfs/Qmaj2NmcyAXT8dFmZRRytE12wpcaHADzbChKToMEjBsj5Z/init-docs non-recursivelly, the result paths are:

Eq. the original /init-docs is suddenly part of the returned paths.

I believe there should be one way for both ways. What should be the right one?

achingbrain commented 4 years ago

I think this is meant to be a reflection of what happens in bash, etc.

Given:

foo
├── bar.txt
└── baz/
    └── qux.txt
$ ls -l foo
total 3
-rw-r--r--   8 alex  staff  256  4 Oct 16:22 bar.txt
drwxr-xr-x  12 alex  staff  384  8 Oct 11:52 baz
$ ls -lR foo
total 3
-rw-r--r--   8 alex  staff  256  4 Oct 16:22 bar.txt
drwxr-xr-x  12 alex  staff  384  8 Oct 11:52 baz

foo/baz:
total 2
-rw-r--r--   1 alex  staff   838 20 May 15:44 qux.txt

In the second example the containing folder becomes part of the path - it prints foo/baz: instead of baz:.

That said, it'd certainly be simpler if it only worked one way, probably the second where the paths contain the CID the user has specified.

AuHau commented 4 years ago

For info: We agreed that the depth will be calculated as using full path. Hence when

/ipfs/Qmaj2NmcyAXT8dFmZRRytE12wpcaHADzbChKToMEjBsj5Z/init-docs

returns

Qmaj2NmcyAXT8dFmZRRytE12wpcaHADzbChKToMEjBsj5Z/init-docs/contact

it will have depth 2.