Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit f613de2

Browse files
committed
use unixfs to check filetype + various cleanup
License: MIT Signed-off-by: Rasmus Erik Voel Jensen <[email protected]>
1 parent b0431ba commit f613de2

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

src/cli/commands/ls.js

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

33
const {print, rightpad} = require('../utils')
4+
const Unixfs = require('ipfs-unixfs')
45

56
module.exports = {
67
command: 'ls',
@@ -15,39 +16,31 @@ module.exports = {
1516
default: false
1617
},
1718
'resolve-type': {
18-
desc: 'Resolve linked objects to find out their types.',
19+
desc: 'Resolve linked objects to find out their types. (not implemented yet)',
1920
type: 'boolean',
20-
default: false // TODO: should be true, false for now, as not implemented
21+
default: false // should be true when implemented
2122
}
2223
},
2324

2425
handler (argv) {
25-
// TODO: should probably be refactored into a src/core/components/ls.js, and also exposed via the HTTP-API?
2626
console.log(argv._.length)
2727
if (argv._.length !== 2) {
28-
// TODO
29-
throw new Error('TODO not implemented yet: no arg => read from stdin, several args ls all of them, with header for each')
28+
throw new Error('Other arguments than single hash not implemented yet.')
3029
}
3130

3231
argv.ipfs.object.get(argv._[1], {enc: 'base58'}, (err, node) => {
3332
if (err) {
34-
// TODO resolve path, to handle addresse like
35-
// QmTkzDwWqPbnAh5YiV5VwcTLnGdwSNsNTn2aDxdXBFca7D/lib
36-
// /ipfs/QmTkzDwWqPbnAh5YiV5VwcTLnGdwSNsNTn2aDxdXBFca7D
37-
// (both fails in js-ipfs, works in go-ipfs)
3833
throw err
3934
}
4035
let {data, links} = node.toJSON()
4136

42-
// TODO: proper way to check type (via unixfs?), not hardcoded here
43-
if (!data || data.length !== 2 ||
44-
data[0] !== 8 || // ??? some multicodec id, or ? find out
45-
data[1] !== 1) { // unixfs directory type
37+
const fileDesc = Unixfs.unmarshal(data)
38+
if (fileDesc.type !== 'directory') {
4639
throw new Error('merkeldag node was not a directory') // TODO: support shards
4740
}
4841

4942
if (argv['resolve-type']) {
50-
throw new Error('--resolve-type not implemented yet') // TODO
43+
throw new Error('--resolve-type not implemented yet')
5144
}
5245

5346
if (argv.headers) {

test/cli/commands.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
const expect = require('chai').expect
55
const runOnAndOff = require('../utils/on-and-off')
66

7-
const commandCount = 56
7+
const commandCount = 57
88

99
describe('commands', () => runOnAndOff((thing) => {
1010
let ipfs

0 commit comments

Comments
 (0)