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

Commit dc1144b

Browse files
authored
Add metadata support (#63)
* chore: dep updated * feat: adds touch and chmod commands and metadata Adds UnixFSv1.5 metadata support to mfs, including displaying it when listing dirs and statting files. Also adds `touch` and `chmod` commands to manipulate metadata in a similar way to the unix shell. * chore: update deps * chore: update deps * test: add cli tests * fix: add missing dep * fix: downgrade repo * fix: fix tests after hashOnly turned to onlyHash * test: add tests for http interface * fix: use multipart pr * chore: remove unecessary browser overrides * chore: update ipfs-utils dep * fix: fix up tests, add support for timespecs * chore: use multipart pr * fix: support optional mtimes
1 parent f533f03 commit dc1144b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+4906
-300
lines changed

package.json

+31-18
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,23 @@
55
"leadMaintainer": "Alex Potsides <[email protected]>",
66
"main": "src/index.js",
77
"browser": {
8-
"fs": false,
9-
"@hapi/joi": "joi-browser"
8+
"@hapi/joi": "joi-browser",
9+
"fs": false
1010
},
1111
"scripts": {
1212
"test": "aegir test",
1313
"test:node": "aegir test -t node",
14+
"test:cli": "aegir test -t node -f test/cli/**/*.js",
15+
"test:core": "aegir test -t node -f test/core/**/*.js",
16+
"test:http": "aegir test -t node -f test/http/**/*.js",
1417
"test:browser": "aegir test -t browser",
1518
"test:webworker": "aegir test -t webworker",
1619
"build": "aegir build",
1720
"lint": "aegir lint",
1821
"release": "aegir release",
1922
"release-minor": "aegir release --type minor",
2023
"release-major": "aegir release --type major",
21-
"coverage": "aegir coverage",
24+
"coverage": "nyc --reporter=text --reporter=lcov npm run test:node",
2225
"dep-check": "aegir dep-check"
2326
},
2427
"repository": {
@@ -38,36 +41,46 @@
3841
},
3942
"homepage": "https://github.com/ipfs/js-ipfs-mfs#readme",
4043
"devDependencies": {
44+
"@hapi/hapi": "^18.4.0",
4145
"aegir": "^20.0.0",
42-
"async-iterator-all": "^1.0.0",
4346
"chai": "^4.2.0",
47+
"chai-as-promised": "^7.1.1",
48+
"delay": "^4.3.0",
4449
"detect-node": "^2.0.4",
4550
"detect-webworker": "^1.0.0",
4651
"dirty-chai": "^2.0.1",
52+
"form-data": "^3.0.0",
4753
"ipfs-block-service": "~0.16.0",
48-
"ipfs-repo": "~0.27.0",
54+
"ipfs-repo": "^0.30.1",
4955
"ipld": "~0.25.0",
50-
"memdown": "^4.0.0",
51-
"temp-write": "^4.0.0"
56+
"it-all": "^1.0.1",
57+
"memdown": "^5.1.0",
58+
"nyc": "^15.0.0",
59+
"sinon": "^8.0.4",
60+
"stream-to-promise": "^2.2.0",
61+
"temp-write": "^4.0.0",
62+
"yargs": "^15.0.2",
63+
"yargs-promise": "^1.1.0"
5264
},
5365
"dependencies": {
5466
"@hapi/boom": "^7.4.2",
5567
"@hapi/joi": "^15.1.0",
56-
"async-iterator-last": "^1.0.0",
57-
"cids": "~0.7.1",
68+
"cids": "^0.7.1",
5869
"debug": "^4.1.0",
5970
"err-code": "^2.0.0",
60-
"hamt-sharding": "~0.0.2",
61-
"interface-datastore": "~0.7.0",
62-
"ipfs-multipart": "~0.2.0",
63-
"ipfs-unixfs": "~0.1.16",
64-
"ipfs-unixfs-exporter": "~0.38.0",
65-
"ipfs-unixfs-importer": "~0.40.0",
66-
"ipld-dag-pb": "~0.18.0",
71+
"hamt-sharding": "^1.0.0",
72+
"interface-datastore": "^0.8.0",
73+
"ipfs-multipart": "^0.3.0",
74+
"ipfs-unixfs": "^0.3.0",
75+
"ipfs-unixfs-exporter": "^0.40.0",
76+
"ipfs-unixfs-importer": "^0.43.0",
77+
"ipfs-utils": "^0.4.2",
78+
"ipld-dag-pb": "^0.18.0",
79+
"it-last": "^1.0.1",
6780
"joi-browser": "^13.4.0",
6881
"mortice": "^2.0.0",
69-
"multicodec": "~0.5.3",
70-
"multihashes": "~0.4.14",
82+
"multicodec": "^1.0.0",
83+
"multihashes": "^0.4.14",
7184
"once": "^1.4.0",
7285
"pull-stream": "^3.6.9"
7386
},

src/cli/chmod.js

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
'use strict'
2+
3+
const {
4+
asBoolean,
5+
asOctal
6+
} = require('./utils')
7+
8+
module.exports = {
9+
command: 'chmod [mode] [path]',
10+
11+
describe: 'Change file modes',
12+
13+
builder: {
14+
path: {
15+
type: 'string',
16+
describe: 'The MFS path to change the mode of'
17+
},
18+
mode: {
19+
type: 'int',
20+
coerce: asOctal,
21+
describe: 'The mode to use'
22+
},
23+
recursive: {
24+
alias: 'r',
25+
type: 'boolean',
26+
default: false,
27+
coerce: asBoolean,
28+
describe: 'Whether to change modes recursively'
29+
},
30+
codec: {
31+
alias: 'c',
32+
type: 'string',
33+
default: 'dag-pb',
34+
describe: 'If intermediate directories are created, use this codec to create them (experimental)'
35+
},
36+
'hash-alg': {
37+
alias: 'h',
38+
type: 'string',
39+
default: 'sha2-256',
40+
describe: 'Hash function to use. Will set CID version to 1 if used'
41+
},
42+
flush: {
43+
alias: 'f',
44+
type: 'boolean',
45+
default: true,
46+
coerce: asBoolean,
47+
describe: 'Flush the changes to disk immediately'
48+
},
49+
'shard-split-threshold': {
50+
type: 'number',
51+
default: 1000,
52+
describe: 'If a directory has more links than this, it will be transformed into a hamt-sharded-directory'
53+
}
54+
},
55+
56+
handler (argv) {
57+
const {
58+
path,
59+
mode,
60+
getIpfs,
61+
recursive,
62+
codec,
63+
hashAlg,
64+
flush,
65+
shardSplitThreshold
66+
} = argv
67+
68+
argv.resolve((async () => {
69+
const ipfs = await getIpfs()
70+
71+
return ipfs.files.chmod(path, mode, {
72+
recursive,
73+
format: codec,
74+
hashAlg,
75+
flush,
76+
shardSplitThreshold
77+
})
78+
})())
79+
}
80+
}

src/cli/cp.js

+14-5
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,25 @@ module.exports = {
1717
coerce: asBoolean,
1818
describe: 'Create any non-existent intermediate directories'
1919
},
20-
format: {
21-
alias: 'h',
20+
codec: {
21+
alias: 'c',
2222
type: 'string',
2323
default: 'dag-pb',
24-
describe: 'If intermediate directories are created, use this format to create them (experimental)'
24+
describe: 'If intermediate directories are created, use this codec to create them (experimental)'
2525
},
2626
'hash-alg': {
2727
alias: 'h',
2828
type: 'string',
2929
default: 'sha2-256',
3030
describe: 'Hash function to use. Will set CID version to 1 if used'
3131
},
32+
flush: {
33+
alias: 'f',
34+
type: 'boolean',
35+
default: true,
36+
coerce: asBoolean,
37+
describe: 'Flush the changes to disk immediately'
38+
},
3239
'shard-split-threshold': {
3340
type: 'number',
3441
default: 1000,
@@ -42,7 +49,8 @@ module.exports = {
4249
dest,
4350
getIpfs,
4451
parents,
45-
format,
52+
codec,
53+
flush,
4654
hashAlg,
4755
shardSplitThreshold
4856
} = argv
@@ -51,7 +59,8 @@ module.exports = {
5159
const ipfs = await getIpfs()
5260
return ipfs.files.cp(source, dest, {
5361
parents,
54-
format,
62+
format: codec,
63+
flush,
5564
hashAlg,
5665
shardSplitThreshold
5766
})

src/cli/index.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
'use strict'
22

3-
const {
4-
print
5-
} = require('./utils')
6-
73
const command = {
84
command: 'files <command>',
95

@@ -14,7 +10,7 @@ const command = {
1410
},
1511

1612
handler (argv) {
17-
print('Type `jsipfs files --help` for more instructions')
13+
argv.print('Type `jsipfs files --help` for more instructions')
1814
}
1915
}
2016

src/cli/ls.js

+8-10
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ const pull = require('pull-stream/pull')
44
const onEnd = require('pull-stream/sinks/on-end')
55
const through = require('pull-stream/throughs/through')
66
const {
7-
print,
87
asBoolean
98
} = require('./utils')
109
const {
1110
FILE_SEPARATOR
1211
} = require('../core/utils/constants')
12+
const formatMode = require('ipfs-utils/src/files/format-mode')
13+
const formatMtime = require('ipfs-utils/src/files/format-mtime')
1314

1415
module.exports = {
1516
command: 'ls [path]',
@@ -43,18 +44,15 @@ module.exports = {
4344
getIpfs,
4445
long,
4546
sort,
46-
cidBase
47+
cidBase,
48+
print
4749
} = argv
4850

4951
argv.resolve((async () => {
5052
const ipfs = await getIpfs()
5153
return new Promise((resolve, reject) => {
5254
if (sort) {
53-
ipfs.files.ls(path || FILE_SEPARATOR, {
54-
long,
55-
sort,
56-
cidBase
57-
})
55+
ipfs.files.ls(path || FILE_SEPARATOR)
5856
.then(files => {
5957
// https://github.com/ipfs/go-ipfs/issues/5181
6058
if (sort) {
@@ -64,8 +62,8 @@ module.exports = {
6462
}
6563

6664
if (long) {
67-
files.forEach(link => {
68-
print(`${link.name}\t${link.hash}\t${link.size}`)
65+
files.forEach(file => {
66+
print(`${formatMode(file.mode, file.type === 1)}\t${formatMtime(file.mtime)}\t${file.name}\t${file.hash}\t${file.size}`)
6967
})
7068
} else {
7169
files.forEach(link => print(link.name))
@@ -85,7 +83,7 @@ module.exports = {
8583
}),
8684
through(file => {
8785
if (long) {
88-
print(`${file.name}\t${file.hash}\t${file.size}`)
86+
print(`${formatMode(file.mode, file.type === 1)}\t${formatMtime(file.mtime)}\t${file.name}\t${file.hash}\t${file.size}`)
8987
} else {
9088
print(file.name)
9189
}

src/cli/mkdir.js

+30-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
'use strict'
22

33
const {
4-
asBoolean
4+
asBoolean,
5+
asOctal,
6+
asDateFromSeconds
57
} = require('./utils')
68

79
module.exports = {
@@ -23,9 +25,17 @@ module.exports = {
2325
default: 0,
2426
describe: 'Cid version to use. (experimental).'
2527
},
28+
codec: {
29+
alias: 'c',
30+
type: 'string',
31+
default: 'dag-pb',
32+
describe: 'If intermediate directories are created, use this codec to create them (experimental)'
33+
},
2634
'hash-alg': {
35+
alias: 'h',
2736
type: 'string',
28-
describe: 'Hash function to use. Will set Cid version to 1 if used. (experimental).'
37+
default: 'sha2-256',
38+
describe: 'Hash function to use. Will set CID version to 1 if used'
2939
},
3040
flush: {
3141
alias: 'f',
@@ -38,6 +48,16 @@ module.exports = {
3848
type: 'number',
3949
default: 1000,
4050
describe: 'If a directory has more links than this, it will be transformed into a hamt-sharded-directory'
51+
},
52+
mode: {
53+
type: 'number',
54+
coerce: asOctal,
55+
describe: 'Mode to apply to the new directory'
56+
},
57+
mtime: {
58+
type: 'date',
59+
coerce: asDateFromSeconds,
60+
describe: 'Mtime to apply to the new directory in seconds'
4161
}
4262
},
4363

@@ -47,9 +67,12 @@ module.exports = {
4767
getIpfs,
4868
parents,
4969
cidVersion,
70+
codec,
5071
hashAlg,
5172
flush,
52-
shardSplitThreshold
73+
shardSplitThreshold,
74+
mode,
75+
mtime
5376
} = argv
5477

5578
argv.resolve((async () => {
@@ -58,9 +81,12 @@ module.exports = {
5881
return ipfs.files.mkdir(path, {
5982
parents,
6083
cidVersion,
84+
format: codec,
6185
hashAlg,
6286
flush,
63-
shardSplitThreshold
87+
shardSplitThreshold,
88+
mode,
89+
mtime
6490
})
6591
})())
6692
}

0 commit comments

Comments
 (0)