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

fix: pin type filtering in pin.ls #2228

Merged
merged 4 commits into from
Jul 17, 2019
Merged

Conversation

lidel
Copy link
Member

@lidel lidel commented Jul 9, 2019

Summary

This PR fixes filtering, improves interop with go-ipfs and adds missing tests for pin ls

Details

Old version returned indirect pin when pin ls -t direct <path> was executed.

This PR also tweaks error handling to match behavior from go-ipfs/js-ipfs-http-client and pass improved interop tests added in ipfs-inactive/interface-js-ipfs-core#375

I've added some inline comments, hope it helps in review.

Related

Old version returned indirect pin
when `pin ls -t direct <path>` was executed.

This fixes filtering and adds necessary tests.

It also tweaks error handling to match behavior
from go-ipfs/js-ipfs-http-client and pass interop tests
from ipfs-inactive/interface-js-ipfs-core#375

License: MIT
Signed-off-by: Marcin Rataj <lidel@lidel.org>
@@ -327,7 +327,7 @@ module.exports = (self) => {
// check the pinned state of specific hashes
waterfall([
(cb) => resolvePath(self.object, paths, cb),
(hashes, cb) => mapSeries(hashes, (hash, done) => pin._isPinnedWithType(hash, types.all, done), cb),
(hashes, cb) => mapSeries(hashes, (hash, done) => pin._isPinnedWithType(hash, type, done), cb),
Copy link
Member Author

@lidel lidel Jul 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the fix for filtering 🙃

@@ -348,12 +348,12 @@ module.exports = (self) => {
})

if (!results.length) {
return cb(new Error(`Path is not pinned`))
return cb(new Error(`path '${paths}' is not pinned`))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to match error from go-ipfs
Interop test for this is added in https://github.com/ipfs/interface-js-ipfs-core/pull/375/files#diff-6a00eb1307f801bb37999815584589bdR190

@@ -57,7 +57,7 @@ exports.ls = {
try {
result = await ipfs.pin.ls(path, { type })
} catch (err) {
throw Boom.boomify(err, { message: 'Failed to list pins' })
throw Boom.boomify(err)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed message prefix to match error from go-ipfs.
Interop test for this is added in https://github.com/ipfs/interface-js-ipfs-core/pull/375/files#diff-6a00eb1307f801bb37999815584589bdR199

@@ -44,14 +45,22 @@ describe('pin', function () {
let pin
let repo

function expectPinned (hash, type, pinned = true) {
function expectPinned (hash, type = pinTypes.all, pinned = true) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expectPinned was not checking if returned type match requested one, so I've added double-check for that.


it('direct for path (no match)', function (done) {
pin.ls(`/ipfs/${pins.root}/mercury/wiki.md`, { type: 'direct' }, (err, pinset) => {
expect(err).to.exist()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make it easier to maintain the error message is not hardcoded here, but checked in interop tests:

Copy link
Contributor

@dirkmc dirkmc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@lidel
Copy link
Member Author

lidel commented Jul 15, 2019

@alanshaw ok to merge this and ipfs-inactive/interface-js-ipfs-core#375 before the fix gets old again? :)

alanshaw pushed a commit to ipfs-inactive/interface-js-ipfs-core that referenced this pull request Jul 16, 2019
This PR adds more detailed tests for `pin.ls`, including one that guards against issue described in ipfs-inactive/js-ipfs-http-client#875

refs ipfs/js-ipfs#2228

License: MIT
Signed-off-by: Marcin Rataj <lidel@lidel.org>
License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
@alanshaw alanshaw merged commit afdfe7f into ipfs:master Jul 17, 2019
@lidel lidel deleted the fix/pin-ls-filtering branch July 19, 2019 12:32
@dirkmc dirkmc mentioned this pull request Jul 19, 2019
11 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants