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

src/files/ls.js uses incorrect long listing option name #1211

Closed
khartig opened this issue Jan 3, 2020 · 1 comment
Closed

src/files/ls.js uses incorrect long listing option name #1211

khartig opened this issue Jan 3, 2020 · 1 comment

Comments

@khartig
Copy link

khartig commented Jan 3, 2020

The IPFS documentation for 'ipfs files ls' CLI command (https://docs.ipfs.io/reference/api/cli/#ipfs-files-ls) lists the long listing option as using:
-l bool
The src/files/ls.js implementation expects -long as the parameter instead.

The documentation at https://github.com/ipfs/interface-js-ipfs-core/blob/master/SPEC/FILES.md#filesls shows using 'long' for the option. This is consistent with the implementation in the ls.js code. The HTTP post request created also uses 'long' as the option flag.
But the 'long' flag is not valid for current implementations of IPFS and is ignored. This results in the long listing never being returned.

using
$ curl "http://localhost:5001/api/v0/files/ls?arg=/&stream=true&long=true"
returns
{"Entries":[{"Name":"dockerImages","Type":0,"Size":0,"Hash":""}]}

using
$ curl "http://localhost:5001/api/v0/files/ls?arg=/&stream=true&l=true"
returns
{"Entries":[{"Name":"dockerImages","Type":1,"Size":0,"Hash":"QmZH8ouPv46gMjckBAcPz1Aa82td6kA95cEZ7G6vP6uWdy"}]}

I am using
ipfs-http-client version 40.1.0
ipfs version 0.4.22
on macOS 10.15.1

To test, I am using the following client code


const ipfsClient = require('ipfs-http-client');

const listImages = async callback => {
// connect to ipfs daemon API server
const ipfs = ipfsClient('http://localhost:5001');

const imageDir = await ipfs.files.ls('/dockerImages');

for await (const dir of imageDir) {
    console.log(dir.name);
    const files = await ipfs.files.ls('/dockerImages/'+dir.name, {long: true});
    files.forEach ((file) => {
        console.log('\t'+file.name);
        console.log('\t'+file.hash)
    });
}

};

listImages();

where I have files in my local IPFS node under /dockerImages
passing {long: true} as the option paramter to ipfs.files.ls will never return the long results.

To get things working locally, I changed line 22 in ls.js to

if (options.l != null) searchParams.set('l', options.l)

and passing the options parameter in the client code as
{l: true}

results with correctly returning Hash, Type, and Size values.

You could alternatively change the code in ls.js to accept long and the option name but translate it to 'l' before making the http request.

Thoughts on this?

@alanshaw
Copy link
Contributor

alanshaw commented Jan 4, 2020

This will be fixed in the new go-ipfs release. I don’t think it’s worth putting work into this. I recommend you temporarily add the param using the searchParams option. https://github.com/ipfs/js-ipfs-http-client#additional-options

@alanshaw alanshaw closed this as completed Feb 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants