( root: string, topFolder: NoteFolder, oldSubpath: string, newSubpath: string )
| 755 | } |
| 756 | |
| 757 | export async function renameFolder( |
| 758 | root: string, |
| 759 | topFolder: NoteFolder, |
| 760 | oldSubpath: string, |
| 761 | newSubpath: string |
| 762 | ): Promise<string> { |
| 763 | const oldClean = oldSubpath.replace(/^\/+|\/+$/g, '') |
| 764 | const newClean = newSubpath.replace(/^\/+|\/+$/g, '') |
| 765 | if (!oldClean || !newClean) throw new Error('Both old and new folder paths are required') |
| 766 | const folderAbs = await folderRoot(root, topFolder) |
| 767 | const oldAbs = resolveSafe(folderAbs, oldClean) |
| 768 | const newAbs = resolveSafe(folderAbs, newClean) |
| 769 | if (newAbs === oldAbs) return newClean |
| 770 | if ((newAbs + path.sep).startsWith(oldAbs + path.sep)) { |
| 771 | throw new Error('Cannot move a folder into itself') |
| 772 | } |
| 773 | await fs.mkdir(path.dirname(newAbs), { recursive: true }) |
| 774 | await fs.rename(oldAbs, newAbs) |
| 775 | return newClean |
| 776 | } |
| 777 | |
| 778 | export async function deleteFolder( |
| 779 | root: string, |
no test coverage detected