From 6c0d8a059633b239519fa8c426cdda42c470a29b Mon Sep 17 00:00:00 2001 From: jkrone Date: Tue, 23 Jan 2018 16:40:04 -0500 Subject: [PATCH 01/20] Initial work on js-ipfs ls -r. Realized that I prefer adding an option to the ipfs.lsImmutable call instead of querying the server for each explored subdir. --- src/cli/commands/ls.js | 41 +++++++++++++++++++++++---------- src/core/components/files.js | 11 +++++++-- src/http/api/resources/files.js | 2 +- 3 files changed, 39 insertions(+), 15 deletions(-) diff --git a/src/cli/commands/ls.js b/src/cli/commands/ls.js index e7beecbaee..2c33ec0d91 100644 --- a/src/cli/commands/ls.js +++ b/src/cli/commands/ls.js @@ -14,6 +14,12 @@ module.exports = { type: 'boolean', default: false }, + recursive: { + alias: 'r', + desc: 'List subdirectories recursively', + type: 'boolean', + default: false + }, 'resolve-type': { desc: 'Resolve linked objects to find out their types. (not implemented yet)', type: 'boolean', @@ -36,21 +42,32 @@ module.exports = { links = [{hash: 'Hash', size: 'Size', name: 'Name'}].concat(links) } - links = links.filter((link) => link.path !== path) - links.forEach((link) => { - if (link.type === 'dir') { - // directory: add trailing "/" - link.name = (link.name || '') + '/' - } - }) const multihashWidth = Math.max.apply(null, links.map((file) => file.hash.length)) const sizeWidth = Math.max.apply(null, links.map((file) => String(file.size).length)) - links.forEach((file) => { - utils.print(utils.rightpad(file.hash, multihashWidth + 1) + - utils.rightpad(file.size || '', sizeWidth + 1) + - file.name) - }) + printFiles(argv.ipfs, argv.recursive, multihashWidth, sizeWidth, 0, links) }) } } + +function printFiles(ipfs, recurse, multihashWidth, sizeWidth, depth, links) { + // console.log('links:', links) + links.forEach(link => { + printFile(multihashWidth, sizeWidth, depth, link) + if (link.type === 'dir' && recurse) { + ipfs.ls(link.hash, (err, files) => { + if (err) throw err + printFiles(ipfs, recurse, multihashWidth, sizeWidth, depth + 1, files) + }) + } + }) +} + +function printFile(multihashWidth, sizeWidth, depth, file) { + const fileName = file.type === 'dir' ? `${file.name || ''}/` : file.name + utils.print( + utils.rightpad(file.hash, multihashWidth + 1) + + utils.rightpad(file.size || '', sizeWidth + 1) + + ' '.repeat(depth * 2) + fileName + ) +} diff --git a/src/core/components/files.js b/src/core/components/files.js index b06c396745..58da80083c 100644 --- a/src/core/components/files.js +++ b/src/core/components/files.js @@ -164,9 +164,16 @@ module.exports = function files (self) { function _lsPullStreamImmutable (ipfsPath) { const path = normalizePath(ipfsPath) const depth = path.split('/').length + console.log('path:', path) + console.log('depth:', depth) + console.log('self._ipldResolver:', self._ipldResolver) return pull( - exporter(ipfsPath, self._ipldResolver, { maxDepth: depth }), - pull.filter((node) => node.depth === depth), + exporter(ipfsPath, self._ipldResolver, { maxDepth: global.Infinity }), + pull.filter((node) => { + console.log('node:', node) + node.depth === depth + return true + }), pull.map((node) => { node = Object.assign({}, node, { hash: toB58String(node.hash) }) delete node.content diff --git a/src/http/api/resources/files.js b/src/http/api/resources/files.js index 1349b46ca8..42eac79c7a 100644 --- a/src/http/api/resources/files.js +++ b/src/http/api/resources/files.js @@ -271,7 +271,7 @@ exports.immutableLs = { // main route handler which is called after the above `parseArgs`, but only if the args were valid handler: (request, reply) => { const key = request.pre.args.key - const ipfs = request.server.app.ipfs + const ipfs = request.server.app.ipfs // index.js assigns ipfs.ls as files.lsImmutable ipfs.ls(key, (err, files) => { if (err) { From e0ff5baca95682e03be1258727da6bd9fb2b8067 Mon Sep 17 00:00:00 2001 From: jkrone Date: Wed, 24 Jan 2018 12:38:32 -0500 Subject: [PATCH 02/20] checkpoint commit. barebones impl passing args through ipfs.ls --- src/cli/commands/ls.js | 6 +++--- src/core/components/files.js | 30 +++++++++++++++++------------- src/http/api/resources/files.js | 3 ++- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/cli/commands/ls.js b/src/cli/commands/ls.js index 2c33ec0d91..b6030d157d 100644 --- a/src/cli/commands/ls.js +++ b/src/cli/commands/ls.js @@ -14,8 +14,8 @@ module.exports = { type: 'boolean', default: false }, - recursive: { - alias: 'r', + r: { + alias: 'recursive', desc: 'List subdirectories recursively', type: 'boolean', default: false @@ -33,7 +33,7 @@ module.exports = { path = path.replace('/ipfs/', '') } - argv.ipfs.ls(path, (err, links) => { + argv.ipfs.ls(path, { recursive: argv.recursive }, (err, links) => { if (err) { throw err } diff --git a/src/core/components/files.js b/src/core/components/files.js index 58da80083c..01e5604c5a 100644 --- a/src/core/components/files.js +++ b/src/core/components/files.js @@ -161,18 +161,18 @@ module.exports = function files (self) { return d } - function _lsPullStreamImmutable (ipfsPath) { + function _lsPullStreamImmutable (ipfsPath, options) { const path = normalizePath(ipfsPath) - const depth = path.split('/').length - console.log('path:', path) - console.log('depth:', depth) - console.log('self._ipldResolver:', self._ipldResolver) + const recurse = options && options.recursive + const depth = recurse ? global.Infinity : path.split('/').length + // console.log('path:', path) + // console.log('depth:', depth) + // console.log('self._ipldResolver:', self._ipldResolver) return pull( - exporter(ipfsPath, self._ipldResolver, { maxDepth: global.Infinity }), + exporter(ipfsPath, self._ipldResolver, { maxDepth: depth }), pull.filter((node) => { - console.log('node:', node) - node.depth === depth - return true + // console.log('node:', node) + return recurse ? node.depth >= depth : node.depth === depth }), pull.map((node) => { node = Object.assign({}, node, { hash: toB58String(node.hash) }) @@ -285,9 +285,13 @@ module.exports = function files (self) { return exporter(ipfsPath, self._ipldResolver) }, - lsImmutable: promisify((ipfsPath, callback) => { + lsImmutable: promisify((ipfsPath, options, callback) => { + if (typeof options === 'function') { + // options arg is optional so if it's a function then it's the callback + callback = options + } pull( - _lsPullStreamImmutable(ipfsPath), + _lsPullStreamImmutable(ipfsPath, options), pull.collect((err, values) => { if (err) { return callback(err) @@ -297,8 +301,8 @@ module.exports = function files (self) { ) }), - lsReadableStreamImmutable: (ipfsPath) => { - return toStream.source(_lsPullStreamImmutable(ipfsPath)) + lsReadableStreamImmutable: (ipfsPath, options) => { + return toStream.source(_lsPullStreamImmutable(ipfsPath, options)) }, lsPullStreamImmutable: _lsPullStreamImmutable diff --git a/src/http/api/resources/files.js b/src/http/api/resources/files.js index 42eac79c7a..2916fbaf6d 100644 --- a/src/http/api/resources/files.js +++ b/src/http/api/resources/files.js @@ -272,8 +272,9 @@ exports.immutableLs = { handler: (request, reply) => { const key = request.pre.args.key const ipfs = request.server.app.ipfs // index.js assigns ipfs.ls as files.lsImmutable + const recurse = request.query && request.query.recursive - ipfs.ls(key, (err, files) => { + ipfs.ls(key, { recursive: recurse }, (err, files) => { if (err) { reply({ Message: 'Failed to list dir: ' + err.message, From cb27a717af63f91a75a12d71d014e5cc5c62eb7d Mon Sep 17 00:00:00 2001 From: jkrone Date: Wed, 24 Jan 2018 14:37:45 -0500 Subject: [PATCH 03/20] clean up impl of 'ipfs ls -r'. Lots of failing tests, unsure if they're related. Also need to understand mfs more, and differences between 'ipfs ls|file ls|files ls' --- src/cli/commands/ls.js | 31 ++++++++----------------------- src/core/components/files.js | 19 +++++++++---------- src/http/api/resources/files.js | 9 +++++---- test/cli/ls.js | 0 4 files changed, 22 insertions(+), 37 deletions(-) create mode 100644 test/cli/ls.js diff --git a/src/cli/commands/ls.js b/src/cli/commands/ls.js index b6030d157d..e21f752b87 100644 --- a/src/cli/commands/ls.js +++ b/src/cli/commands/ls.js @@ -45,29 +45,14 @@ module.exports = { const multihashWidth = Math.max.apply(null, links.map((file) => file.hash.length)) const sizeWidth = Math.max.apply(null, links.map((file) => String(file.size).length)) - printFiles(argv.ipfs, argv.recursive, multihashWidth, sizeWidth, 0, links) + links.forEach(link => { + const fileName = link.type === 'dir' ? `${link.name || ''}/` : link.name + utils.print( + utils.rightpad(link.hash, multihashWidth + 1) + + utils.rightpad(link.size || '', sizeWidth + 1) + + ' '.repeat((link.depth - 1) * 2) + fileName + ) + }) }) } } - -function printFiles(ipfs, recurse, multihashWidth, sizeWidth, depth, links) { - // console.log('links:', links) - links.forEach(link => { - printFile(multihashWidth, sizeWidth, depth, link) - if (link.type === 'dir' && recurse) { - ipfs.ls(link.hash, (err, files) => { - if (err) throw err - printFiles(ipfs, recurse, multihashWidth, sizeWidth, depth + 1, files) - }) - } - }) -} - -function printFile(multihashWidth, sizeWidth, depth, file) { - const fileName = file.type === 'dir' ? `${file.name || ''}/` : file.name - utils.print( - utils.rightpad(file.hash, multihashWidth + 1) + - utils.rightpad(file.size || '', sizeWidth + 1) + - ' '.repeat(depth * 2) + fileName - ) -} diff --git a/src/core/components/files.js b/src/core/components/files.js index 01e5604c5a..3c7b1b4e08 100644 --- a/src/core/components/files.js +++ b/src/core/components/files.js @@ -163,17 +163,15 @@ module.exports = function files (self) { function _lsPullStreamImmutable (ipfsPath, options) { const path = normalizePath(ipfsPath) - const recurse = options && options.recursive - const depth = recurse ? global.Infinity : path.split('/').length - // console.log('path:', path) - // console.log('depth:', depth) - // console.log('self._ipldResolver:', self._ipldResolver) + const recursive = options && options.recursive + const pathDepth = path.split('/').length + const maxDepth = recursive ? global.Infinity : pathDepth + return pull( - exporter(ipfsPath, self._ipldResolver, { maxDepth: depth }), - pull.filter((node) => { - // console.log('node:', node) - return recurse ? node.depth >= depth : node.depth === depth - }), + exporter(ipfsPath, self._ipldResolver, { maxDepth: maxDepth }), + pull.filter((node) => + recursive ? node.depth >= pathDepth : node.depth === pathDepth + ), pull.map((node) => { node = Object.assign({}, node, { hash: toB58String(node.hash) }) delete node.content @@ -290,6 +288,7 @@ module.exports = function files (self) { // options arg is optional so if it's a function then it's the callback callback = options } + pull( _lsPullStreamImmutable(ipfsPath, options), pull.collect((err, values) => { diff --git a/src/http/api/resources/files.js b/src/http/api/resources/files.js index 2916fbaf6d..31f5804043 100644 --- a/src/http/api/resources/files.js +++ b/src/http/api/resources/files.js @@ -271,10 +271,10 @@ exports.immutableLs = { // main route handler which is called after the above `parseArgs`, but only if the args were valid handler: (request, reply) => { const key = request.pre.args.key - const ipfs = request.server.app.ipfs // index.js assigns ipfs.ls as files.lsImmutable - const recurse = request.query && request.query.recursive + const ipfs = request.server.app.ipfs + const recursive = request.query && request.query.recursive === 'true' - ipfs.ls(key, { recursive: recurse }, (err, files) => { + ipfs.ls(key, { recursive: recursive }, (err, files) => { if (err) { reply({ Message: 'Failed to list dir: ' + err.message, @@ -289,7 +289,8 @@ exports.immutableLs = { Name: file.name, Hash: file.hash, Size: file.size, - Type: toTypeCode(file.type) + Type: toTypeCode(file.type), + Depth: file.depth })) }] }) diff --git a/test/cli/ls.js b/test/cli/ls.js new file mode 100644 index 0000000000..e69de29bb2 From a8a4b8476244f728bbdd64a0a1d36f58ced4b3e1 Mon Sep 17 00:00:00 2001 From: jkrone Date: Thu, 25 Jan 2018 10:02:17 -0500 Subject: [PATCH 04/20] consider 'ipfs ls' as an alias to 'ipfs files ls' --- src/cli/bin.js | 5 +++-- src/cli/commands/files.js | 5 ++++- src/cli/commands/files/ls.js | 29 +++++++++++++++++++++++++++++ src/core/components/files.js | 1 + src/http/api/resources/files.js | 3 +++ 5 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 src/cli/commands/files/ls.js diff --git a/src/cli/bin.js b/src/cli/bin.js index 67e60f8362..0df66354a1 100755 --- a/src/cli/bin.js +++ b/src/cli/bin.js @@ -36,12 +36,13 @@ const cli = yargs }) // NOTE: This creates an alias of -// `jsipfs files {add, get, cat}` to `jsipfs {add, get, cat}`. +// `jsipfs files {add, get, cat, ls}` to `jsipfs {add, get, cat, ls}`. // This will stay until https://github.com/ipfs/specs/issues/98 is resolved. const addCmd = require('./commands/files/add') const catCmd = require('./commands/files/cat') const getCmd = require('./commands/files/get') -const aliases = [addCmd, catCmd, getCmd] +const lsCmd = require('./commands/files/ls') +const aliases = [addCmd, catCmd, getCmd, lsCmd] aliases.forEach((alias) => { cli.command(alias.command, alias.describe, alias.builder, alias.handler) }) diff --git a/src/cli/commands/files.js b/src/cli/commands/files.js index 09ca4de380..e9ac95d657 100644 --- a/src/cli/commands/files.js +++ b/src/cli/commands/files.js @@ -1,5 +1,8 @@ 'use strict' +const print = require('../utils').print + + module.exports = { command: 'files ', @@ -11,6 +14,6 @@ module.exports = { }, handler (argv) { - console.log('Type `jsipfs bitswap --help` for more instructions') + print('Type `jsipfs files --help` for more instructions') } } diff --git a/src/cli/commands/files/ls.js b/src/cli/commands/files/ls.js new file mode 100644 index 0000000000..437788381f --- /dev/null +++ b/src/cli/commands/files/ls.js @@ -0,0 +1,29 @@ +'use strict' + +const print = require('../../utils').print + +module.exports = { + command: 'ls ', + + describe: 'List directory contents for Unix filesystem objects.', + + builder: { + + }, + + handler (argv) { + let path = argv.key + argv.ipfs.files.ls(path, (err, links) => { + if (err) { + throw err + } + + // Single file? Then print its hash + if (links.length === 0) { + links = [{hash: path}] + } + + links.forEach((file) => print(file.hash)) + }) + } +} diff --git a/src/core/components/files.js b/src/core/components/files.js index 3c7b1b4e08..d383a56dbe 100644 --- a/src/core/components/files.js +++ b/src/core/components/files.js @@ -287,6 +287,7 @@ module.exports = function files (self) { if (typeof options === 'function') { // options arg is optional so if it's a function then it's the callback callback = options + options = {} } pull( diff --git a/src/http/api/resources/files.js b/src/http/api/resources/files.js index 31f5804043..ea00bf217c 100644 --- a/src/http/api/resources/files.js +++ b/src/http/api/resources/files.js @@ -274,6 +274,9 @@ exports.immutableLs = { const ipfs = request.server.app.ipfs const recursive = request.query && request.query.recursive === 'true' + console.log('ipfs.files.ls:', ipfs.files.ls) + console.log('ipfs.ls:', ipfs.ls) + ipfs.ls(key, { recursive: recursive }, (err, files) => { if (err) { reply({ From 6ef9d90076fbcb1d6ec4b93406736c3847701989 Mon Sep 17 00:00:00 2001 From: jkrone Date: Fri, 9 Feb 2018 09:25:22 -0600 Subject: [PATCH 05/20] deprecate 'ipfs file ls' --- src/cli/commands/file/ls.js | 2 ++ src/cli/commands/files/ls.js | 1 + src/core/components/files.js | 8 ++++---- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/cli/commands/file/ls.js b/src/cli/commands/file/ls.js index c952087b98..31abd73e60 100644 --- a/src/cli/commands/file/ls.js +++ b/src/cli/commands/file/ls.js @@ -11,6 +11,8 @@ module.exports = { handler (argv) { let path = argv.key + // `ipfs file ls` is deprecated. See https://ipfs.io/docs/commands/#ipfs-file-ls + print(`This functionality is deprecated, and will be removed in future versions. If possible, please use 'ipfs ls' instead.`) argv.ipfs.ls(path, (err, links) => { if (err) { throw err diff --git a/src/cli/commands/files/ls.js b/src/cli/commands/files/ls.js index 437788381f..e50c8716dc 100644 --- a/src/cli/commands/files/ls.js +++ b/src/cli/commands/files/ls.js @@ -13,6 +13,7 @@ module.exports = { handler (argv) { let path = argv.key + argv.ipfs.files.ls(path, (err, links) => { if (err) { throw err diff --git a/src/core/components/files.js b/src/core/components/files.js index d383a56dbe..78c0053cf8 100644 --- a/src/core/components/files.js +++ b/src/core/components/files.js @@ -169,10 +169,10 @@ module.exports = function files (self) { return pull( exporter(ipfsPath, self._ipldResolver, { maxDepth: maxDepth }), - pull.filter((node) => + pull.filter(node => recursive ? node.depth >= pathDepth : node.depth === pathDepth ), - pull.map((node) => { + pull.map(node => { node = Object.assign({}, node, { hash: toB58String(node.hash) }) delete node.content return node @@ -285,7 +285,6 @@ module.exports = function files (self) { lsImmutable: promisify((ipfsPath, options, callback) => { if (typeof options === 'function') { - // options arg is optional so if it's a function then it's the callback callback = options options = {} } @@ -294,7 +293,8 @@ module.exports = function files (self) { _lsPullStreamImmutable(ipfsPath, options), pull.collect((err, values) => { if (err) { - return callback(err) + callback(err) + return } callback(null, values) }) From 9957557a34be3d024ff9327e8ef29864f3e44c8e Mon Sep 17 00:00:00 2001 From: jkrone Date: Fri, 9 Feb 2018 11:15:58 -0600 Subject: [PATCH 06/20] trace failure of js-ipfs ls 'public ipfs path' to print. Checkpoint while I test master --- src/cli/bin.js | 4 ++-- src/cli/commands/ls.js | 1 + src/core/components/files.js | 5 ++++- src/http/api/resources/file.js | 1 + src/http/api/resources/files.js | 6 +++--- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/cli/bin.js b/src/cli/bin.js index 0df66354a1..72fc1d1ecc 100755 --- a/src/cli/bin.js +++ b/src/cli/bin.js @@ -41,8 +41,8 @@ const cli = yargs const addCmd = require('./commands/files/add') const catCmd = require('./commands/files/cat') const getCmd = require('./commands/files/get') -const lsCmd = require('./commands/files/ls') -const aliases = [addCmd, catCmd, getCmd, lsCmd] +// const lsCmd = require('./commands/files/ls') +const aliases = [addCmd, catCmd, getCmd /*, lsCmd */] aliases.forEach((alias) => { cli.command(alias.command, alias.describe, alias.builder, alias.handler) }) diff --git a/src/cli/commands/ls.js b/src/cli/commands/ls.js index e21f752b87..33c4a9791a 100644 --- a/src/cli/commands/ls.js +++ b/src/cli/commands/ls.js @@ -37,6 +37,7 @@ module.exports = { if (err) { throw err } + console.log('links:', links) if (argv.headers) { links = [{hash: 'Hash', size: 'Size', name: 'Name'}].concat(links) diff --git a/src/core/components/files.js b/src/core/components/files.js index 78c0053cf8..180173c56e 100644 --- a/src/core/components/files.js +++ b/src/core/components/files.js @@ -173,7 +173,8 @@ module.exports = function files (self) { recursive ? node.depth >= pathDepth : node.depth === pathDepth ), pull.map(node => { - node = Object.assign({}, node, { hash: toB58String(node.hash) }) + const cid = new CID(node.hash) + node = Object.assign({}, node, { hash: cid.toBaseEncodedString() }) delete node.content return node }) @@ -292,10 +293,12 @@ module.exports = function files (self) { pull( _lsPullStreamImmutable(ipfsPath, options), pull.collect((err, values) => { + console.log('did we bug out?:', err) if (err) { callback(err) return } + console.log('values:', values) callback(null, values) }) ) diff --git a/src/http/api/resources/file.js b/src/http/api/resources/file.js index 6c0b6b4c4c..e677e25e12 100644 --- a/src/http/api/resources/file.js +++ b/src/http/api/resources/file.js @@ -72,6 +72,7 @@ exports.ls = { // uses common parseKey method that returns a `key` parseArgs: exports.parseKey, + // TODO What is this? // main route handler which is called after the above `parseArgs`, but only if the args were valid handler: (request, reply) => { const path = request.pre.args.path diff --git a/src/http/api/resources/files.js b/src/http/api/resources/files.js index ea00bf217c..38dbe7b7a4 100644 --- a/src/http/api/resources/files.js +++ b/src/http/api/resources/files.js @@ -37,6 +37,7 @@ exports.parseKey = (request, reply) => { } try { + // TODO make CID. ref: block.js mh.fromB58String(key) } catch (err) { log.error(err) @@ -274,16 +275,15 @@ exports.immutableLs = { const ipfs = request.server.app.ipfs const recursive = request.query && request.query.recursive === 'true' - console.log('ipfs.files.ls:', ipfs.files.ls) - console.log('ipfs.ls:', ipfs.ls) - ipfs.ls(key, { recursive: recursive }, (err, files) => { + console.trace('ipfs.ls results') if (err) { reply({ Message: 'Failed to list dir: ' + err.message, Code: 0 }).code(500) } + console.log('files:', files) reply({ Objects: [{ From acf38e51baad5b3d3d8c58a155cd3c19c327afc2 Mon Sep 17 00:00:00 2001 From: jkrone Date: Sun, 11 Feb 2018 17:08:32 -0600 Subject: [PATCH 07/20] line ending conversion seemed to break tests. reverting and reseting my git index. --- src/cli/commands/files/ls.js | 1 - src/cli/commands/ls.js | 1 - src/core/components/files.js | 2 - src/http/api/resources/files.js | 2 - test/cli/files.js | 126 +++++++++++++++++--------------- 5 files changed, 67 insertions(+), 65 deletions(-) diff --git a/src/cli/commands/files/ls.js b/src/cli/commands/files/ls.js index e50c8716dc..437788381f 100644 --- a/src/cli/commands/files/ls.js +++ b/src/cli/commands/files/ls.js @@ -13,7 +13,6 @@ module.exports = { handler (argv) { let path = argv.key - argv.ipfs.files.ls(path, (err, links) => { if (err) { throw err diff --git a/src/cli/commands/ls.js b/src/cli/commands/ls.js index 33c4a9791a..e21f752b87 100644 --- a/src/cli/commands/ls.js +++ b/src/cli/commands/ls.js @@ -37,7 +37,6 @@ module.exports = { if (err) { throw err } - console.log('links:', links) if (argv.headers) { links = [{hash: 'Hash', size: 'Size', name: 'Name'}].concat(links) diff --git a/src/core/components/files.js b/src/core/components/files.js index 180173c56e..d2afecf767 100644 --- a/src/core/components/files.js +++ b/src/core/components/files.js @@ -293,12 +293,10 @@ module.exports = function files (self) { pull( _lsPullStreamImmutable(ipfsPath, options), pull.collect((err, values) => { - console.log('did we bug out?:', err) if (err) { callback(err) return } - console.log('values:', values) callback(null, values) }) ) diff --git a/src/http/api/resources/files.js b/src/http/api/resources/files.js index 38dbe7b7a4..033634b009 100644 --- a/src/http/api/resources/files.js +++ b/src/http/api/resources/files.js @@ -276,14 +276,12 @@ exports.immutableLs = { const recursive = request.query && request.query.recursive === 'true' ipfs.ls(key, { recursive: recursive }, (err, files) => { - console.trace('ipfs.ls results') if (err) { reply({ Message: 'Failed to list dir: ' + err.message, Code: 0 }).code(500) } - console.log('files:', files) reply({ Objects: [{ diff --git a/test/cli/files.js b/test/cli/files.js index 9fa95a0401..062070f121 100644 --- a/test/cli/files.js +++ b/test/cli/files.js @@ -136,7 +136,7 @@ describe('files', () => runOnAndOff((thing) => { }) }) - it('add recursively test', function () { + it.only('add recursively test', function () { this.timeout(60 * 1000) return ipfs('files add -r test/fixtures/test-data/recursive-get-dir') @@ -296,73 +296,81 @@ describe('files', () => runOnAndOff((thing) => { }) }) - it('ls', function () { - this.timeout(20 * 1000) + describe('ls', () => { + before(() => { + return ipfs('files add -r test/fixtures/test-data/recursive-get-dir') + .then(console.log.bind(console, 'files added:')) + }) - return ipfs('ls QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2') - .then((out) => { - expect(out).to.eql( - 'QmQQHYDwAQms78fPcvx1uFFsfho23YJNoewfLbi9AtdyJ9 123530 blocks/\n' + - 'QmPkWYfSLCEBLZu7BZt4kigGDMe3cpogMbeVf97gN2xJDN 3939 config\n' + - 'Qma13ZrhKG52MWnwtZ6fMD8jGj8d4Q9sJgn5xtKgeZw5uz 5503 datastore/\n' + - 'QmUhUuiTKkkK8J6JZ9zmj8iNHPuNfGYcszgRumzhHBxEEU 7397 init-docs/\n' + - 'QmR56UJmAaZLXLdTT1ALrE9vVqV8soUEekm9BMd4FnuYqV 10 version\n') - }) - }) + it('prints added files', function () { + this.timeout(20 * 1000) + // old: QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2 + return ipfs('ls QmRyExB6Q2DYGuztKfXC3txxDsRKW8QS9ib7XQM7xy16hx') + .then((out) => { + expect(out).to.eql( + 'QmQQHYDwAQms78fPcvx1uFFsfho23YJNoewfLbi9AtdyJ9 123530 blocks/\n' + + 'QmPkWYfSLCEBLZu7BZt4kigGDMe3cpogMbeVf97gN2xJDN 3939 config\n' + + 'Qma13ZrhKG52MWnwtZ6fMD8jGj8d4Q9sJgn5xtKgeZw5uz 5503 datastore/\n' + + 'QmUhUuiTKkkK8J6JZ9zmj8iNHPuNfGYcszgRumzhHBxEEU 7397 init-docs/\n' + + 'QmR56UJmAaZLXLdTT1ALrE9vVqV8soUEekm9BMd4FnuYqV 10 version\n') + }) + }) - it('ls -v', function () { - this.timeout(20 * 1000) + it(`prints nothing for non-existant hashes`, function(done) { + this.slow(3200) + setTimeout(done, 3000) + ipfs('ls QmYmW4HiZhotsoSqnv2o1oSssvkRM8b9RweBoH7ao5nki2') + .then(() => done( + new Error('ipfs ls found something when it should not have') + )) + }) - return ipfs('ls /ipfs/QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2 -v') - .then((out) => { - expect(out).to.eql( - 'Hash Size Name\n' + - 'QmQQHYDwAQms78fPcvx1uFFsfho23YJNoewfLbi9AtdyJ9 123530 blocks/\n' + - 'QmPkWYfSLCEBLZu7BZt4kigGDMe3cpogMbeVf97gN2xJDN 3939 config\n' + - 'Qma13ZrhKG52MWnwtZ6fMD8jGj8d4Q9sJgn5xtKgeZw5uz 5503 datastore/\n' + - 'QmUhUuiTKkkK8J6JZ9zmj8iNHPuNfGYcszgRumzhHBxEEU 7397 init-docs/\n' + - 'QmR56UJmAaZLXLdTT1ALrE9vVqV8soUEekm9BMd4FnuYqV 10 version\n') - }) - }) + it('adds a header, -v', function () { + this.timeout(20 * 1000) + + return ipfs('ls /ipfs/QmRyExB6Q2DYGuztKfXC3txxDsRKW8QS9ib7XQM7xy16hx -v') + .then((out) => { + expect(out).to.eql( + 'Hash Size Name\n' + + 'QmQQHYDwAQms78fPcvx1uFFsfho23YJNoewfLbi9AtdyJ9 123530 blocks/\n' + + 'QmPkWYfSLCEBLZu7BZt4kigGDMe3cpogMbeVf97gN2xJDN 3939 config\n' + + 'Qma13ZrhKG52MWnwtZ6fMD8jGj8d4Q9sJgn5xtKgeZw5uz 5503 datastore/\n' + + 'QmUhUuiTKkkK8J6JZ9zmj8iNHPuNfGYcszgRumzhHBxEEU 7397 init-docs/\n' + + 'QmR56UJmAaZLXLdTT1ALrE9vVqV8soUEekm9BMd4FnuYqV 10 version\n' + ) + }) + }) - it('ls ', function () { - this.timeout(20 * 1000) + it('follows a path, ls ', function () { + this.timeout(20 * 1000) + + return ipfs('ls /ipfs/QmRyExB6Q2DYGuztKfXC3txxDsRKW8QS9ib7XQM7xy16hx/init-docs') + .then((out) => { + expect(out).to.eql( + 'QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V 1688 about\n' + + 'QmYCvbfNbCwFR45HiNP45rwJgvatpiW38D961L5qAhUM5Y 200 contact\n' + + 'QmegvLXxpVKiZ4b57Xs1syfBVRd8CbucVHAp7KpLQdGieC 65 docs/\n' + + 'QmY5heUM5qgRubMDD1og9fhCPA6QdkMp3QCwd4s7gJsyE7 322 help\n' + + 'QmdncfsVm2h5Kqq9hPmU7oAVX2zTSVP3L869tgTbPYnsha 1728 quick-start\n' + + 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB 1102 readme\n' + + 'QmTumTjvcYCAvRRwQ8sDRxh8ezmrcr88YFU7iYNroGGTBZ 1027 security-notes\n' + + 'QmciSU8hfpAXKjvK5YLUSwApomGSWN5gFbP4EpDAEzu2Te 863 tour/\n' + ) + }) + }) - return ipfs('ls /ipfs/QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2/init-docs') - .then((out) => { - expect(out).to.eql( - 'QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V 1688 about\n' + - 'QmYCvbfNbCwFR45HiNP45rwJgvatpiW38D961L5qAhUM5Y 200 contact\n' + - 'QmegvLXxpVKiZ4b57Xs1syfBVRd8CbucVHAp7KpLQdGieC 65 docs/\n' + - 'QmY5heUM5qgRubMDD1og9fhCPA6QdkMp3QCwd4s7gJsyE7 322 help\n' + - 'QmdncfsVm2h5Kqq9hPmU7oAVX2zTSVP3L869tgTbPYnsha 1728 quick-start\n' + - 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB 1102 readme\n' + - 'QmTumTjvcYCAvRRwQ8sDRxh8ezmrcr88YFU7iYNroGGTBZ 1027 security-notes\n' + - 'QmciSU8hfpAXKjvK5YLUSwApomGSWN5gFbP4EpDAEzu2Te 863 tour/\n') - }) - }) + it('recursively follows folders, -r', function() { + this.timeout(20 * 1000) - it('ls --help', function () { - this.timeout(20 * 1000) + return ipfs('ls -r /ipfs/QmRyExB6Q2DYGuztKfXC3txxDsRKW8QS9ib7XQM7xy16hx/init-docs') + .then(out => { + console.log('output from ls -r:', out) - return ipfs('ls --help') - .then((out) => { - expect(out.split('\n').slice(1)).to.eql(['', - 'List files for the given directory', - '', - 'Options:', - ' --version Show version number [boolean]', - ' --silent Write no output [boolean] [default: false]', - ' --pass Pass phrase for the keys [string] [default: ""]', - ' --help Show help [boolean]', - ' -v, --headers Print table headers (Hash, Size, Name).', - ' [boolean] [default: false]', - ' --resolve-type Resolve linked objects to find out their types. (not', - ' implemented yet) [boolean] [default: false]', - '', '']) - }) + }) + }) }) + it('get', function () { this.timeout(20 * 1000) From fb18080ba064cfb719e1a949e245b4f4ca250365 Mon Sep 17 00:00:00 2001 From: jkrone Date: Tue, 13 Feb 2018 18:35:56 -0600 Subject: [PATCH 08/20] adjust padding to account for subdirs, add ls -r test for same. --- src/cli/commands/ls.js | 3 ++- test/cli/files.js | 38 ++++++++++++++++++++++---------------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/cli/commands/ls.js b/src/cli/commands/ls.js index e21f752b87..cf63dde2e1 100644 --- a/src/cli/commands/ls.js +++ b/src/cli/commands/ls.js @@ -47,10 +47,11 @@ module.exports = { links.forEach(link => { const fileName = link.type === 'dir' ? `${link.name || ''}/` : link.name + const padding = link.depth - path.split('/').length utils.print( utils.rightpad(link.hash, multihashWidth + 1) + utils.rightpad(link.size || '', sizeWidth + 1) + - ' '.repeat((link.depth - 1) * 2) + fileName + ' '.repeat(padding) + fileName ) }) }) diff --git a/test/cli/files.js b/test/cli/files.js index 062070f121..daa352ac90 100644 --- a/test/cli/files.js +++ b/test/cli/files.js @@ -136,7 +136,7 @@ describe('files', () => runOnAndOff((thing) => { }) }) - it.only('add recursively test', function () { + it('add recursively test', function () { this.timeout(60 * 1000) return ipfs('files add -r test/fixtures/test-data/recursive-get-dir') @@ -296,16 +296,12 @@ describe('files', () => runOnAndOff((thing) => { }) }) - describe('ls', () => { - before(() => { - return ipfs('files add -r test/fixtures/test-data/recursive-get-dir') - .then(console.log.bind(console, 'files added:')) - }) + describe.only('ls', () => { + before(() => ipfs('files add -r test/fixtures/test-data/recursive-get-dir')) it('prints added files', function () { this.timeout(20 * 1000) - // old: QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2 - return ipfs('ls QmRyExB6Q2DYGuztKfXC3txxDsRKW8QS9ib7XQM7xy16hx') + return ipfs('ls QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2') .then((out) => { expect(out).to.eql( 'QmQQHYDwAQms78fPcvx1uFFsfho23YJNoewfLbi9AtdyJ9 123530 blocks/\n' + @@ -327,8 +323,7 @@ describe('files', () => runOnAndOff((thing) => { it('adds a header, -v', function () { this.timeout(20 * 1000) - - return ipfs('ls /ipfs/QmRyExB6Q2DYGuztKfXC3txxDsRKW8QS9ib7XQM7xy16hx -v') + return ipfs('ls /ipfs/Qmzzz4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2 -v') .then((out) => { expect(out).to.eql( 'Hash Size Name\n' + @@ -344,7 +339,7 @@ describe('files', () => runOnAndOff((thing) => { it('follows a path, ls ', function () { this.timeout(20 * 1000) - return ipfs('ls /ipfs/QmRyExB6Q2DYGuztKfXC3txxDsRKW8QS9ib7XQM7xy16hx/init-docs') + return ipfs('ls /ipfs/QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2/init-docs') .then((out) => { expect(out).to.eql( 'QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V 1688 about\n' + @@ -360,13 +355,24 @@ describe('files', () => runOnAndOff((thing) => { }) it('recursively follows folders, -r', function() { + this.slow(2000) this.timeout(20 * 1000) - return ipfs('ls -r /ipfs/QmRyExB6Q2DYGuztKfXC3txxDsRKW8QS9ib7XQM7xy16hx/init-docs') - .then(out => { - console.log('output from ls -r:', out) - - }) + return ipfs('ls -r /ipfs/QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2/init-docs') + .then(out => + expect(out).to.eql( +`QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V 1688 about +QmYCvbfNbCwFR45HiNP45rwJgvatpiW38D961L5qAhUM5Y 200 contact +QmegvLXxpVKiZ4b57Xs1syfBVRd8CbucVHAp7KpLQdGieC 65 docs/ +QmQN88TEidd3RY2u3dpib49fERTDfKtDpvxnvczATNsfKT 14 index +QmY5heUM5qgRubMDD1og9fhCPA6QdkMp3QCwd4s7gJsyE7 322 help +QmdncfsVm2h5Kqq9hPmU7oAVX2zTSVP3L869tgTbPYnsha 1728 quick-start +QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB 1102 readme +QmTumTjvcYCAvRRwQ8sDRxh8ezmrcr88YFU7iYNroGGTBZ 1027 security-notes +QmciSU8hfpAXKjvK5YLUSwApomGSWN5gFbP4EpDAEzu2Te 863 tour/ +QmYE7xo6NxbHEVEHej1yzxijYaNY51BaeKxjXxn6Ssa6Bs 807 0.0-intro +`) + ) }) }) From 74ba38ac8589bbfff64f9f59ceec4f79c4f2df10 Mon Sep 17 00:00:00 2001 From: jkrone Date: Tue, 13 Feb 2018 19:25:29 -0600 Subject: [PATCH 09/20] don't overwrite error response --- src/http/api/resources/files.js | 2 +- test/cli/files.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/http/api/resources/files.js b/src/http/api/resources/files.js index 033634b009..bcd5cea081 100644 --- a/src/http/api/resources/files.js +++ b/src/http/api/resources/files.js @@ -277,7 +277,7 @@ exports.immutableLs = { ipfs.ls(key, { recursive: recursive }, (err, files) => { if (err) { - reply({ + return reply({ Message: 'Failed to list dir: ' + err.message, Code: 0 }).code(500) diff --git a/test/cli/files.js b/test/cli/files.js index daa352ac90..b03d08c911 100644 --- a/test/cli/files.js +++ b/test/cli/files.js @@ -323,7 +323,7 @@ describe('files', () => runOnAndOff((thing) => { it('adds a header, -v', function () { this.timeout(20 * 1000) - return ipfs('ls /ipfs/Qmzzz4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2 -v') + return ipfs('ls /ipfs/QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2 -v') .then((out) => { expect(out).to.eql( 'Hash Size Name\n' + From 50ac0dc5e1273024a0f41acd0f5bad61647aef62 Mon Sep 17 00:00:00 2001 From: jkrone Date: Tue, 13 Feb 2018 22:27:29 -0600 Subject: [PATCH 10/20] copy ls test to test/cli/ls, might remove or dedupe files ls tests. --- test/cli/ls.js | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/test/cli/ls.js b/test/cli/ls.js index e69de29bb2..fbf422c4f3 100644 --- a/test/cli/ls.js +++ b/test/cli/ls.js @@ -0,0 +1,90 @@ +/* eslint-env mocha */ +'use strict' + +const expect = require('chai').expect +const runOnAndOff = require('../utils/on-and-off') + +describe('ls', () => runOnAndOff((thing) => { + let ipfs + + before(() => { + ipfs = thing.ipfs + return ipfs('files add -r test/fixtures/test-data/recursive-get-dir') + }) + + it('prints added files', function () { + this.timeout(20 * 1000) + return ipfs('ls QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2') + .then((out) => { + expect(out).to.eql( + 'QmQQHYDwAQms78fPcvx1uFFsfho23YJNoewfLbi9AtdyJ9 123530 blocks/\n' + + 'QmPkWYfSLCEBLZu7BZt4kigGDMe3cpogMbeVf97gN2xJDN 3939 config\n' + + 'Qma13ZrhKG52MWnwtZ6fMD8jGj8d4Q9sJgn5xtKgeZw5uz 5503 datastore/\n' + + 'QmUhUuiTKkkK8J6JZ9zmj8iNHPuNfGYcszgRumzhHBxEEU 7397 init-docs/\n' + + 'QmR56UJmAaZLXLdTT1ALrE9vVqV8soUEekm9BMd4FnuYqV 10 version\n') + }) + }) + + it(`prints nothing for non-existant hashes`, function(done) { + this.slow(3200) + setTimeout(done, 3000) + ipfs('ls QmYmW4HiZhotsoSqnv2o1oSssvkRM8b9RweBoH7ao5nki2') + .then(() => done( + new Error('ipfs ls found something when it should not have') + )) + }) + + it('adds a header, -v', function () { + this.timeout(20 * 1000) + return ipfs('ls /ipfs/QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2 -v') + .then((out) => { + expect(out).to.eql( + 'Hash Size Name\n' + + 'QmQQHYDwAQms78fPcvx1uFFsfho23YJNoewfLbi9AtdyJ9 123530 blocks/\n' + + 'QmPkWYfSLCEBLZu7BZt4kigGDMe3cpogMbeVf97gN2xJDN 3939 config\n' + + 'Qma13ZrhKG52MWnwtZ6fMD8jGj8d4Q9sJgn5xtKgeZw5uz 5503 datastore/\n' + + 'QmUhUuiTKkkK8J6JZ9zmj8iNHPuNfGYcszgRumzhHBxEEU 7397 init-docs/\n' + + 'QmR56UJmAaZLXLdTT1ALrE9vVqV8soUEekm9BMd4FnuYqV 10 version\n' + ) + }) + }) + + it('follows a path, ls ', function () { + this.timeout(20 * 1000) + + return ipfs('ls /ipfs/QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2/init-docs') + .then((out) => { + expect(out).to.eql( + 'QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V 1688 about\n' + + 'QmYCvbfNbCwFR45HiNP45rwJgvatpiW38D961L5qAhUM5Y 200 contact\n' + + 'QmegvLXxpVKiZ4b57Xs1syfBVRd8CbucVHAp7KpLQdGieC 65 docs/\n' + + 'QmY5heUM5qgRubMDD1og9fhCPA6QdkMp3QCwd4s7gJsyE7 322 help\n' + + 'QmdncfsVm2h5Kqq9hPmU7oAVX2zTSVP3L869tgTbPYnsha 1728 quick-start\n' + + 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB 1102 readme\n' + + 'QmTumTjvcYCAvRRwQ8sDRxh8ezmrcr88YFU7iYNroGGTBZ 1027 security-notes\n' + + 'QmciSU8hfpAXKjvK5YLUSwApomGSWN5gFbP4EpDAEzu2Te 863 tour/\n' + ) + }) + }) + + it('recursively follows folders, -r', function() { + this.slow(2000) + this.timeout(20 * 1000) + + return ipfs('ls -r /ipfs/QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2/init-docs') + .then(out => + expect(out).to.eql( +`QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V 1688 about +QmYCvbfNbCwFR45HiNP45rwJgvatpiW38D961L5qAhUM5Y 200 contact +QmegvLXxpVKiZ4b57Xs1syfBVRd8CbucVHAp7KpLQdGieC 65 docs/ +QmQN88TEidd3RY2u3dpib49fERTDfKtDpvxnvczATNsfKT 14 index +QmY5heUM5qgRubMDD1og9fhCPA6QdkMp3QCwd4s7gJsyE7 322 help +QmdncfsVm2h5Kqq9hPmU7oAVX2zTSVP3L869tgTbPYnsha 1728 quick-start +QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB 1102 readme +QmTumTjvcYCAvRRwQ8sDRxh8ezmrcr88YFU7iYNroGGTBZ 1027 security-notes +QmciSU8hfpAXKjvK5YLUSwApomGSWN5gFbP4EpDAEzu2Te 863 tour/ +QmYE7xo6NxbHEVEHej1yzxijYaNY51BaeKxjXxn6Ssa6Bs 807 0.0-intro +`) + ) + }) +})) From 0c818b780176c69629117ec1ca15b0826b5efbf2 Mon Sep 17 00:00:00 2001 From: jkrone Date: Wed, 14 Feb 2018 12:02:40 -0500 Subject: [PATCH 11/20] clean tests. Gotta take another look at files ls vs ls --- src/cli/bin.js | 5 ++- test/cli/files.js | 89 ++++++----------------------------------------- test/cli/ls.js | 43 ++++++++++++----------- 3 files changed, 34 insertions(+), 103 deletions(-) diff --git a/src/cli/bin.js b/src/cli/bin.js index 72fc1d1ecc..67e60f8362 100755 --- a/src/cli/bin.js +++ b/src/cli/bin.js @@ -36,13 +36,12 @@ const cli = yargs }) // NOTE: This creates an alias of -// `jsipfs files {add, get, cat, ls}` to `jsipfs {add, get, cat, ls}`. +// `jsipfs files {add, get, cat}` to `jsipfs {add, get, cat}`. // This will stay until https://github.com/ipfs/specs/issues/98 is resolved. const addCmd = require('./commands/files/add') const catCmd = require('./commands/files/cat') const getCmd = require('./commands/files/get') -// const lsCmd = require('./commands/files/ls') -const aliases = [addCmd, catCmd, getCmd /*, lsCmd */] +const aliases = [addCmd, catCmd, getCmd] aliases.forEach((alias) => { cli.command(alias.command, alias.describe, alias.builder, alias.handler) }) diff --git a/test/cli/files.js b/test/cli/files.js index b03d08c911..e836f9c9e8 100644 --- a/test/cli/files.js +++ b/test/cli/files.js @@ -296,87 +296,18 @@ describe('files', () => runOnAndOff((thing) => { }) }) - describe.only('ls', () => { - before(() => ipfs('files add -r test/fixtures/test-data/recursive-get-dir')) - - it('prints added files', function () { - this.timeout(20 * 1000) - return ipfs('ls QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2') - .then((out) => { - expect(out).to.eql( - 'QmQQHYDwAQms78fPcvx1uFFsfho23YJNoewfLbi9AtdyJ9 123530 blocks/\n' + - 'QmPkWYfSLCEBLZu7BZt4kigGDMe3cpogMbeVf97gN2xJDN 3939 config\n' + - 'Qma13ZrhKG52MWnwtZ6fMD8jGj8d4Q9sJgn5xtKgeZw5uz 5503 datastore/\n' + - 'QmUhUuiTKkkK8J6JZ9zmj8iNHPuNfGYcszgRumzhHBxEEU 7397 init-docs/\n' + - 'QmR56UJmAaZLXLdTT1ALrE9vVqV8soUEekm9BMd4FnuYqV 10 version\n') - }) - }) - - it(`prints nothing for non-existant hashes`, function(done) { - this.slow(3200) - setTimeout(done, 3000) - ipfs('ls QmYmW4HiZhotsoSqnv2o1oSssvkRM8b9RweBoH7ao5nki2') - .then(() => done( - new Error('ipfs ls found something when it should not have') - )) - }) - - it('adds a header, -v', function () { - this.timeout(20 * 1000) - return ipfs('ls /ipfs/QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2 -v') - .then((out) => { - expect(out).to.eql( - 'Hash Size Name\n' + - 'QmQQHYDwAQms78fPcvx1uFFsfho23YJNoewfLbi9AtdyJ9 123530 blocks/\n' + - 'QmPkWYfSLCEBLZu7BZt4kigGDMe3cpogMbeVf97gN2xJDN 3939 config\n' + - 'Qma13ZrhKG52MWnwtZ6fMD8jGj8d4Q9sJgn5xtKgeZw5uz 5503 datastore/\n' + - 'QmUhUuiTKkkK8J6JZ9zmj8iNHPuNfGYcszgRumzhHBxEEU 7397 init-docs/\n' + - 'QmR56UJmAaZLXLdTT1ALrE9vVqV8soUEekm9BMd4FnuYqV 10 version\n' - ) - }) - }) - - it('follows a path, ls ', function () { - this.timeout(20 * 1000) - - return ipfs('ls /ipfs/QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2/init-docs') - .then((out) => { - expect(out).to.eql( - 'QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V 1688 about\n' + - 'QmYCvbfNbCwFR45HiNP45rwJgvatpiW38D961L5qAhUM5Y 200 contact\n' + - 'QmegvLXxpVKiZ4b57Xs1syfBVRd8CbucVHAp7KpLQdGieC 65 docs/\n' + - 'QmY5heUM5qgRubMDD1og9fhCPA6QdkMp3QCwd4s7gJsyE7 322 help\n' + - 'QmdncfsVm2h5Kqq9hPmU7oAVX2zTSVP3L869tgTbPYnsha 1728 quick-start\n' + - 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB 1102 readme\n' + - 'QmTumTjvcYCAvRRwQ8sDRxh8ezmrcr88YFU7iYNroGGTBZ 1027 security-notes\n' + - 'QmciSU8hfpAXKjvK5YLUSwApomGSWN5gFbP4EpDAEzu2Te 863 tour/\n' - ) - }) - }) - - it('recursively follows folders, -r', function() { - this.slow(2000) - this.timeout(20 * 1000) - - return ipfs('ls -r /ipfs/QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2/init-docs') - .then(out => - expect(out).to.eql( -`QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V 1688 about -QmYCvbfNbCwFR45HiNP45rwJgvatpiW38D961L5qAhUM5Y 200 contact -QmegvLXxpVKiZ4b57Xs1syfBVRd8CbucVHAp7KpLQdGieC 65 docs/ -QmQN88TEidd3RY2u3dpib49fERTDfKtDpvxnvczATNsfKT 14 index -QmY5heUM5qgRubMDD1og9fhCPA6QdkMp3QCwd4s7gJsyE7 322 help -QmdncfsVm2h5Kqq9hPmU7oAVX2zTSVP3L869tgTbPYnsha 1728 quick-start -QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB 1102 readme -QmTumTjvcYCAvRRwQ8sDRxh8ezmrcr88YFU7iYNroGGTBZ 1027 security-notes -QmciSU8hfpAXKjvK5YLUSwApomGSWN5gFbP4EpDAEzu2Te 863 tour/ -QmYE7xo6NxbHEVEHej1yzxijYaNY51BaeKxjXxn6Ssa6Bs 807 0.0-intro -`) - ) - }) + it('has an alias to ipfs ls', () => { + return ipfs('files ls QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2') + .then(out => { + expect(out).to.eql( + 'QmQQHYDwAQms78fPcvx1uFFsfho23YJNoewfLbi9AtdyJ9 123530 blocks/\n' + + 'QmPkWYfSLCEBLZu7BZt4kigGDMe3cpogMbeVf97gN2xJDN 3939 config\n' + + 'Qma13ZrhKG52MWnwtZ6fMD8jGj8d4Q9sJgn5xtKgeZw5uz 5503 datastore/\n' + + 'QmUhUuiTKkkK8J6JZ9zmj8iNHPuNfGYcszgRumzhHBxEEU 7397 init-docs/\n' + + 'QmR56UJmAaZLXLdTT1ALrE9vVqV8soUEekm9BMd4FnuYqV 10 version\n') + }) }) - it('get', function () { this.timeout(20 * 1000) diff --git a/test/cli/ls.js b/test/cli/ls.js index fbf422c4f3..e88dbf07e8 100644 --- a/test/cli/ls.js +++ b/test/cli/ls.js @@ -17,11 +17,12 @@ describe('ls', () => runOnAndOff((thing) => { return ipfs('ls QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2') .then((out) => { expect(out).to.eql( - 'QmQQHYDwAQms78fPcvx1uFFsfho23YJNoewfLbi9AtdyJ9 123530 blocks/\n' + - 'QmPkWYfSLCEBLZu7BZt4kigGDMe3cpogMbeVf97gN2xJDN 3939 config\n' + - 'Qma13ZrhKG52MWnwtZ6fMD8jGj8d4Q9sJgn5xtKgeZw5uz 5503 datastore/\n' + - 'QmUhUuiTKkkK8J6JZ9zmj8iNHPuNfGYcszgRumzhHBxEEU 7397 init-docs/\n' + - 'QmR56UJmAaZLXLdTT1ALrE9vVqV8soUEekm9BMd4FnuYqV 10 version\n') +`QmQQHYDwAQms78fPcvx1uFFsfho23YJNoewfLbi9AtdyJ9 123530 blocks/ +QmPkWYfSLCEBLZu7BZt4kigGDMe3cpogMbeVf97gN2xJDN 3939 config +Qma13ZrhKG52MWnwtZ6fMD8jGj8d4Q9sJgn5xtKgeZw5uz 5503 datastore/ +QmUhUuiTKkkK8J6JZ9zmj8iNHPuNfGYcszgRumzhHBxEEU 7397 init-docs/ +QmR56UJmAaZLXLdTT1ALrE9vVqV8soUEekm9BMd4FnuYqV 10 version +`) }) }) @@ -39,13 +40,13 @@ describe('ls', () => runOnAndOff((thing) => { return ipfs('ls /ipfs/QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2 -v') .then((out) => { expect(out).to.eql( - 'Hash Size Name\n' + - 'QmQQHYDwAQms78fPcvx1uFFsfho23YJNoewfLbi9AtdyJ9 123530 blocks/\n' + - 'QmPkWYfSLCEBLZu7BZt4kigGDMe3cpogMbeVf97gN2xJDN 3939 config\n' + - 'Qma13ZrhKG52MWnwtZ6fMD8jGj8d4Q9sJgn5xtKgeZw5uz 5503 datastore/\n' + - 'QmUhUuiTKkkK8J6JZ9zmj8iNHPuNfGYcszgRumzhHBxEEU 7397 init-docs/\n' + - 'QmR56UJmAaZLXLdTT1ALrE9vVqV8soUEekm9BMd4FnuYqV 10 version\n' - ) +`Hash Size Name +QmQQHYDwAQms78fPcvx1uFFsfho23YJNoewfLbi9AtdyJ9 123530 blocks/ +QmPkWYfSLCEBLZu7BZt4kigGDMe3cpogMbeVf97gN2xJDN 3939 config +Qma13ZrhKG52MWnwtZ6fMD8jGj8d4Q9sJgn5xtKgeZw5uz 5503 datastore/ +QmUhUuiTKkkK8J6JZ9zmj8iNHPuNfGYcszgRumzhHBxEEU 7397 init-docs/ +QmR56UJmAaZLXLdTT1ALrE9vVqV8soUEekm9BMd4FnuYqV 10 version +`) }) }) @@ -55,15 +56,15 @@ describe('ls', () => runOnAndOff((thing) => { return ipfs('ls /ipfs/QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2/init-docs') .then((out) => { expect(out).to.eql( - 'QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V 1688 about\n' + - 'QmYCvbfNbCwFR45HiNP45rwJgvatpiW38D961L5qAhUM5Y 200 contact\n' + - 'QmegvLXxpVKiZ4b57Xs1syfBVRd8CbucVHAp7KpLQdGieC 65 docs/\n' + - 'QmY5heUM5qgRubMDD1og9fhCPA6QdkMp3QCwd4s7gJsyE7 322 help\n' + - 'QmdncfsVm2h5Kqq9hPmU7oAVX2zTSVP3L869tgTbPYnsha 1728 quick-start\n' + - 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB 1102 readme\n' + - 'QmTumTjvcYCAvRRwQ8sDRxh8ezmrcr88YFU7iYNroGGTBZ 1027 security-notes\n' + - 'QmciSU8hfpAXKjvK5YLUSwApomGSWN5gFbP4EpDAEzu2Te 863 tour/\n' - ) +`QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V 1688 about +QmYCvbfNbCwFR45HiNP45rwJgvatpiW38D961L5qAhUM5Y 200 contact +QmegvLXxpVKiZ4b57Xs1syfBVRd8CbucVHAp7KpLQdGieC 65 docs/ +QmY5heUM5qgRubMDD1og9fhCPA6QdkMp3QCwd4s7gJsyE7 322 help +QmdncfsVm2h5Kqq9hPmU7oAVX2zTSVP3L869tgTbPYnsha 1728 quick-start +QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB 1102 readme +QmTumTjvcYCAvRRwQ8sDRxh8ezmrcr88YFU7iYNroGGTBZ 1027 security-notes +QmciSU8hfpAXKjvK5YLUSwApomGSWN5gFbP4EpDAEzu2Te 863 tour/ +`) }) }) From b3d254c2e70c67233d79c2622b545bf6a94a806b Mon Sep 17 00:00:00 2001 From: jkrone Date: Wed, 14 Feb 2018 18:39:31 -0500 Subject: [PATCH 12/20] remove files ls --- src/cli/commands/files/ls.js | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 src/cli/commands/files/ls.js diff --git a/src/cli/commands/files/ls.js b/src/cli/commands/files/ls.js deleted file mode 100644 index 437788381f..0000000000 --- a/src/cli/commands/files/ls.js +++ /dev/null @@ -1,29 +0,0 @@ -'use strict' - -const print = require('../../utils').print - -module.exports = { - command: 'ls ', - - describe: 'List directory contents for Unix filesystem objects.', - - builder: { - - }, - - handler (argv) { - let path = argv.key - argv.ipfs.files.ls(path, (err, links) => { - if (err) { - throw err - } - - // Single file? Then print its hash - if (links.length === 0) { - links = [{hash: path}] - } - - links.forEach((file) => print(file.hash)) - }) - } -} From 68d1724320ba3bbaf2234869d2275b9e1ffc0093 Mon Sep 17 00:00:00 2001 From: jkrone Date: Thu, 15 Feb 2018 13:42:45 -0500 Subject: [PATCH 13/20] convert files parseArgs to use CIDs, --- src/cli/commands/files.js | 1 - src/http/api/resources/files.js | 10 ++++------ test/cli/files.js | 12 ------------ 3 files changed, 4 insertions(+), 19 deletions(-) diff --git a/src/cli/commands/files.js b/src/cli/commands/files.js index e9ac95d657..cfb26545ed 100644 --- a/src/cli/commands/files.js +++ b/src/cli/commands/files.js @@ -2,7 +2,6 @@ const print = require('../utils').print - module.exports = { command: 'files ', diff --git a/src/http/api/resources/files.js b/src/http/api/resources/files.js index bcd5cea081..ff2d51c953 100644 --- a/src/http/api/resources/files.js +++ b/src/http/api/resources/files.js @@ -1,6 +1,7 @@ 'use strict' const mh = require('multihashes') +const CID = require('cids') const multipart = require('ipfs-multipart') const debug = require('debug') const tar = require('tar-stream') @@ -37,8 +38,9 @@ exports.parseKey = (request, reply) => { } try { - // TODO make CID. ref: block.js - mh.fromB58String(key) + return reply({ + key: new CID(key) + }) } catch (err) { log.error(err) return reply({ @@ -46,10 +48,6 @@ exports.parseKey = (request, reply) => { Code: 0 }).code(500).takeover() } - - reply({ - key: request.query.arg - }) } exports.cat = { diff --git a/test/cli/files.js b/test/cli/files.js index e836f9c9e8..b2d317abd3 100644 --- a/test/cli/files.js +++ b/test/cli/files.js @@ -296,18 +296,6 @@ describe('files', () => runOnAndOff((thing) => { }) }) - it('has an alias to ipfs ls', () => { - return ipfs('files ls QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2') - .then(out => { - expect(out).to.eql( - 'QmQQHYDwAQms78fPcvx1uFFsfho23YJNoewfLbi9AtdyJ9 123530 blocks/\n' + - 'QmPkWYfSLCEBLZu7BZt4kigGDMe3cpogMbeVf97gN2xJDN 3939 config\n' + - 'Qma13ZrhKG52MWnwtZ6fMD8jGj8d4Q9sJgn5xtKgeZw5uz 5503 datastore/\n' + - 'QmUhUuiTKkkK8J6JZ9zmj8iNHPuNfGYcszgRumzhHBxEEU 7397 init-docs/\n' + - 'QmR56UJmAaZLXLdTT1ALrE9vVqV8soUEekm9BMd4FnuYqV 10 version\n') - }) - }) - it('get', function () { this.timeout(20 * 1000) From e695b2da85cbc17012d08d8430fd0730a1dafa7a Mon Sep 17 00:00:00 2001 From: jkrone Date: Thu, 15 Feb 2018 15:46:50 -0500 Subject: [PATCH 14/20] clean tests, migrate mh to CID, takeover an error http response. --- src/http/api/resources/files.js | 10 ++++++---- test/cli/file.js | 6 +++++- test/cli/ls.js | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/http/api/resources/files.js b/src/http/api/resources/files.js index ff2d51c953..bf8434fe95 100644 --- a/src/http/api/resources/files.js +++ b/src/http/api/resources/files.js @@ -38,9 +38,7 @@ exports.parseKey = (request, reply) => { } try { - return reply({ - key: new CID(key) - }) + new CID(key) } catch (err) { log.error(err) return reply({ @@ -48,6 +46,10 @@ exports.parseKey = (request, reply) => { Code: 0 }).code(500).takeover() } + + return reply({ + key: request.query.arg + }) } exports.cat = { @@ -278,7 +280,7 @@ exports.immutableLs = { return reply({ Message: 'Failed to list dir: ' + err.message, Code: 0 - }).code(500) + }).code(500).takeover() } reply({ diff --git a/test/cli/file.js b/test/cli/file.js index 59ab531f6d..afe4d98db0 100644 --- a/test/cli/file.js +++ b/test/cli/file.js @@ -17,12 +17,16 @@ describe('file ls', () => runOnAndOff((thing) => { it('prints a filename', () => { return ipfs(`file ls ${file}`) - .then((out) => expect(out).to.eql(`${file}\n`)) + .then((out) => expect(out).to.eql( + `This functionality is deprecated, and will be removed in future versions. If possible, please use 'ipfs ls' instead.\n` + + `${file}\n` + )) }) it('prints the filenames in a directory', () => { return ipfs(`file ls ${dir}`) .then((out) => expect(out).to.eql( + `This functionality is deprecated, and will be removed in future versions. If possible, please use 'ipfs ls' instead.\n` + 'QmQQHYDwAQms78fPcvx1uFFsfho23YJNoewfLbi9AtdyJ9\n' + 'QmPkWYfSLCEBLZu7BZt4kigGDMe3cpogMbeVf97gN2xJDN\n' + 'Qma13ZrhKG52MWnwtZ6fMD8jGj8d4Q9sJgn5xtKgeZw5uz\n' + diff --git a/test/cli/ls.js b/test/cli/ls.js index e88dbf07e8..43a4f4545c 100644 --- a/test/cli/ls.js +++ b/test/cli/ls.js @@ -50,7 +50,7 @@ QmR56UJmAaZLXLdTT1ALrE9vVqV8soUEekm9BMd4FnuYqV 10 version }) }) - it('follows a path, ls ', function () { + it('follows a path, /', function () { this.timeout(20 * 1000) return ipfs('ls /ipfs/QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2/init-docs') From f12b416cef0366781c5c565fa8228a39ff0c291a Mon Sep 17 00:00:00 2001 From: jkrone Date: Thu, 15 Feb 2018 16:13:39 -0500 Subject: [PATCH 15/20] clean --- src/http/api/resources/file.js | 1 - src/http/api/resources/files.js | 1 - 2 files changed, 2 deletions(-) diff --git a/src/http/api/resources/file.js b/src/http/api/resources/file.js index e677e25e12..6c0b6b4c4c 100644 --- a/src/http/api/resources/file.js +++ b/src/http/api/resources/file.js @@ -72,7 +72,6 @@ exports.ls = { // uses common parseKey method that returns a `key` parseArgs: exports.parseKey, - // TODO What is this? // main route handler which is called after the above `parseArgs`, but only if the args were valid handler: (request, reply) => { const path = request.pre.args.path diff --git a/src/http/api/resources/files.js b/src/http/api/resources/files.js index bf8434fe95..55721408df 100644 --- a/src/http/api/resources/files.js +++ b/src/http/api/resources/files.js @@ -1,6 +1,5 @@ 'use strict' -const mh = require('multihashes') const CID = require('cids') const multipart = require('ipfs-multipart') const debug = require('debug') From dd202fc407b6e059b0957f6d07bede1f27b71548 Mon Sep 17 00:00:00 2001 From: jkrone Date: Thu, 15 Feb 2018 16:35:51 -0500 Subject: [PATCH 16/20] lint fixes --- src/http/api/resources/files.js | 6 +-- test/cli/ls.js | 74 ++++++++++++++++----------------- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/src/http/api/resources/files.js b/src/http/api/resources/files.js index 55721408df..55c406d86c 100644 --- a/src/http/api/resources/files.js +++ b/src/http/api/resources/files.js @@ -1,6 +1,6 @@ 'use strict' -const CID = require('cids') +const mh = require('multihashes') const multipart = require('ipfs-multipart') const debug = require('debug') const tar = require('tar-stream') @@ -37,7 +37,7 @@ exports.parseKey = (request, reply) => { } try { - new CID(key) + mh.fromB58String(key) } catch (err) { log.error(err) return reply({ @@ -46,7 +46,7 @@ exports.parseKey = (request, reply) => { }).code(500).takeover() } - return reply({ + reply({ key: request.query.arg }) } diff --git a/test/cli/ls.js b/test/cli/ls.js index 43a4f4545c..cb737d6820 100644 --- a/test/cli/ls.js +++ b/test/cli/ls.js @@ -17,16 +17,16 @@ describe('ls', () => runOnAndOff((thing) => { return ipfs('ls QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2') .then((out) => { expect(out).to.eql( -`QmQQHYDwAQms78fPcvx1uFFsfho23YJNoewfLbi9AtdyJ9 123530 blocks/ -QmPkWYfSLCEBLZu7BZt4kigGDMe3cpogMbeVf97gN2xJDN 3939 config -Qma13ZrhKG52MWnwtZ6fMD8jGj8d4Q9sJgn5xtKgeZw5uz 5503 datastore/ -QmUhUuiTKkkK8J6JZ9zmj8iNHPuNfGYcszgRumzhHBxEEU 7397 init-docs/ -QmR56UJmAaZLXLdTT1ALrE9vVqV8soUEekm9BMd4FnuYqV 10 version -`) + 'QmQQHYDwAQms78fPcvx1uFFsfho23YJNoewfLbi9AtdyJ9 123530 blocks/\n' + + 'QmPkWYfSLCEBLZu7BZt4kigGDMe3cpogMbeVf97gN2xJDN 3939 config\n' + + 'Qma13ZrhKG52MWnwtZ6fMD8jGj8d4Q9sJgn5xtKgeZw5uz 5503 datastore/\n' + + 'QmUhUuiTKkkK8J6JZ9zmj8iNHPuNfGYcszgRumzhHBxEEU 7397 init-docs/\n' + + 'QmR56UJmAaZLXLdTT1ALrE9vVqV8soUEekm9BMd4FnuYqV 10 version\n' + ) }) }) - it(`prints nothing for non-existant hashes`, function(done) { + it(`prints nothing for non-existant hashes`, function (done) { this.slow(3200) setTimeout(done, 3000) ipfs('ls QmYmW4HiZhotsoSqnv2o1oSssvkRM8b9RweBoH7ao5nki2') @@ -40,13 +40,13 @@ QmR56UJmAaZLXLdTT1ALrE9vVqV8soUEekm9BMd4FnuYqV 10 version return ipfs('ls /ipfs/QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2 -v') .then((out) => { expect(out).to.eql( -`Hash Size Name -QmQQHYDwAQms78fPcvx1uFFsfho23YJNoewfLbi9AtdyJ9 123530 blocks/ -QmPkWYfSLCEBLZu7BZt4kigGDMe3cpogMbeVf97gN2xJDN 3939 config -Qma13ZrhKG52MWnwtZ6fMD8jGj8d4Q9sJgn5xtKgeZw5uz 5503 datastore/ -QmUhUuiTKkkK8J6JZ9zmj8iNHPuNfGYcszgRumzhHBxEEU 7397 init-docs/ -QmR56UJmAaZLXLdTT1ALrE9vVqV8soUEekm9BMd4FnuYqV 10 version -`) + 'Hash Size Name\n' + + 'QmQQHYDwAQms78fPcvx1uFFsfho23YJNoewfLbi9AtdyJ9 123530 blocks/\n' + + 'QmPkWYfSLCEBLZu7BZt4kigGDMe3cpogMbeVf97gN2xJDN 3939 config\n' + + 'Qma13ZrhKG52MWnwtZ6fMD8jGj8d4Q9sJgn5xtKgeZw5uz 5503 datastore/\n' + + 'QmUhUuiTKkkK8J6JZ9zmj8iNHPuNfGYcszgRumzhHBxEEU 7397 init-docs/\n' + + 'QmR56UJmAaZLXLdTT1ALrE9vVqV8soUEekm9BMd4FnuYqV 10 version\n' + ) }) }) @@ -56,36 +56,36 @@ QmR56UJmAaZLXLdTT1ALrE9vVqV8soUEekm9BMd4FnuYqV 10 version return ipfs('ls /ipfs/QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2/init-docs') .then((out) => { expect(out).to.eql( -`QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V 1688 about -QmYCvbfNbCwFR45HiNP45rwJgvatpiW38D961L5qAhUM5Y 200 contact -QmegvLXxpVKiZ4b57Xs1syfBVRd8CbucVHAp7KpLQdGieC 65 docs/ -QmY5heUM5qgRubMDD1og9fhCPA6QdkMp3QCwd4s7gJsyE7 322 help -QmdncfsVm2h5Kqq9hPmU7oAVX2zTSVP3L869tgTbPYnsha 1728 quick-start -QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB 1102 readme -QmTumTjvcYCAvRRwQ8sDRxh8ezmrcr88YFU7iYNroGGTBZ 1027 security-notes -QmciSU8hfpAXKjvK5YLUSwApomGSWN5gFbP4EpDAEzu2Te 863 tour/ -`) + 'QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V 1688 about\n' + + 'QmYCvbfNbCwFR45HiNP45rwJgvatpiW38D961L5qAhUM5Y 200 contact\n' + + 'QmegvLXxpVKiZ4b57Xs1syfBVRd8CbucVHAp7KpLQdGieC 65 docs/\n' + + 'QmY5heUM5qgRubMDD1og9fhCPA6QdkMp3QCwd4s7gJsyE7 322 help\n' + + 'QmdncfsVm2h5Kqq9hPmU7oAVX2zTSVP3L869tgTbPYnsha 1728 quick-start\n' + + 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB 1102 readme\n' + + 'QmTumTjvcYCAvRRwQ8sDRxh8ezmrcr88YFU7iYNroGGTBZ 1027 security-notes\n' + + 'QmciSU8hfpAXKjvK5YLUSwApomGSWN5gFbP4EpDAEzu2Te 863 tour/\n' + ) }) }) - it('recursively follows folders, -r', function() { + it('recursively follows folders, -r', function () { this.slow(2000) this.timeout(20 * 1000) return ipfs('ls -r /ipfs/QmYmW4HiZhotsoSqnv2o1oUusvkRM8b9RweBoH7ao5nki2/init-docs') - .then(out => + .then(out => { expect(out).to.eql( -`QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V 1688 about -QmYCvbfNbCwFR45HiNP45rwJgvatpiW38D961L5qAhUM5Y 200 contact -QmegvLXxpVKiZ4b57Xs1syfBVRd8CbucVHAp7KpLQdGieC 65 docs/ -QmQN88TEidd3RY2u3dpib49fERTDfKtDpvxnvczATNsfKT 14 index -QmY5heUM5qgRubMDD1og9fhCPA6QdkMp3QCwd4s7gJsyE7 322 help -QmdncfsVm2h5Kqq9hPmU7oAVX2zTSVP3L869tgTbPYnsha 1728 quick-start -QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB 1102 readme -QmTumTjvcYCAvRRwQ8sDRxh8ezmrcr88YFU7iYNroGGTBZ 1027 security-notes -QmciSU8hfpAXKjvK5YLUSwApomGSWN5gFbP4EpDAEzu2Te 863 tour/ -QmYE7xo6NxbHEVEHej1yzxijYaNY51BaeKxjXxn6Ssa6Bs 807 0.0-intro -`) - ) + 'QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V 1688 about\n' + + 'QmYCvbfNbCwFR45HiNP45rwJgvatpiW38D961L5qAhUM5Y 200 contact\n' + + 'QmegvLXxpVKiZ4b57Xs1syfBVRd8CbucVHAp7KpLQdGieC 65 docs/\n' + + 'QmQN88TEidd3RY2u3dpib49fERTDfKtDpvxnvczATNsfKT 14 index\n' + + 'QmY5heUM5qgRubMDD1og9fhCPA6QdkMp3QCwd4s7gJsyE7 322 help\n' + + 'QmdncfsVm2h5Kqq9hPmU7oAVX2zTSVP3L869tgTbPYnsha 1728 quick-start\n' + + 'QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB 1102 readme\n' + + 'QmTumTjvcYCAvRRwQ8sDRxh8ezmrcr88YFU7iYNroGGTBZ 1027 security-notes\n' + + 'QmciSU8hfpAXKjvK5YLUSwApomGSWN5gFbP4EpDAEzu2Te 863 tour/\n' + + 'QmYE7xo6NxbHEVEHej1yzxijYaNY51BaeKxjXxn6Ssa6Bs 807 0.0-intro\n' + ) + }) }) })) From e20c9de137a3b558e321d8030ba59c6783bf5cd1 Mon Sep 17 00:00:00 2001 From: jkrone Date: Fri, 16 Feb 2018 13:01:07 -0500 Subject: [PATCH 17/20] alias 'ipfs files ls' to 'ipfs ls' --- src/cli/commands/files.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cli/commands/files.js b/src/cli/commands/files.js index cfb26545ed..1e24b3c226 100644 --- a/src/cli/commands/files.js +++ b/src/cli/commands/files.js @@ -1,6 +1,7 @@ 'use strict' const print = require('../utils').print +const lsCmd = require('./ls') module.exports = { command: 'files ', @@ -10,6 +11,7 @@ module.exports = { builder (yargs) { return yargs .commandDir('files') + .command(lsCmd) }, handler (argv) { From 7da61267cfd3a6dc1619c4e8939baadcb4ba18b4 Mon Sep 17 00:00:00 2001 From: jkrone Date: Tue, 20 Feb 2018 11:53:49 -0500 Subject: [PATCH 18/20] update ipfs-api dep --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 382d8f7326..ad1c74bbfc 100644 --- a/package.json +++ b/package.json @@ -106,9 +106,9 @@ "hapi": "^16.6.2", "hapi-set-header": "^1.0.2", "hoek": "^5.0.3", - "ipfs-api": "^18.0.0", - "ipfs-bitswap": "~0.19.0", "human-to-milliseconds": "^1.0.0", + "ipfs-api": "^18.1.1", + "ipfs-bitswap": "~0.19.0", "ipfs-block": "~0.6.1", "ipfs-block-service": "~0.13.0", "ipfs-multipart": "~0.1.0", From 303e48015da7df05eaec42455a514fe05a3d8fb4 Mon Sep 17 00:00:00 2001 From: jkrone Date: Tue, 20 Feb 2018 14:20:28 -0500 Subject: [PATCH 19/20] update ls test for non-existant files. Had an unhandled rejection warning. --- test/cli/ls.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/test/cli/ls.js b/test/cli/ls.js index cb737d6820..2db8448e39 100644 --- a/test/cli/ls.js +++ b/test/cli/ls.js @@ -26,13 +26,14 @@ describe('ls', () => runOnAndOff((thing) => { }) }) - it(`prints nothing for non-existant hashes`, function (done) { - this.slow(3200) - setTimeout(done, 3000) - ipfs('ls QmYmW4HiZhotsoSqnv2o1oSssvkRM8b9RweBoH7ao5nki2') - .then(() => done( - new Error('ipfs ls found something when it should not have') - )) + it('prints nothing for non-existant hashes', function (done) { + // If the daemon is off, ls should fail + // If the daemon is on, ls should search until it hits a timeout + return Promise.race([ + ipfs.fail('ls QmYmW4HiZhotsoSqnv2o1oSssvkRM8b9RweBoH7ao5nki2'), + new Promise((res, rej) => setTimeout(res, 4000)) + ]) + .catch(() => expect.fail(0, 1, 'Should have thrown or timedout')) }) it('adds a header, -v', function () { From 5fa1c3dab938f56e5eb162b119dd3f48a036a9cf Mon Sep 17 00:00:00 2001 From: jkrone Date: Tue, 20 Feb 2018 16:22:31 -0500 Subject: [PATCH 20/20] gah! mocha uses the arity of the test function to determine whether the test is cb or promise based?! --- test/cli/ls.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cli/ls.js b/test/cli/ls.js index 2db8448e39..80b75bf342 100644 --- a/test/cli/ls.js +++ b/test/cli/ls.js @@ -26,7 +26,7 @@ describe('ls', () => runOnAndOff((thing) => { }) }) - it('prints nothing for non-existant hashes', function (done) { + it('prints nothing for non-existant hashes', function () { // If the daemon is off, ls should fail // If the daemon is on, ls should search until it hits a timeout return Promise.race([