trganda / obsidian-attachment-management

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

[BUG] No rename attachment correctly when the new attachment path was already exists. #13

Closed trganda closed 1 year ago

trganda commented 1 year ago

On rename event, the callback will ignore to rename the attachment filename if the the attachment folder was already exists

    const exitsDst = await this.app.vault.adapter.exists(stripedNewAttachPath);
    if (exitsDst) {
      // if the file exists in the vault
      if (eventType === RENAME_EVENT_TYPE_FILE) {
        new Notice(`Same file name exists: ${stripedNewAttachPath}`);
        return;
      } else if (eventType === RENAME_EVENT_TYPE_FOLDER) {
        // for most case, this should not be happen, just notice it.
        new Notice(`Folder already exists: ${stripedNewAttachPath}`);
        return;
      }
    } else {
      const cfile = this.app.vault.getAbstractFileByPath(stripedOldAttachPath);
      if (cfile === null) {
        return;
      }
      await this.app.fileManager.renameFile(cfile, stripedNewAttachPath);
    }
trganda commented 1 year ago

fixed in https://github.com/trganda/obsidian-attachment-management/releases/tag/0.3.4