Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

fix: files ls inconsisntency #776

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/files/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const transform = function (res, callback) {
callback(null, entries.map((entry) => {
return {
name: entry.Name,
type: entry.Type,
type: (entry.Type === 0) ? 'file' : 'directory',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unixfs type for file is 2, and directory is 1.

Sources:
[0] https://github.com/ipfs/js-ipfs-unixfs/blob/master/src/unixfs.proto.js#L6,L7
[1] https://github.com/ipfs/js-ipfs/blob/master/src/http/api/resources/files.js#L323,L332

Also per source [1], it appears that js-ipfs-unixfs-engine uses dir[2] instead of directory. However, js-ipfs-unixfs defines the string type as directory[3].

[2] https://github.com/ipfs/js-ipfs-unixfs-engine/blob/master/src/exporter/dir-flat.js#L32
[3] https://github.com/ipfs/js-ipfs-unixfs/blob/master/src/index.js#L11

I'm unsure if this is going to cause a conflict immediately though, but it looks like js-ipfs-unixfs-engine should be updated as well at some point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unixfs type for file is 2, and directory is 1.

That's strange, because I'm getting 0s for files and 1s for directories... Hmmm, well, I'll take a look at this later then. 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the numbers in go-ipfs?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are here: https://github.com/ipfs/go-ipfs/blob/v0.4.15/mfs/system.go#L39-L42 (I ran into this separately.) Talking with @whyrusleeping on IRC about it, because a) confusing and b) not well documented. I'd also expected them to match UnixFS.

size: entry.Size,
hash: entry.Hash
}
Expand Down