-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added 'pin ls' Command #364
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
90e5c7f
pin: Added a Pinner#Set function to retrieve the set of pinned keys
mappum afc7b6f
core/commands: Added a 'pin ls' command
mappum 961e450
core/commands: Fixed pin flag name (conflicted with global -r/--recur…
mappum edb8eea
core/commands: Created a general key list output type and plaintext m…
mappum 477c246
core/commands: Fixed 'refs' option name collision
mappum db53de8
core/commands: Made 'refs' output u.Keys instead of strings
mappum 49dc13e
core/commands: Added plaintext marshaler for 'pin ls'
mappum 277ba26
commands: Gave global options exported names
mappum bbf3a1f
commands: Changed Option to an interface
mappum aa84f69
commands: Added a 'Definition()' method to OptionValue to get a refer…
mappum 761392d
commands/cli: Only allow recursive paths if -r option definition is O…
mappum 87853f2
core/commands: Made 'add' use OptionRecursivePath
mappum 4c1a5f6
core/commands: Restored 'pin'/'refs' option names
mappum ae6f00d
commands: Fixed tests
mappum e6091be
pin: Return copies of pinned keys, of each type (direct/indirect/recu…
mappum 9de0100
core/commands: pin ls: Accept 'type' option to specify type of pinned…
mappum 69ce294
commands/cli: Fixed helptext option type
mappum 928f20b
core/commands: pin ls: Default type to 'direct'
mappum 5461d76
core/commands: Better syntax for 'pin ls' option value handling
mappum 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
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
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
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 |
---|---|---|
|
@@ -6,6 +6,7 @@ import ( | |
cmds "github.com/jbenet/go-ipfs/commands" | ||
"github.com/jbenet/go-ipfs/core" | ||
"github.com/jbenet/go-ipfs/merkledag" | ||
u "github.com/jbenet/go-ipfs/util" | ||
) | ||
|
||
var pinCmd = &cmds.Command{ | ||
|
@@ -16,6 +17,7 @@ var pinCmd = &cmds.Command{ | |
Subcommands: map[string]*cmds.Command{ | ||
"add": addPinCmd, | ||
"rm": rmPinCmd, | ||
"ls": listPinCmd, | ||
}, | ||
} | ||
|
||
|
@@ -99,6 +101,68 @@ collected if needed. | |
}, | ||
} | ||
|
||
var listPinCmd = &cmds.Command{ | ||
Helptext: cmds.HelpText{ | ||
Tagline: "List objects pinned to local storage", | ||
ShortDescription: ` | ||
Returns a list of hashes of objects being pinned. Objects that are indirectly | ||
or recursively pinned are not included in the list. | ||
`, | ||
LongDescription: ` | ||
Returns a list of hashes of objects being pinned. Objects that are indirectly | ||
or recursively pinned are not included in the list. | ||
|
||
Use --type=<type> to specify the type of pinned keys to list. Valid values are: | ||
* "direct" | ||
* "indirect" | ||
* "recursive" | ||
* "all" | ||
(Defaults to "direct") | ||
`, | ||
}, | ||
|
||
Options: []cmds.Option{ | ||
cmds.StringOption("type", "t", "The type of pinned keys to list. Can be \"direct\", \"indirect\", \"recursive\", or \"all\". Defaults to \"direct\""), | ||
}, | ||
Run: func(req cmds.Request) (interface{}, error) { | ||
n, err := req.Context().GetNode() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
typeStr, found, err := req.Option("type").String() | ||
if err != nil { | ||
return nil, err | ||
} | ||
if !found { | ||
typeStr = "direct" | ||
} | ||
|
||
switch typeStr { | ||
case "all", "direct", "indirect", "recursive": | ||
default: | ||
return nil, cmds.ClientError("Invalid type '" + typeStr + "', must be one of {direct, indirect, recursive, all}") | ||
} | ||
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. switch typeStr {
case "all", "direct", "indirect", "recursive":
default:
return nil, cmds.ClientError("Invalid type '" + typeStr + "', must be one of {direct, indirect, recursive, all}")
} |
||
|
||
keys := make([]u.Key, 0) | ||
if typeStr == "direct" || typeStr == "all" { | ||
keys = append(keys, n.Pinning.DirectKeys()...) | ||
} | ||
if typeStr == "indirect" || typeStr == "all" { | ||
keys = append(keys, n.Pinning.IndirectKeys()...) | ||
} | ||
if typeStr == "recursive" || typeStr == "all" { | ||
keys = append(keys, n.Pinning.RecursiveKeys()...) | ||
} | ||
|
||
return &KeyList{Keys: keys}, nil | ||
}, | ||
Type: &KeyList{}, | ||
Marshalers: cmds.MarshalerMap{ | ||
cmds.Text: KeyListTextMarshaler, | ||
}, | ||
} | ||
|
||
func pin(n *core.IpfsNode, paths []string, recursive bool) ([]*merkledag.Node, error) { | ||
|
||
dagnodes := make([]*merkledag.Node, 0) | ||
|
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.
is this planning to change later on?
Maybe: