Skip to content

Commit

Permalink
adds default case and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
alanshaw committed Mar 27, 2018
1 parent 3dd7ecc commit 36eb609
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions add-on/src/lib/ipfs-proxy/pre-mfs-scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@ const MfsPre = {
'files.stat': createSrcPre,
'files.rm' (getScope, rootPath) {
const srcPre = createSrcPre(getScope, rootPath)
return (...args) => { // Do not allow rm app root
// Do not allow rm app root
// Need to explicitly deny because it's ok to rm -rf /a/path that's not /
return (...args) => {
if (isRoot(args[0])) throw new Error('cannot delete root')
return srcPre(...args)
}
},
'files.read': createSrcPre,
'files.write' (getScope, rootPath) {
const srcPre = createSrcPre(getScope, rootPath)
return (...args) => { // Do not allow write to app root
// Do not allow write to app root
// Need to explicitly deny because app path might not exist yet
return (...args) => {
if (isRoot(args[0])) throw new Error('/ was not a file')
return srcPre(...args)
}
Expand Down Expand Up @@ -62,9 +66,10 @@ function createOptionalSrcPre (getScope, rootPath) {
args[0] = Path.join(appPath, safePath(args[0]))
} else {
switch (args.length) {
case 0: return [appPath] // e.g. ipfs.files.ls()
case 0: return [appPath] // e.g. ipfs.files.ls()
case 1: return [appPath, args[0]] // e.g. ipfs.files.ls(options)
case 2: return [appPath, args[1]] // e.g. ipfs.files.ls(null, options)
default: throw new Error('Unexpected number of arguments')
}
}
return args
Expand Down

0 comments on commit 36eb609

Please sign in to comment.