fix: use shorter temp file name for the index files (#6863)

close #6842

Co-authored-by: David Michon <dmichon@microsoft.com>
This commit is contained in:
Zoltan Kochan
2023-07-26 12:44:06 +03:00
committed by GitHub
parent 56564248c5
commit dac59e6321
4 changed files with 9 additions and 6 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/package-requester": patch
"pnpm": patch
---
The length of the temporary file names in the content-addressable store reduced in order to prevent `ENAMETOOLONG` errors from happening [#6842](https://github.com/pnpm/pnpm/issues/6842).

View File

@@ -52,7 +52,6 @@
"p-limit": "^3.1.0",
"p-map-values": "^1.0.0",
"p-queue": "^6.6.2",
"path-temp": "^2.1.0",
"promise-share": "^1.0.0",
"ramda": "npm:@pnpm/ramda@0.28.1",
"safe-promise-defer": "^1.0.1",

View File

@@ -49,7 +49,6 @@ import pMapValues from 'p-map-values'
import PQueue from 'p-queue'
import loadJsonFile from 'load-json-file'
import pDefer from 'p-defer'
import { fastPathTemp as pathTemp } from 'path-temp'
import pShare from 'promise-share'
import pick from 'ramda/src/pick'
import semver from 'semver'
@@ -656,7 +655,9 @@ async function writeJsonFile (filePath: string, data: unknown) {
// There is actually no need to create the directory in 99% of cases.
// So by using cafs API, we'll improve performance.
await fs.mkdir(targetDir, { recursive: true })
const temp = pathTemp(filePath)
// We remove the "-index.json" from the end of the temp file name
// in order to avoid ENAMETOOLONG errors
const temp = `${filePath.slice(0, -11)}${process.pid}`
await gfs.writeFile(temp, JSON.stringify(data))
await optimisticRenameOverwrite(temp, filePath)
}

3
pnpm-lock.yaml generated
View File

@@ -3633,9 +3633,6 @@ importers:
p-queue:
specifier: ^6.6.2
version: 6.6.2
path-temp:
specifier: ^2.1.0
version: 2.1.0
promise-share:
specifier: ^1.0.0
version: 1.0.0