trganda / obsidian-attachment-management

Attachment Management of Obsidian
MIT License
143 stars 8 forks source link

New update just renamed all my files in my attachments folder #67

Open spiritualgeek opened 9 months ago

spiritualgeek commented 9 months ago

Was creating a new note in a folder

Within the folder I have an attachments folder

As I created the new note, all files were prefixed with the new note name?

This is a serious bug :/

Edit:

I know how this happens

My notes follow a strict naming methodology per folder

{fixed-prefix}-{variable-suffix}

If I create a note with the name {fixed-prefix}- and save, the plugin will go out and find all files starting with that and proceed to rename without considering which note is actually being edited

This will happen, on the odd occasion, when I'm still thinking what to name the {variable-suffix} portion and the note is saved

Can you please look into this?

Thanks

huyz commented 9 months ago

That does sound dangerous. I would rather just trigger a shortcut than have this be done automatically

trganda commented 9 months ago

I have just end my vocation, and I will take a look at this problem.

trganda commented 9 months ago

Hi @spiritualgeek, I will explain how rename operation working.

Suppose you have a note with name {fixed-prefix} and your setting is path = ${notepath}/${notename}, name = ${notename}-${date}, if your pasted a image file to the note {fixed-prefix}, the plugin will try to create a foler with ${notepath}/${notename} (we suppose the ${notepath} is empty and the folder was named with {fixed-prefix}). The folder {fixed-prefix} will have a attachment file {fixed-prefix}-${date}.

When you rename the note file {fixed-prefix} to {fixed-prefix}-, this plugin will calucate the attachemnt path with the old note name ({fixed-prefix}) and new name ({fixed-prefix}-). The result will be {fixed-prefix} and {fixed-prefix}-, then it rename the attachment folder from {fixed-prefix} to {fixed-prefix}-.

Af that, the plugin will traverse the new attachment folder {fixed-prefix}- and process each file, if the extension was satisfied, replace the {fixed-prefix} in the file name to {fixed-prefix}- directly.

This will leading some problem if you already have some file in the attachemnt file that filename contain the {fixed-prefix} but thery are not relate with the note. They will also be renamed.

The most important thing I want to say is, for the rename operation, the note was associate with the attachment folder. It not care about wherever the file in attachment folder was linked in the note. And this is for simple reason when I develop this plugin.

trganda commented 9 months ago

This will happen, on the odd occasion, when I'm still thinking what to name the {variable-suffix} portion and the note is saved

The advise is, not to create a note with name {fixed-prefix}-, you can write whatever in the {variable-suffix} and rename it when you think out.

spiritualgeek commented 9 months ago

Thank you for the detailed reply. It's an edge case that I will be careful with for now