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

Commit

Permalink
feat: support --raw-leaves
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed Jul 23, 2018
1 parent f4344b0 commit 7b92684
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 87 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@
"ipfs-block": "~0.7.1",
"ipfs-block-service": "~0.14.0",
"ipfs-http-response": "~0.1.2",
"ipfs-mfs": "~0.1.0",
"ipfs-mfs": "~0.2.2",
"ipfs-multipart": "~0.1.0",
"ipfs-repo": "~0.22.1",
"ipfs-unixfs": "~0.1.15",
"ipfs-unixfs-engine": "~0.30.0",
"ipfs-unixfs-engine": "~0.31.2",
"ipld": "~0.17.3",
"ipld-dag-cbor": "~0.12.1",
"ipld-dag-pb": "~0.14.5",
Expand Down
36 changes: 5 additions & 31 deletions src/cli/commands/files/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,19 @@ module.exports = {
},
'raw-leaves': {
type: 'boolean',
default: undefined,
default: false,
describe: 'Use raw blocks for leaf nodes. (experimental)'
},
'cid-version': {
type: 'integer',
describe: 'Cid version. Non-zero value will change default of \'raw-leaves\' to true. (experimental)'
describe: 'CID version. Defaults to 0 unless an option that depends on CIDv1 is passed. (experimental)',
default: 0
},
hash: {
type: 'string',
choices: Object.keys(mh.names),
describe: 'Hash function to use. Will set Cid version to 1 if used. (experimental)'
describe: 'Hash function to use. Will set Cid version to 1 if used. (experimental)',
default: 'sha2-256'
},
quiet: {
alias: 'q',
Expand Down Expand Up @@ -197,34 +199,6 @@ module.exports = {
pin: argv.pin
}

// Temporary restriction on raw-leaves:
// When cid-version=1 then raw-leaves MUST be present and false.
//
// This is because raw-leaves is not yet implemented in js-ipfs,
// and go-ipfs changes the value of raw-leaves to true when
// cid-version > 0 unless explicitly set to false.
//
// This retains feature parity without having to implement raw-leaves.
if (options.cidVersion > 0 && options.rawLeaves !== false) {
throw new Error('Implied argument raw-leaves must be passed and set to false when cid-version is > 0')
}

// Temporary restriction on raw-leaves:
// When hash != undefined then raw-leaves MUST be present and false.
//
// This is because raw-leaves is not yet implemented in js-ipfs,
// and go-ipfs changes the value of raw-leaves to true when
// hash != undefined unless explicitly set to false.
//
// This retains feature parity without having to implement raw-leaves.
if (options.hash && options.rawLeaves !== false) {
throw new Error('Implied argument raw-leaves must be passed and set to false when hash argument is specified')
}

if (options.rawLeaves) {
throw new Error('Not implemented: raw-leaves')
}

if (options.enableShardingExperiment && utils.isDaemonOn()) {
throw new Error('Error: Enabling the sharding experiment should be done on the daemon')
}
Expand Down
16 changes: 2 additions & 14 deletions src/http/api/resources/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,20 +153,8 @@ exports.add = {
validate: {
query: Joi.object()
.keys({
'cid-version': Joi.number().integer().min(0).max(1),
// Temporary restriction on raw-leaves:
// When cid-version=1 then raw-leaves MUST be present and false.
//
// This is because raw-leaves is not yet implemented in js-ipfs,
// and go-ipfs changes the value of raw-leaves to true when
// cid-version > 0 unless explicitly set to false.
//
// This retains feature parity without having to implement raw-leaves.
'raw-leaves': Joi.boolean().when('cid-version', {
is: 1,
then: Joi.boolean().valid(false).required(),
otherwise: Joi.boolean().valid(false)
}),
'cid-version': Joi.number().integer().min(0).max(1).default(0),
'raw-leaves': Joi.boolean(),
'only-hash': Joi.boolean(),
pin: Joi.boolean().default(true),
'wrap-with-directory': Joi.boolean()
Expand Down
58 changes: 18 additions & 40 deletions test/cli/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,56 +205,34 @@ describe('files', () => runOnAndOff((thing) => {
})
})

// Temporarily expect to fail as raw-leaves not yet implemented.
//
// When cid-version=1 then raw-leaves MUST be present and false.
//
// This is because raw-leaves is not yet implemented in js-ipfs,
// and go-ipfs changes the value of raw-leaves to true when
// cid-version > 0 unless explicitly set to false.
//
// This retains feature parity without having to implement raw-leaves.
it('add with cid-version=1', function () {
this.timeout(30 * 1000)

return new Promise((resolve, reject) => {
ipfs('add src/init-files/init-docs/readme --cid-version=1')
.then(() => reject(new Error('Raw leaves not expected to be implemented')))
.catch((err) => {
expect(err).to.exist()
resolve()
})
})
return ipfs('add src/init-files/init-docs/readme --cid-version=1')
.then((out) => {
expect(out)
.to.eql('added zdj7WWeQ43G6JJvLWQWZpyHuAMq6uYWRjkBXFad11vE2LHhQ7 readme\n')
})
})

// TODO: this test is failing, @alanshaw?
it.skip('add with cid-version=1 and raw-leaves=false', () => {
return ipfs('add src/init-files/init-docs/readme --cid-version=1 --raw-leaves=false').then((out) => {
expect(out)
.to.eql('added zdj7WWeQ43G6JJvLWQWZpyHuAMq6uYWRjkBXFad11vE2LHhQ7 readme\n')
})
it('add with cid-version=1 and raw-leaves=false', () => {
this.timeout(30 * 1000)

return ipfs('add src/init-files/init-docs/readme --cid-version=1 --raw-leaves=false')
.then((out) => {
expect(out)
.to.eql('added zdj7WWeQ43G6JJvLWQWZpyHuAMq6uYWRjkBXFad11vE2LHhQ7 readme\n')
})
})

// Temporarily expect to fail as raw-leaves not yet implemented
//
// When cid-version=1 then raw-leaves MUST be present and false.
//
// This is because raw-leaves is not yet implemented in js-ipfs,
// and go-ipfs changes the value of raw-leaves to true when
// cid-version > 0 unless explicitly set to false.
//
// This retains feature parity without having to implement raw-leaves.
it('add with cid-version=1 and raw-leaves=true', function () {
this.timeout(30 * 1000)

return new Promise((resolve, reject) => {
ipfs('add src/init-files/init-docs/readme --cid-version=1 --raw-leaves=true')
.then(() => reject(new Error('Raw leaves not expected to be implemented')))
.catch((err) => {
expect(err).to.exist()
resolve()
})
})
return ipfs('add src/init-files/init-docs/readme --cid-version=1 --raw-leaves=true')
.then((out) => {
expect(out)
.to.eql('added zdj7WiLc855B1KPRgV7Fh8ivjuAhePE1tuJafmxH5HmmSjqaD readme\n')
})
})

it('add --quiet', function () {
Expand Down

0 comments on commit 7b92684

Please sign in to comment.