This repository has been archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Add metadata support #63
Merged
Merged
Changes from 4 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
dcc5ce7
chore: dep updated
achingbrain 95e1d9c
feat: adds touch and chmod commands and metadata
achingbrain b3976c4
chore: update deps
achingbrain d4fbd67
chore: update deps
achingbrain 43eadd4
test: add cli tests
achingbrain 07bdca1
fix: add missing dep
achingbrain afaf7a5
Merge remote-tracking branch 'origin/master' into add-metadata-support
achingbrain 6679fe5
fix: downgrade repo
achingbrain 1ae8e79
fix: fix tests after hashOnly turned to onlyHash
achingbrain 0b409ae
test: add tests for http interface
achingbrain 18dc766
fix: use multipart pr
achingbrain 8889f25
chore: remove unecessary browser overrides
achingbrain cdcf704
chore: update ipfs-utils dep
achingbrain 0ee7296
fix: fix up tests, add support for timespecs
achingbrain 234e11c
chore: use multipart pr
achingbrain d55b595
fix: support optional mtimes
achingbrain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
'use strict' | ||
|
||
const { | ||
asBoolean, | ||
asOctal | ||
} = require('./utils') | ||
|
||
module.exports = { | ||
command: 'chmod [mode] [path]', | ||
|
||
describe: 'Change file modes', | ||
|
||
builder: { | ||
path: { | ||
type: 'string', | ||
describe: 'The MFS path to change the mode of' | ||
}, | ||
mode: { | ||
type: 'int', | ||
coerce: asOctal, | ||
describe: 'The mode to use' | ||
}, | ||
recursive: { | ||
type: 'boolean', | ||
default: false, | ||
coerce: asBoolean, | ||
describe: 'Whether to change modes recursively' | ||
}, | ||
flush: { | ||
alias: 'f', | ||
type: 'boolean', | ||
default: true, | ||
coerce: asBoolean, | ||
describe: 'Flush the changes to disk immediately' | ||
}, | ||
'shard-split-threshold': { | ||
type: 'number', | ||
default: 1000, | ||
describe: 'If a directory has more links than this, it will be transformed into a hamt-sharded-directory' | ||
} | ||
}, | ||
|
||
handler (argv) { | ||
const { | ||
path, | ||
mode, | ||
getIpfs, | ||
recursive, | ||
flush, | ||
shardSplitThreshold | ||
} = argv | ||
|
||
argv.resolve((async () => { | ||
const ipfs = await getIpfs() | ||
|
||
return ipfs.files.chmod(path, mode, { | ||
recursive, | ||
flush, | ||
shardSplitThreshold | ||
}) | ||
})()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
'use strict' | ||
|
||
const { | ||
asBoolean | ||
asBoolean, | ||
asOctal | ||
} = require('./utils') | ||
|
||
module.exports = { | ||
|
@@ -38,6 +39,20 @@ module.exports = { | |
type: 'number', | ||
default: 1000, | ||
describe: 'If a directory has more links than this, it will be transformed into a hamt-sharded-directory' | ||
}, | ||
mode: { | ||
alias: 'm', | ||
type: 'number', | ||
default: true, | ||
coerce: asOctal, | ||
describe: 'Mode to apply to the new directory' | ||
}, | ||
mtime: { | ||
alias: 'm', | ||
type: 'number', | ||
default: true, | ||
coerce: asOctal, | ||
describe: 'Mtime to apply to the new directory' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As discussed, peeps probably want to use strings. |
||
} | ||
}, | ||
|
||
|
@@ -49,7 +64,9 @@ module.exports = { | |
cidVersion, | ||
hashAlg, | ||
flush, | ||
shardSplitThreshold | ||
shardSplitThreshold, | ||
mode, | ||
mtime | ||
} = argv | ||
|
||
argv.resolve((async () => { | ||
|
@@ -60,7 +77,9 @@ module.exports = { | |
cidVersion, | ||
hashAlg, | ||
flush, | ||
shardSplitThreshold | ||
shardSplitThreshold, | ||
mode, | ||
mtime | ||
}) | ||
})()) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,59 @@ | ||||||
'use strict' | ||||||
|
||||||
const { | ||||||
asBoolean | ||||||
} = require('./utils') | ||||||
|
||||||
module.exports = { | ||||||
command: 'touch [path]', | ||||||
|
||||||
describe: 'change file modification times', | ||||||
|
||||||
builder: { | ||||||
flush: { | ||||||
alias: 'f', | ||||||
type: 'boolean', | ||||||
default: true, | ||||||
coerce: asBoolean, | ||||||
describe: 'Flush the changes to disk immediately' | ||||||
}, | ||||||
'shard-split-threshold': { | ||||||
type: 'number', | ||||||
default: 1000, | ||||||
describe: 'If a directory has more links than this, it will be transformed into a hamt-sharded-directory' | ||||||
}, | ||||||
'cid-version': { | ||||||
alias: ['cid-ver'], | ||||||
type: 'number', | ||||||
default: 0, | ||||||
describe: 'Cid version to use' | ||||||
}, | ||||||
mtime: { | ||||||
alias: 'm', | ||||||
type: 'number', | ||||||
default: parseInt(Date.now() / 1000), | ||||||
describe: 'Time to use as the new modification time' | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
...or is it seconds? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's seconds in the spec. |
||||||
} | ||||||
}, | ||||||
|
||||||
handler (argv) { | ||||||
const { | ||||||
path, | ||||||
getIpfs, | ||||||
flush, | ||||||
shardSplitThreshold, | ||||||
cidVersion, | ||||||
mtime | ||||||
} = argv | ||||||
|
||||||
argv.resolve((async () => { | ||||||
const ipfs = await getIpfs() | ||||||
|
||||||
return ipfs.files.touch(path, mtime, { | ||||||
flush, | ||||||
shardSplitThreshold, | ||||||
cidVersion | ||||||
}) | ||||||
})()) | ||||||
} | ||||||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
'use strict' | ||
|
||
const applyDefaultOptions = require('./utils/apply-default-options') | ||
const toMfsPath = require('./utils/to-mfs-path') | ||
const log = require('debug')('ipfs:mfs:touch') | ||
const errCode = require('err-code') | ||
const UnixFS = require('ipfs-unixfs') | ||
const toTrail = require('./utils/to-trail') | ||
const addLink = require('./utils/add-link') | ||
const updateTree = require('./utils/update-tree') | ||
const updateMfsRoot = require('./utils/update-mfs-root') | ||
const { DAGNode } = require('ipld-dag-pb') | ||
const mc = require('multicodec') | ||
const mh = require('multihashes') | ||
|
||
const defaultOptions = { | ||
flush: true, | ||
shardSplitThreshold: 1000, | ||
cidVersion: 1, | ||
format: 'dag-pb', | ||
hashAlg: 'sha2-256' | ||
} | ||
|
||
module.exports = (context) => { | ||
return async function mfsChmod (path, mode, options) { | ||
options = applyDefaultOptions(options, defaultOptions) | ||
|
||
log(`Fetching stats for ${path}`) | ||
|
||
const { | ||
cid, | ||
mfsDirectory, | ||
name | ||
} = await toMfsPath(context, path) | ||
|
||
if (cid.codec !== 'dag-pb') { | ||
throw errCode(new Error(`${path} was not a UnixFS node`), 'ERR_NOT_UNIXFS') | ||
} | ||
|
||
let node = await context.ipld.get(cid) | ||
const metadata = UnixFS.unmarshal(node.Data) | ||
metadata.mode = mode | ||
node = new DAGNode(metadata.marshal(), node.Links) | ||
|
||
const updatedCid = await context.ipld.put(node, mc.DAG_PB, { | ||
cidVersion: cid.version, | ||
hashAlg: mh.names['sha2-256'], | ||
hashOnly: !options.flush | ||
achingbrain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}) | ||
|
||
const trail = await toTrail(context, mfsDirectory, options) | ||
const parent = trail[trail.length - 1] | ||
const parentNode = await context.ipld.get(parent.cid) | ||
|
||
const result = await addLink(context, { | ||
parent: parentNode, | ||
name: name, | ||
cid: updatedCid, | ||
size: node.serialize().length, | ||
flush: options.flush, | ||
format: 'dag-pb', | ||
hashAlg: 'sha2-256', | ||
cidVersion: cid.version | ||
}) | ||
|
||
parent.cid = result.cid | ||
|
||
// update the tree with the new child | ||
const newRootCid = await updateTree(context, trail, options) | ||
|
||
// Update the MFS record with the new CID for the root of the tree | ||
await updateMfsRoot(context, newRootCid) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically a breaking change...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure -
h
was taken by another command so the short version of this option never worked before. More of a fix?