ipfs/kubo · error

%s: MFS destination parent %q %q does not exist: %w

Error message

%s: MFS destination parent %q %q does not exist: %w

What it means

Before linking the added node into MFS, the command verifies the parent directory of the --to-files destination exists via mfs.Lookup; if it does not, this error wraps the lookup failure. MFS does not auto-create intermediate directories on PutNode, so a missing parent is fatal.

Source

Thrown at core/commands/add.go:615

						}
						// confirm dst is a dir
						if mfsNode.Type() != mfs.TDir {
							errCh <- fmt.Errorf("%s: MFS destination %q is not a directory", toFilesOptionName, toFilesDst)
							return
						}
						// if MFS destination is a dir, append filename to the dir path
						toFilesDst += gopath.Base(addit.Name())
					}

					// error if we try to overwrite a preexisting file destination
					if fileAddedToMFS && !dstAsDir {
						errCh <- fmt.Errorf("%s: MFS destination is a file: only one entry can be copied to %q", toFilesOptionName, toFilesDst)
						return
					}

					_, err = mfs.Lookup(ipfsNode.FilesRoot, gopath.Dir(toFilesDst))
					if err != nil {
						errCh <- fmt.Errorf("%s: MFS destination parent %q %q does not exist: %w", toFilesOptionName, toFilesDst, gopath.Dir(toFilesDst), err)
						return
					}

					var nodeAdded ipld.Node
					nodeAdded, err = api.Dag().Get(req.Context, pathAdded.RootCid())
					if err != nil {
						errCh <- err
						return
					}
					err = mfs.PutNode(ipfsNode.FilesRoot, toFilesDst, nodeAdded)
					if err != nil {
						errCh <- fmt.Errorf("%s: cannot put node in path %q: %w", toFilesOptionName, toFilesDst, err)
						return
					}
					fileAddedToMFS = true
				}
				errCh <- err
			}()

View on GitHub (pinned to 329838acdf)

Solutions

  1. Create the parent directory first: ipfs files mkdir -p /a/b
  2. Use an existing MFS directory as the destination (trailing slash form)
  3. Correct the typo in the --to-files path

Example fix

// before
ipfs add --to-files /a/b/c.txt file   # /a/b missing
// after
ipfs files mkdir -p /a/b
ipfs add --to-files /a/b/c.txt file
Defensive patterns

Strategy: validation

Validate before calling

// create parent dirs before add --to-files
parent=$(dirname "$DST")
ipfs files mkdir -p "$parent"
ipfs add --to-files "$DST" "$FILE"

Prevention

When it happens

Trigger: Run `ipfs add --to-files /a/b/c.txt file` where /a/b does not exist in MFS: mfs.Lookup(FilesRoot, '/a/b') fails, producing '--to-files: MFS destination parent "/a/b/c.txt" "/a/b" does not exist: <lookup error>'.

Common situations: Fresh node with empty MFS (no /tmp or /docs created yet); typo in destination path; scripts assuming --to-files creates nested paths implicitly like mkdir -p.

Related errors


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