fix: prevent ENOENT caused by parallel store prune (#8586)

* fix: prevent ENOENT caused by parallel `store prune`

Close #8579

* fix: cspell

* test: fix
This commit is contained in:
Khải
2024-09-30 07:44:05 +07:00
committed by GitHub
parent 9797a1e889
commit 81bd9427ad
4 changed files with 12 additions and 5 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/plugin-commands-store": patch
"pnpm": patch
---
Prevent ENOENT errors caused by running `store prune` in parallel.

View File

@@ -57,6 +57,7 @@
"enametoolong",
"endregion",
"eneedauth",
"enoent",
"enten",
"eperm",
"etamponi",

View File

@@ -78,7 +78,7 @@ test('cleanExpiredCache removes items that outlive dlxCacheMaxAge', async () =>
)
expect(rmSpy).toHaveBeenCalledWith(
expect.stringContaining(path.join(cacheDir, 'dlx', createCacheKey('baz'))),
{ recursive: true }
{ recursive: true, force: true }
)
readdirSyncSpy.mockRestore()
@@ -117,7 +117,7 @@ test('cleanExpiredCache removes all directories without checking stat if dlxCach
expect(readdirSyncSpy).toHaveBeenCalledWith(path.join(cacheDir, 'dlx'), expect.anything())
expect(lstatSpy).not.toHaveBeenCalled()
for (const key of ['foo', 'bar', 'baz']) {
expect(rmSpy).toHaveBeenCalledWith(path.join(cacheDir, 'dlx', createCacheKey(key)), { recursive: true })
expect(rmSpy).toHaveBeenCalledWith(path.join(cacheDir, 'dlx', createCacheKey(key)), { recursive: true, force: true })
}
readdirSyncSpy.mockRestore()

View File

@@ -30,7 +30,7 @@ export async function cleanExpiredDlxCache ({
}
if (shouldClean) {
// delete the symlink, the symlink's target, and orphans (if any)
await fs.rm(dlxCachePath, { recursive: true })
await fs.rm(dlxCachePath, { recursive: true, force: true })
}
}))
@@ -45,7 +45,7 @@ export async function cleanOrphans (dlxCacheDir: string): Promise<void> {
const dlxCacheLink = path.join(dlxCachePath, 'pkg')
const dlxCacheLinkStats = await getStats(dlxCacheLink)
if (dlxCacheLinkStats === 'ENOENT') {
return fs.rm(dlxCachePath, { recursive: true })
return fs.rm(dlxCachePath, { recursive: true, force: true })
}
const dlxCacheLinkTarget = await getRealPath(dlxCacheLink)
const children = await fs.readdir(dlxCachePath)
@@ -53,7 +53,7 @@ export async function cleanOrphans (dlxCacheDir: string): Promise<void> {
if (name === 'pkg') return
const fullPath = path.join(dlxCachePath, name)
if (fullPath === dlxCacheLinkTarget) return
await fs.rm(fullPath, { recursive: true })
await fs.rm(fullPath, { recursive: true, force: true })
}))
}))
}