-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
feat(add): add support for naming pinned CIDs #10877
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
Conversation
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.
Thank you for submitting this, looks like an useful feature.
Before merging, we need:
- add short description of the new feature -- ok to reuse example from this PR -- to
docs/changelogs/v0.37.md
- add tests to
test/cli
that testsipfs add
with--pin-name
works as expected- confirms
--pin-name=foo
created pin namedfoo
- confirms
--pin=false --pin-name=foo
produces an error - confirms what happens if no value is passed to
--pin-name
- easiest way is to always require name, and don't do any magic
- if we want to do magic, then it needs to be robus:
- if in CLI, and not piped, the source filename is used
- what happens if added file was added from stdin (
echo hi | ipfs add --pin-name
)? ignore empty name?
- what happens if added file was added from stdin (
- if in HTTP RPC, we ignore empty name?
- if in CLI, and not piped, the source filename is used
- confirms
@KapilSareen mind adding tests and addressing the behaviors above and making sure the CI is green?
Signed-off-by: kapil <kapilsareen584@gmail.com>
d3d933a
to
1d27b9d
Compare
Done @lidel! I’ve added tests in
Currently, if the input is from Also added a changelog entry under Let me know if you'd like the fallback behavior tweaked further or if there's anything else missing! |
- modify PinRoot to accept name parameter, eliminating double pinning - remove automatic filename fallback logic for cleaner behavior - only create named pins when explicitly requested via --pin-name=value - replace NoPinName constant with idiomatic empty string literals - Update help text and tests to reflect explicit-only behavior
core/commands/add.go
Outdated
if pinName == "" { | ||
it := req.Files.Entries() | ||
if it.Next() { | ||
pinName = it.Name() |
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.
The failing tests reveal current implementation has several problematic behaviors:
- Automatic filename as pin name: When no
--pin-name
is provided, it automatically uses filename, but filename is known only in CLI only when not piped (if piped or over HTTP, we still have no name) - Impossible
--pin-name
without value: We cannot make--pin-name
work without consuming next argument due togo-ipfs-cmds
limitations. This is potentially bad because--pin-name foo
will consume "foo" but--pin-name -Q foo
will consume-Q
(?). In general, gets hairy. - Error-prone magic behavior: (imo) users familiar with unix tools don't expect automatic pin naming when they don't specify the flag.
I still think --pin-name=value
is useful, so let's reduce scope of this PR to that, and remove magic that automatically "guesses" the value. If --pin-name
is passed, user needs to provide value, or it errors.
Since I've already reviewed things, its easier if I do it – I'll apply changes shortly.
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.
Thank you @KapilSareen, I've simplified to require explicit ---pin-name
to unblock merging this.
Lgtm, we will include it in v0.37
This PR adds support for assigning a human-readable name to a pinned CID. Named pins enhance usability by allowing users to refer to content symbolically instead of using raw multihashes.
Changes
--pin-name
flag toipfs add
Example Usage
Fixes #10341