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

Commit

Permalink
feat: support -X special permissions arg to files.chmod (#2719)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
achingbrain committed Jan 23, 2020
1 parent 2dfa0b1 commit d6ece05
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 32 deletions.
10 changes: 5 additions & 5 deletions package.json
Expand Up @@ -98,14 +98,14 @@
"ipfs-bitswap": "^0.26.2",
"ipfs-block": "~0.8.1",
"ipfs-block-service": "~0.16.0",
"ipfs-http-client": "^41.0.0",
"ipfs-http-client": "^41.0.1",
"ipfs-http-response": "~0.4.0",
"ipfs-mfs": "^0.15.0",
"ipfs-mfs": "^0.16.0",
"ipfs-multipart": "^0.3.0",
"ipfs-repo": "^0.30.0",
"ipfs-unixfs": "^0.3.0",
"ipfs-unixfs-exporter": "^0.40.0",
"ipfs-unixfs-importer": "^0.43.0",
"ipfs-unixfs-exporter": "^0.41.0",
"ipfs-unixfs-importer": "^0.44.0",
"ipfs-utils": "^0.4.2",
"ipld": "~0.25.0",
"ipld-bitcoin": "~0.3.0",
Expand Down Expand Up @@ -204,7 +204,7 @@
"execa": "^3.0.0",
"form-data": "^3.0.0",
"hat": "0.0.3",
"interface-ipfs-core": "^0.127.0",
"interface-ipfs-core": "^0.128.0",
"ipfs-interop": "^0.2.0",
"ipfsd-ctl": "^1.0.2",
"libp2p-websocket-star": "~0.10.2",
Expand Down
29 changes: 7 additions & 22 deletions src/core/components/files-regular/add-async-iterator.js
Expand Up @@ -74,39 +74,24 @@ function transformFile (ipfs, opts) {
return async function * (source) {
for await (const file of source) {
let cid = file.cid
const hash = cid.toBaseEncodedString()
let path = file.path ? file.path : hash

if (opts.wrapWithDirectory && !file.path) {
path = ''
}

if (opts.onlyHash) {
yield {
path,
hash,
size: file.unixfs.fileSize()
}

return
}

const node = await ipfs.object.get(file.cid, Object.assign({}, opts, { preload: false }))

if (opts.cidVersion === 1) {
cid = cid.toV1()
}

let size = node.size
const hash = cid.toBaseEncodedString()
let path = file.path ? file.path : hash

if (Buffer.isBuffer(node)) {
size = node.length
if (opts.wrapWithDirectory && !file.path) {
path = ''
}

yield {
path,
hash,
size
size: file.size,
mode: file.unixfs && file.unixfs.mode,
mtime: file.unixfs && file.unixfs.mtime
}
}
}
Expand Down
18 changes: 13 additions & 5 deletions src/http/api/resources/files-regular.js
Expand Up @@ -206,7 +206,9 @@ exports.add = {
filesParsed = true

yield {
path: entry.name
path: entry.name,
mode: entry.mode,
mtime: entry.mtime
}
}
}
Expand All @@ -233,13 +235,19 @@ exports.add = {
},
async function (source) {
for await (const file of source) {
output.write(JSON.stringify({
const entry = {
Name: file.path,
Hash: cidToString(file.hash, { base: request.query['cid-base'] }),
Size: file.size,
Mode: file.mode === undefined ? undefined : file.mode.toString(8).padStart(4, '0'),
Mtime: file.mtime
}) + '\n')
Mode: file.mode === undefined ? undefined : file.mode.toString(8).padStart(4, '0')
}

if (file.mtime) {
entry.Mtime = file.mtime.secs
entry.MtimeNsecs = file.mtime.nsecs
}

output.write(JSON.stringify(entry) + '\n')
}
}
)
Expand Down

0 comments on commit d6ece05

Please sign in to comment.