Skip to content

Commit ab7d3cd

Browse files
authored
[ENG-1072] Error "Folder already exists" when create new canvas (#601)
* a small safeguard * normalize the name to fix bug * pr comment
1 parent ba090dd commit ab7d3cd

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

apps/obsidian/src/components/GeneralSettings.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,19 @@ const GeneralSettings = () => {
191191
}, []);
192192

193193
const handleSave = async () => {
194+
const trimmedNodesFolderPath = nodesFolderPath.trim();
195+
const trimmedCanvasFolderPath = canvasFolderPath.trim();
196+
const trimmedCanvasAttachmentsFolderPath =
197+
canvasAttachmentsFolderPath.trim();
194198
plugin.settings.showIdsInFrontmatter = showIdsInFrontmatter;
195-
plugin.settings.nodesFolderPath = nodesFolderPath;
196-
plugin.settings.canvasFolderPath = canvasFolderPath;
197-
plugin.settings.canvasAttachmentsFolderPath = canvasAttachmentsFolderPath;
199+
plugin.settings.nodesFolderPath = trimmedNodesFolderPath;
200+
plugin.settings.canvasFolderPath = trimmedCanvasFolderPath;
201+
plugin.settings.canvasAttachmentsFolderPath =
202+
trimmedCanvasAttachmentsFolderPath;
198203
plugin.settings.nodeTagHotkey = nodeTagHotkey || "";
204+
setNodesFolderPath(trimmedNodesFolderPath);
205+
setCanvasFolderPath(trimmedCanvasFolderPath);
206+
setCanvasAttachmentsFolderPath(trimmedCanvasAttachmentsFolderPath);
199207
await plugin.saveSettings();
200208
new Notice("General settings saved");
201209
setHasUnsavedChanges(false);

apps/obsidian/src/utils/file.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ import { TAbstractFile, TFolder, Vault, normalizePath } from "obsidian";
22

33
export const checkAndCreateFolder = async (folderpath: string, vault: Vault) => {
44
if (!folderpath) return;
5+
const normalizedPath = normalizePath(folderpath);
56

6-
const abstractItem = vault.getAbstractFileByPath(folderpath);
7+
const abstractItem = vault.getAbstractFileByPath(normalizedPath);
78
if (abstractItem instanceof TFolder) return;
89
if (abstractItem instanceof TAbstractFile) {
9-
throw new Error(`${folderpath} exists as a file`);
10+
throw new Error(`${normalizedPath} exists as a file`);
1011
}
11-
await vault.createFolder(folderpath);
12+
await vault.createFolder(normalizedPath);
1213
};
1314

1415
export const getNewUniqueFilepath = ({

0 commit comments

Comments
 (0)