( versionPath: string, now: number, )
| 147 | } |
| 148 | |
| 149 | async function processOrphanedPluginVersion( |
| 150 | versionPath: string, |
| 151 | now: number, |
| 152 | ): Promise<void> { |
| 153 | const orphanedAtPath = getOrphanedAtPath(versionPath) |
| 154 | |
| 155 | let orphanedAt: number |
| 156 | try { |
| 157 | orphanedAt = (await stat(orphanedAtPath)).mtimeMs |
| 158 | } catch (error) { |
| 159 | const code = getErrnoCode(error) |
| 160 | if (code === 'ENOENT') { |
| 161 | await markPluginVersionOrphaned(versionPath) |
| 162 | return |
| 163 | } |
| 164 | logForDebugging(`Failed to stat orphaned marker: ${versionPath}: ${error}`) |
| 165 | return |
| 166 | } |
| 167 | |
| 168 | if (now - orphanedAt > CLEANUP_AGE_MS) { |
| 169 | try { |
| 170 | await rm(versionPath, { recursive: true, force: true }) |
| 171 | } catch (error) { |
| 172 | logForDebugging( |
| 173 | `Failed to delete orphaned version: ${versionPath}: ${error}`, |
| 174 | ) |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | async function removeIfEmpty(dirPath: string): Promise<void> { |
| 180 | if ((await readSubdirs(dirPath)).length === 0) { |
no test coverage detected