Skip to content

fix: create destination directory when moving a note - #135

Merged
Yakitrak merged 1 commit into
Yakitrak:mainfrom
postoso:fix/move-creates-destination-directory
Sep 1, 2026
Merged

fix: create destination directory when moving a note#135
Yakitrak merged 1 commit into
Yakitrak:mainfrom
postoso:fix/move-creates-destination-directory

Conversation

@postoso

@postoso postoso commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Description

move now creates any missing directories in the destination path before renaming the file, so notesmd-cli move "Target Note" "newfolder/Target Note" works without running mkdir first.

(*Note).Move called os.Rename and mapped every error to NoteDoesNotExistError. os.Rename returns ENOENT when the destination directory is missing, so the command printed "Cannot find note in vault" and blamed a source note that was sitting right there. The source is now checked before the directory is created, so a genuinely missing note still reports NoteDoesNotExistError and does not leave an empty destination folder behind on its way to failing.

Motivation and Context

Fixes #134.

That issue offered two options, better error text or creating the folder, and asked which you preferred. I went with creating it because create and daily already do exactly this for their note paths (pkg/actions/create.go:43, pkg/actions/daily.go:47), which left move as the odd one out. If you would rather move stay conservative and just report the missing folder, say so and I will swap the os.MkdirAll for a check on the parent directory plus a new error constant. It is a small change either way.

Two subtests added to TestMoveNote: one moves a note into a nested path that does not exist yet, one checks that a missing source note fails without creating the destination directory. The first fails on unpatched note.go with the exact error from the issue.

The README line for move gains the same sentence the create section already has about intermediate directories.

Checklist:

  • I have written unit tests for my changes.
  • I have updated the documentation accordingly.
  • All new and existing tests passed.

os.Rename fails with ENOENT when the destination directory does not exist,
and Move mapped every rename error to NoteDoesNotExistError, so moving a
note into a new folder reported "Cannot find note in vault" even though
the source note was there.

Create the intermediate directories before the rename, matching what
create and daily already do for their note paths. The source is checked
first so a genuinely missing note still reports NoteDoesNotExistError and
does not leave an empty destination directory behind.

Fixes Yakitrak#134

@Yakitrak Yakitrak left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thats for the PR!

@Yakitrak
Yakitrak merged commit 3c72f74 into Yakitrak:main Sep 1, 2026
3 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.

move reports source missing when destination folder does not exist

2 participants