(root: string, oldRel: string, nextRel: string)
| 2748 | } |
| 2749 | |
| 2750 | async function moveNoteComments(root: string, oldRel: string, nextRel: string): Promise<void> { |
| 2751 | const oldAbs = noteCommentsPath(root, oldRel) |
| 2752 | const nextAbs = noteCommentsPath(root, nextRel) |
| 2753 | if (oldAbs === nextAbs) return |
| 2754 | try { |
| 2755 | await fs.access(oldAbs) |
| 2756 | } catch { |
| 2757 | return |
| 2758 | } |
| 2759 | await fs.mkdir(path.dirname(nextAbs), { recursive: true }) |
| 2760 | try { |
| 2761 | await fs.access(nextAbs) |
| 2762 | const [existing, moving] = await Promise.all([ |
| 2763 | readNoteComments(root, nextRel), |
| 2764 | readNoteComments(root, oldRel) |
| 2765 | ]) |
| 2766 | await writeNoteComments(root, nextRel, [...existing, ...moving]) |
| 2767 | await fs.rm(oldAbs, { force: true }) |
| 2768 | } catch (err) { |
| 2769 | if ((err as NodeJS.ErrnoException).code !== 'ENOENT') throw err |
| 2770 | await fs.rename(oldAbs, nextAbs) |
| 2771 | } |
| 2772 | } |
| 2773 | |
| 2774 | async function copyNoteComments(root: string, sourceRel: string, nextRel: string): Promise<void> { |
| 2775 | const source = await readNoteComments(root, sourceRel) |
no test coverage detected