ipfs/kubo · error

can only update directories

Error message

can only update directories

What it means

Helper updatePath, used by `ipfs files chcid` to apply a new CID builder: after mfs.Lookup resolves the path, the type switch finds the node is not an *mfs.Directory (a regular file or symlink), so SetCidBuilder cannot be applied. Fires when a user points chcid at a file rather than a directory.

Source

Thrown at core/commands/files.go:1361

		return nil
	},
}

func updatePath(rt *mfs.Root, pth string, builder cid.Builder) error {
	if builder == nil {
		return nil
	}

	nd, err := mfs.Lookup(rt, pth)
	if err != nil {
		return err
	}

	switch n := nd.(type) {
	case *mfs.Directory:
		n.SetCidBuilder(builder)
	default:
		return fmt.Errorf("can only update directories")
	}

	return nil
}

var filesRmCmd = &cmds.Command{
	Helptext: cmds.HelpText{
		Tagline: "Remove a file from MFS.",
		ShortDescription: `
Remove files or directories.

    $ ipfs files rm /foo
    $ ipfs files ls /bar
    cat
    dog
    fish
    $ ipfs files rm -r /bar
`,

View on GitHub (pinned to 329838acdf)

Solutions

  1. Run `ipfs files chcid` on a directory path only; check the target with `ipfs files stat` first.
  2. If the whole tree should change CID format, apply chcid to the parent directory (it propagates on rebuild) rather than to individual files.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at core/commands/files.go:1361 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of ipfs/kubo@329838acdf (2026-09-03). Data as JSON: /api/errors/26dc865f9a4de8c9. Report an issue: GitHub.