( pluginId: string, )
| 128 | * Recursive walk — not hot-path (only on uninstall). |
| 129 | */ |
| 130 | export async function getPluginDataDirSize( |
| 131 | pluginId: string, |
| 132 | ): Promise<{ bytes: number; human: string } | null> { |
| 133 | const dir = pluginDataDirPath(pluginId) |
| 134 | let bytes = 0 |
| 135 | const walk = async (p: string) => { |
| 136 | for (const entry of await readdir(p, { withFileTypes: true })) { |
| 137 | const full = join(p, entry.name) |
| 138 | if (entry.isDirectory()) { |
| 139 | await walk(full) |
| 140 | } else { |
| 141 | // Per-entry catch: a broken symlink makes stat() throw ENOENT. |
| 142 | // Without this, one broken link bubbles to the outer catch → |
| 143 | // returns null → dialog skipped → data silently deleted. |
| 144 | try { |
| 145 | bytes += (await stat(full)).size |
| 146 | } catch { |
| 147 | // Broken symlink / raced delete — skip this entry, keep walking |
| 148 | } |
| 149 | } |
| 150 | } |
| 151 | } |
| 152 | try { |
| 153 | await walk(dir) |
| 154 | } catch (e) { |
| 155 | if (isFsInaccessible(e)) return null |
| 156 | throw e |
| 157 | } |
| 158 | if (bytes === 0) return null |
| 159 | return { bytes, human: formatFileSize(bytes) } |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * Best-effort cleanup on last-scope uninstall. Failure is logged but does |
no test coverage detected