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

Commit d6ece05

Browse files
authored
feat: support -X special permissions arg to files.chmod (#2719)
* feat: support -X special permissions arg to files.chmod Also adds tests for metadata with mfs stat and files.add Depends on: - [ ] ipfs-inactive/interface-js-ipfs-core#580 - [ ] ipfs-inactive/js-ipfs-http-client#1221 * chore: remove gh urls
1 parent 2dfa0b1 commit d6ece05

File tree

3 files changed

+25
-32
lines changed

3 files changed

+25
-32
lines changed

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,14 @@
9898
"ipfs-bitswap": "^0.26.2",
9999
"ipfs-block": "~0.8.1",
100100
"ipfs-block-service": "~0.16.0",
101-
"ipfs-http-client": "^41.0.0",
101+
"ipfs-http-client": "^41.0.1",
102102
"ipfs-http-response": "~0.4.0",
103-
"ipfs-mfs": "^0.15.0",
103+
"ipfs-mfs": "^0.16.0",
104104
"ipfs-multipart": "^0.3.0",
105105
"ipfs-repo": "^0.30.0",
106106
"ipfs-unixfs": "^0.3.0",
107-
"ipfs-unixfs-exporter": "^0.40.0",
108-
"ipfs-unixfs-importer": "^0.43.0",
107+
"ipfs-unixfs-exporter": "^0.41.0",
108+
"ipfs-unixfs-importer": "^0.44.0",
109109
"ipfs-utils": "^0.4.2",
110110
"ipld": "~0.25.0",
111111
"ipld-bitcoin": "~0.3.0",
@@ -204,7 +204,7 @@
204204
"execa": "^3.0.0",
205205
"form-data": "^3.0.0",
206206
"hat": "0.0.3",
207-
"interface-ipfs-core": "^0.127.0",
207+
"interface-ipfs-core": "^0.128.0",
208208
"ipfs-interop": "^0.2.0",
209209
"ipfsd-ctl": "^1.0.2",
210210
"libp2p-websocket-star": "~0.10.2",

src/core/components/files-regular/add-async-iterator.js

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -74,39 +74,24 @@ function transformFile (ipfs, opts) {
7474
return async function * (source) {
7575
for await (const file of source) {
7676
let cid = file.cid
77-
const hash = cid.toBaseEncodedString()
78-
let path = file.path ? file.path : hash
79-
80-
if (opts.wrapWithDirectory && !file.path) {
81-
path = ''
82-
}
83-
84-
if (opts.onlyHash) {
85-
yield {
86-
path,
87-
hash,
88-
size: file.unixfs.fileSize()
89-
}
90-
91-
return
92-
}
93-
94-
const node = await ipfs.object.get(file.cid, Object.assign({}, opts, { preload: false }))
9577

9678
if (opts.cidVersion === 1) {
9779
cid = cid.toV1()
9880
}
9981

100-
let size = node.size
82+
const hash = cid.toBaseEncodedString()
83+
let path = file.path ? file.path : hash
10184

102-
if (Buffer.isBuffer(node)) {
103-
size = node.length
85+
if (opts.wrapWithDirectory && !file.path) {
86+
path = ''
10487
}
10588

10689
yield {
10790
path,
10891
hash,
109-
size
92+
size: file.size,
93+
mode: file.unixfs && file.unixfs.mode,
94+
mtime: file.unixfs && file.unixfs.mtime
11095
}
11196
}
11297
}

src/http/api/resources/files-regular.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,9 @@ exports.add = {
206206
filesParsed = true
207207

208208
yield {
209-
path: entry.name
209+
path: entry.name,
210+
mode: entry.mode,
211+
mtime: entry.mtime
210212
}
211213
}
212214
}
@@ -233,13 +235,19 @@ exports.add = {
233235
},
234236
async function (source) {
235237
for await (const file of source) {
236-
output.write(JSON.stringify({
238+
const entry = {
237239
Name: file.path,
238240
Hash: cidToString(file.hash, { base: request.query['cid-base'] }),
239241
Size: file.size,
240-
Mode: file.mode === undefined ? undefined : file.mode.toString(8).padStart(4, '0'),
241-
Mtime: file.mtime
242-
}) + '\n')
242+
Mode: file.mode === undefined ? undefined : file.mode.toString(8).padStart(4, '0')
243+
}
244+
245+
if (file.mtime) {
246+
entry.Mtime = file.mtime.secs
247+
entry.MtimeNsecs = file.mtime.nsecs
248+
}
249+
250+
output.write(JSON.stringify(entry) + '\n')
243251
}
244252
}
245253
)

0 commit comments

Comments
 (0)