Skip to content

Conversation

KapilSareen
Copy link
Contributor

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

  • Introduces the --pin-name flag to ipfs add

Example Usage

$ ipfs add test.go --pin --pin-name testname
added QmdZwVeTRV1m4YKNXUEd2tBjxkag7JY4Lwf2zmcVJbXKfi test.go

$ ipfs pin ls --names
QmesP6bmy8z4fMn2UzuaXpxur8Drm4VcWApqgPeEg47r3g recursive testname

Fixes #10341

@KapilSareen KapilSareen requested a review from a team as a code owner July 17, 2025 22:33
Copy link
Member

@lidel lidel left a 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 tests ipfs add with --pin-name works as expected
    • confirms --pin-name=foo created pin named foo
    • 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?
        • if in HTTP RPC, we ignore empty name?

@KapilSareen mind adding tests and addressing the behaviors above and making sure the CI is green?

Signed-off-by: kapil <kapilsareen584@gmail.com>
@KapilSareen
Copy link
Contributor Author

Done @lidel!

I’ve added tests in test/cli to confirm:

  • --pin-name=foo creates a named pin as expected
  • --pin=false --pin-name=foo returns an error
  • When --pin-name is passed without a value, the filename is used as the pin name

Currently, if the input is from stdin (e.g. echo hi | ipfs add --pin-name), it falls back to an empty string (i.e. no pin name is assigned).

Also added a changelog entry under docs/changelogs/v0.37.md.

Let me know if you'd like the fallback behavior tweaked further or if there's anything else missing!

@lidel lidel mentioned this pull request Jul 22, 2025
51 tasks
lidel added 2 commits August 6, 2025 01:07
- 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
Comment on lines 266 to 269
if pinName == "" {
it := req.Files.Entries()
if it.Next() {
pinName = it.Name()
Copy link
Member

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:

  1. 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)
  2. Impossible --pin-name without value: We cannot make --pin-name work without consuming next argument due to go-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.
  3. 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.

Copy link
Member

@lidel lidel left a 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

@lidel lidel merged commit 10abb90 into ipfs:master Aug 6, 2025
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ipfs add --name does not exist
2 participants