mirror of
https://github.com/pnpm/pnpm.git
synced 2026-04-10 18:18:56 -04:00
fix: do not scan non-directories in store directory when pruning store
close #2563 PR #2644 Co-authored-by: Zoltan Kochan <zkochan@users.noreply.github.com> Co-authored-by: Zoltan Kochan <z@kochan.io>
This commit is contained in:
5
.changeset/orange-phones-press.md
Normal file
5
.changeset/orange-phones-press.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/package-store": patch
|
||||
---
|
||||
|
||||
only scan diretories when doing store prune
|
||||
@@ -14,7 +14,9 @@ export default async function prune (storeDir: string) {
|
||||
globalInfo('Removed all cached metadata files')
|
||||
const pkgIndexFiles = [] as string[]
|
||||
const removedHashes = new Set<string>()
|
||||
const dirs = await fs.readdir(cafsDir)
|
||||
const dirs = (await fs.readdir(cafsDir, { withFileTypes: true }))
|
||||
.filter(entry => entry.isDirectory())
|
||||
.map(dir => dir.name)
|
||||
let fileCounter = 0
|
||||
for (const dir of dirs) {
|
||||
const subdir = path.join(cafsDir, dir)
|
||||
|
||||
@@ -5,6 +5,7 @@ import prepare from '@pnpm/prepare'
|
||||
import { REGISTRY_MOCK_PORT } from '@pnpm/registry-mock'
|
||||
import rimraf = require('@zkochan/rimraf')
|
||||
import execa = require('execa')
|
||||
import fs = require('fs')
|
||||
import path = require('path')
|
||||
import R = require('ramda')
|
||||
import sinon = require('sinon')
|
||||
@@ -145,3 +146,21 @@ test('keep dependency used by package', async (t) => {
|
||||
await project.storeHas('is-positive', '3.1.0')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('prune will skip scanning non-directory in storeDir', async (t) => {
|
||||
const project = prepare(t)
|
||||
const storeDir = path.resolve('store')
|
||||
await execa('node', [pnpmBin, 'add', 'is-not-positive@1.0.0', 'is-positive@3.1.0', '--store-dir', storeDir, '--registry', REGISTRY])
|
||||
fs.writeFileSync(path.join(storeDir, STORE_VERSION, 'files/.DS_store'), 'foobar')
|
||||
|
||||
await store.handler({
|
||||
dir: process.cwd(),
|
||||
rawConfig: {
|
||||
registry: REGISTRY,
|
||||
},
|
||||
registries: { default: REGISTRY },
|
||||
storeDir,
|
||||
}, ['prune'])
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user