( fileName: string, targetPath: string, mode?: number )
| 72 | } |
| 73 | |
| 74 | export async function migrateLegacyFile( |
| 75 | fileName: string, |
| 76 | targetPath: string, |
| 77 | mode?: number |
| 78 | ): Promise<void> { |
| 79 | const legacyPath = getLegacyFilePath(fileName); |
| 80 | if (legacyPath === targetPath || (await exists(targetPath)) || !(await exists(legacyPath))) { |
| 81 | return; |
| 82 | } |
| 83 | |
| 84 | try { |
| 85 | await mkdir(path.dirname(targetPath), { recursive: true, mode: 0o700 }); |
| 86 | await rename(legacyPath, targetPath); |
| 87 | if (mode !== undefined) { |
| 88 | await chmod(targetPath, mode); |
| 89 | } |
| 90 | } catch { |
| 91 | // Leave the legacy file in place; readers resolve to it via resolveReadPath. |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Returns the path to read from: the XDG target after attempting migration, |
no test coverage detected