mirror of
https://github.com/pnpm/pnpm.git
synced 2026-04-27 18:46:18 -04:00
fix(worker): inconsistent store structure due to race condition (#10536)
close #10535
This commit is contained in:
5
.changeset/red-shirts-take.md
Normal file
5
.changeset/red-shirts-take.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/worker": patch
|
||||
---
|
||||
|
||||
Fix inconsistent store structure due to race condition.
|
||||
@@ -224,20 +224,25 @@ interface AddFilesFromDirResult {
|
||||
|
||||
function initStore ({ storeDir }: InitStoreMessage): { status: string } {
|
||||
fs.mkdirSync(storeDir, { recursive: true })
|
||||
try {
|
||||
const hexChars = '0123456789abcdef'.split('')
|
||||
for (const subDir of ['files', 'index']) {
|
||||
const subDirPath = path.join(storeDir, subDir)
|
||||
const hexChars = '0123456789abcdef'.split('')
|
||||
for (const subDir of ['files', 'index']) {
|
||||
const subDirPath = path.join(storeDir, subDir)
|
||||
try {
|
||||
fs.mkdirSync(subDirPath)
|
||||
for (const hex1 of hexChars) {
|
||||
for (const hex2 of hexChars) {
|
||||
} catch {
|
||||
// If a parallel process has already started creating the directories in the store,
|
||||
// ignore if it already exists.
|
||||
}
|
||||
for (const hex1 of hexChars) {
|
||||
for (const hex2 of hexChars) {
|
||||
try {
|
||||
fs.mkdirSync(path.join(subDirPath, `${hex1}${hex2}`))
|
||||
} catch {
|
||||
// If a parallel process has already started creating the directories in the store,
|
||||
// ignore if it already exists.
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// If a parallel process has already started creating the directories in the store,
|
||||
// then we just stop.
|
||||
}
|
||||
return { status: 'success' }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user