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

Commit acbda68

Browse files
authored
feat: support UnixFSv1.5 metadata (#2621)
* feat: support UnixFSv1.5 metadata Adds metadata support. Specifying metadata: ```console $ jsipfs add --mode=0777 --mtime=100000 ./foo.txt ``` Respecting exsting metadata: ```console $ jsipfs add --preserve-mode --preserve-mtime ./foo.txt ``` Displaying metadata: ```console $ jsipfs ls Qmfoo -rw-r--r-- Nov 21, 2019, 09:46:23 AM CST bar.txt Qbar 0 ``` * chore: update dep paths and jsdocs * chore: fix linting * fix: expose metadata in http api * test: interface tests passing * chore: update package.json with branches * fix: support mtime as timespec * fix: check mtime formatting in timezone agnostic way * fix: do not run hrtime tests in the browser * chore: upgrade interop tests * chore: symlink ipfs dir for interop tests * fix: build ipfs before running examples * fix: expose mtime-nsecs to cli and add tests * fix: export path to js-ipfs binary * fix: support optional mtime * fix: linting * fix: pin datastore-pubsub version due to ipfs/js-datastore-pubsub#20 * chore: restore datastore-pubsub semver
1 parent 57c1027 commit acbda68

File tree

18 files changed

+322
-105
lines changed

18 files changed

+322
-105
lines changed

.travis.yml

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,28 +76,44 @@ jobs:
7676
- stage: test
7777
name: interop - node
7878
script:
79+
- mkdir -p node_modules/ipfs-interop/node_modules
80+
- ln -s `pwd` node_modules/ipfs-interop/node_modules/ipfs
81+
- export IPFS_JS_EXEC=`pwd`/src/cli/bin.js
82+
- export IPFS_REUSEPORT=false
7983
- cd node_modules/ipfs-interop
80-
- IPFS_JS_EXEC=./../../src/cli/bin.js IPFS_REUSEPORT=false npx aegir test -t node --bail
84+
- npx aegir test -t node --bail
8185

8286
- stage: test
8387
name: interop - browser
8488
script:
89+
- mkdir -p node_modules/ipfs-interop/node_modules
90+
- ln -s `pwd` node_modules/ipfs-interop/node_modules/ipfs
91+
- export IPFS_JS_EXEC=`pwd`/src/cli/bin.js
92+
- export IPFS_REUSEPORT=false
8593
- cd node_modules/ipfs-interop
86-
- IPFS_JS_EXEC=./../../src/cli/bin.js IPFS_REUSEPORT=false npx aegir test -t browser --bail
94+
- npx aegir test -t browser --bail
8795

8896
- stage: test
8997
name: interop - electron-main
9098
os: osx
9199
script:
100+
- mkdir -p node_modules/ipfs-interop/node_modules
101+
- ln -s `pwd` node_modules/ipfs-interop/node_modules/ipfs
102+
- export IPFS_JS_EXEC=`pwd`/src/cli/bin.js
103+
- export IPFS_REUSEPORT=false
92104
- cd node_modules/ipfs-interop
93-
- IPFS_JS_EXEC=./../../src/cli/bin.js IPFS_REUSEPORT=false npx aegir test -t electron-main -f ./test/node.js --bail --timeout 10000
105+
- npx aegir test -t electron-main -f ./test/node.js --bail --timeout 10000
94106

95107
- stage: test
96108
name: interop - electron-renderer
97109
os: osx
98110
script:
111+
- mkdir -p node_modules/ipfs-interop/node_modules
112+
- ln -s `pwd` node_modules/ipfs-interop/node_modules/ipfs
113+
- export IPFS_JS_EXEC=`pwd`/src/cli/bin.js
114+
- export IPFS_REUSEPORT=false
99115
- cd node_modules/ipfs-interop
100-
- IPFS_JS_EXEC=./../../src/cli/bin.js IPFS_REUSEPORT=false npx aegir test -t electron-renderer -f ./test/browser.js --bail --timeout 10000
116+
- npx aegir test -t electron-renderer -f ./test/browser.js --bail --timeout 10000
101117

102118
- stage: test
103119
name: external - ipfs-companion
@@ -142,125 +158,143 @@ jobs:
142158
- stage: test
143159
name: example - browser-add-readable-stream
144160
script:
161+
- npm run build
145162
- cd examples
146163
- npm install
147164
- npm run test -- browser-add-readable-stream
148165

149166
- stage: test
150167
name: example - browser-browserify
151168
script:
169+
- npm run build
152170
- cd examples
153171
- npm install
154172
- npm run test -- browser-browserify
155173

156174
- stage: test
157175
name: example - browser-create-react-app
158176
script:
177+
- npm run build
159178
- cd examples
160179
- npm install
161180
- npm run test -- browser-create-react-app
162181

163182
- stage: test
164183
name: example - browser-mfs
165184
script:
185+
- npm run build
166186
- cd examples
167187
- npm install
168188
- npm run test -- browser-mfs
169189

170190
- stage: test
171191
name: example - browser-parceljs
172192
script:
193+
- npm run build
173194
- cd examples
174195
- npm install
175196
- npm run test -- browser-parceljs
176197

177198
- stage: test
178199
name: example - browser-readablestream
179200
script:
201+
- npm run build
180202
- cd examples
181203
- npm install
182204
- npm run test -- browser-readablestream
183205

184206
- stage: test
185207
name: example - browser-script-tag
186208
script:
209+
- npm run build
187210
- cd examples
188211
- npm install
189212
- npm run test -- browser-script-tag
190213

191214
- stage: test
192215
name: example - browser-video-streaming
193216
script:
217+
- npm run build
194218
- cd examples
195219
- npm install
196220
- npm run test -- browser-video-streaming
197221

198222
- stage: test
199223
name: example - browser-vue
200224
script:
225+
- npm run build
201226
- cd examples
202227
- npm install
203228
- npm run test -- browser-vue
204229

205230
- stage: test
206231
name: example - browser-webpack
207232
script:
233+
- npm run build
208234
- cd examples
209235
- npm install
210236
- npm run test -- browser-webpack
211237

212238
- stage: test
213239
name: example - circuit-relaying
214240
script:
241+
- npm run build
215242
- cd examples
216243
- npm install
217244
- npm run test -- circuit-relaying
218245

219246
- stage: test
220247
name: example - custom-ipfs-repo
221248
script:
249+
- npm run build
222250
- cd examples
223251
- npm install
224252
- npm run test -- custom-ipfs-repo
225253

226254
- stage: test
227255
name: example - custom-libp2p
228256
script:
257+
- npm run build
229258
- cd examples
230259
- npm install
231260
- npm run test -- custom-libp2p
232261

233262
- stage: test
234263
name: example - exchange-files-in-browser
235264
script:
265+
- npm run build
236266
- cd examples
237267
- npm install
238268
- npm run test -- exchange-files-in-browser
239269

240270
- stage: test
241271
name: example - explore-ethereum-blockchain
242272
script:
273+
- npm run build
243274
- cd examples
244275
- npm install
245276
- npm run test -- explore-ethereum-blockchain
246277

247278
- stage: test
248279
name: example - ipfs-101
249280
script:
281+
- npm run build
250282
- cd examples
251283
- npm install
252284
- npm run test -- ipfs-101
253285

254286
- stage: test
255287
name: example - running-multiple-nodes
256288
script:
289+
- npm run build
257290
- cd examples
258291
- npm install
259292
- npm run test -- running-multiple-nodes
260293

261294
- stage: test
262295
name: example - traverse-ipld-graphs
263296
script:
297+
- npm run build
264298
- cd examples
265299
- npm install
266300
- npm run test -- traverse-ipld-graphs

examples/running-multiple-nodes/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const IPFS = require('ipfs')
3+
const IPFS = require('../../')
44

55
const execa = require('execa')
66
const os = require('os')

package.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
"class-is": "^1.1.0",
8282
"dag-cbor-links": "^1.3.2",
8383
"datastore-core": "~0.7.0",
84-
"datastore-pubsub": "^0.2.1",
84+
"datastore-pubsub": "^0.2.3",
8585
"debug": "^4.1.0",
8686
"dlv": "^1.1.3",
8787
"err-code": "^2.0.0",
@@ -95,18 +95,18 @@
9595
"hashlru": "^2.3.0",
9696
"human-to-milliseconds": "^2.0.0",
9797
"interface-datastore": "~0.8.0",
98-
"ipfs-bitswap": "^0.26.0",
98+
"ipfs-bitswap": "^0.26.2",
9999
"ipfs-block": "~0.8.1",
100100
"ipfs-block-service": "~0.16.0",
101-
"ipfs-http-client": "^40.1.0",
101+
"ipfs-http-client": "^40.2.0",
102102
"ipfs-http-response": "~0.4.0",
103-
"ipfs-mfs": "^0.13.2",
104-
"ipfs-multipart": "^0.2.0",
103+
"ipfs-mfs": "^0.14.0",
104+
"ipfs-multipart": "^0.3.0",
105105
"ipfs-repo": "^0.30.0",
106-
"ipfs-unixfs": "~0.1.16",
107-
"ipfs-unixfs-exporter": "^0.38.0",
108-
"ipfs-unixfs-importer": "^0.42.0",
109-
"ipfs-utils": "~0.4.0",
106+
"ipfs-unixfs": "^0.3.0",
107+
"ipfs-unixfs-exporter": "^0.40.0",
108+
"ipfs-unixfs-importer": "^0.43.0",
109+
"ipfs-utils": "^0.4.2",
110110
"ipld": "~0.25.0",
111111
"ipld-bitcoin": "~0.3.0",
112112
"ipld-dag-cbor": "~0.15.0",
@@ -137,7 +137,7 @@
137137
"libp2p-floodsub": "^0.18.0",
138138
"libp2p-gossipsub": "~0.0.5",
139139
"libp2p-kad-dht": "~0.16.0",
140-
"libp2p-keychain": "^0.5.2",
140+
"libp2p-keychain": "^0.5.4",
141141
"libp2p-mdns": "~0.12.0",
142142
"libp2p-record": "~0.7.0",
143143
"libp2p-secio": "~0.11.0",
@@ -154,7 +154,7 @@
154154
"multiaddr": "^6.1.1",
155155
"multiaddr-to-uri": "^5.0.0",
156156
"multibase": "~0.6.0",
157-
"multicodec": "~0.5.5",
157+
"multicodec": "^1.0.0",
158158
"multihashes": "~0.4.14",
159159
"multihashing-async": "^0.8.0",
160160
"node-fetch": "^2.3.0",
@@ -204,8 +204,8 @@
204204
"execa": "^3.0.0",
205205
"form-data": "^3.0.0",
206206
"hat": "0.0.3",
207-
"interface-ipfs-core": "^0.125.0",
208-
"ipfs-interop": "^0.1.1",
207+
"interface-ipfs-core": "^0.126.0",
208+
"ipfs-interop": "^0.2.0",
209209
"ipfsd-ctl": "^1.0.2",
210210
"libp2p-websocket-star": "~0.10.2",
211211
"lodash": "^4.17.15",

src/cli/commands/add.js

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,50 @@ module.exports = {
122122
type: 'boolean',
123123
default: false,
124124
describe: 'Include files that are hidden. Only takes effect on recursive add.'
125+
},
126+
'preserve-mode': {
127+
type: 'boolean',
128+
default: false,
129+
describe: 'Apply permissions to created UnixFS entries'
130+
},
131+
'preserve-mtime': {
132+
type: 'boolean',
133+
default: false,
134+
describe: 'Apply modification time to created UnixFS entries'
135+
},
136+
mode: {
137+
type: 'string',
138+
describe: 'File mode to apply to created UnixFS entries'
139+
},
140+
mtime: {
141+
type: 'number',
142+
coerce: (value) => {
143+
value = parseInt(value)
144+
145+
if (isNaN(value)) {
146+
throw new Error('mtime must be a number')
147+
}
148+
149+
return value
150+
},
151+
describe: 'Modification time in seconds before or since the Unix Epoch to apply to created UnixFS entries'
152+
},
153+
'mtime-nsecs': {
154+
type: 'number',
155+
coerce: (value) => {
156+
value = parseInt(value)
157+
158+
if (isNaN(value)) {
159+
throw new Error('mtime-nsecs must be a number')
160+
}
161+
162+
if (value < 0 || value > 999999999) {
163+
throw new Error('mtime-nsecs must be in the range [0,999999999]')
164+
}
165+
166+
return value
167+
},
168+
describe: 'Modification time fraction in nanoseconds'
125169
}
126170
},
127171

@@ -171,9 +215,28 @@ module.exports = {
171215
}
172216
}
173217

218+
let mtime
219+
220+
if (argv.mtime != null) {
221+
mtime = {
222+
secs: argv.mtime
223+
}
224+
225+
if (argv.mtimeNsecs != null) {
226+
mtime.nsecs = argv.mtimeNsecs
227+
}
228+
}
229+
174230
const source = argv.file
175-
? globSource(argv.file, { recursive: argv.recursive, hidden: argv.hidden })
176-
: process.stdin // Pipe directly to ipfs.add
231+
? globSource(argv.file, {
232+
recursive: argv.recursive,
233+
hidden: argv.hidden,
234+
preserveMode: argv.preserveMode,
235+
preserveMtime: argv.preserveMtime,
236+
mode: argv.mode,
237+
mtime
238+
})
239+
: argv.getStdin() // Pipe directly to ipfs.add
177240

178241
let finalHash
179242

src/cli/commands/block/put.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ module.exports = {
4444
data = await promisify(fs.readFile)(argv.block)
4545
} else {
4646
data = await new Promise((resolve, reject) => {
47-
process.stdin.pipe(bl((err, input) => {
47+
argv.getStdin().pipe(bl((err, input) => {
4848
if (err) return reject(err)
4949
resolve(input)
5050
}))

src/cli/commands/daemon.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ module.exports = {
4848
handler (argv) {
4949
argv.resolve((async () => {
5050
const { print } = argv
51+
5152
print('Initializing IPFS daemon...')
5253
print(`js-ipfs version: ${require('../../../package.json').version}`)
5354
print(`System version: ${os.arch()}/${os.platform()}`)

src/cli/commands/dag/put.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ module.exports = {
7979
}
8080
},
8181

82-
handler ({ data, format, inputEncoding, pin, hashAlg, cidVersion, cidBase, preload, onlyHash, getIpfs, print, resolve }) {
82+
handler ({ data, format, inputEncoding, pin, hashAlg, cidVersion, cidBase, preload, onlyHash, getIpfs, print, resolve, getStdin }) {
8383
resolve((async () => {
8484
const ipfs = await getIpfs()
8585

@@ -101,7 +101,7 @@ module.exports = {
101101
// pipe from stdin
102102
source = Buffer.alloc(0)
103103

104-
for await (const buf of process.stdin) {
104+
for await (const buf of getStdin()) {
105105
source = Buffer.concat([source, buf])
106106
}
107107
} else {

0 commit comments

Comments
 (0)