Skip to content

Commit

Permalink
fix: use shorter temp file name for the index files
Browse files Browse the repository at this point in the history
close #6842
  • Loading branch information
zkochan committed Jul 25, 2023
1 parent 5656424 commit de2a618
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/four-penguins-buy.md
Original file line number Diff line number Diff line change
@@ -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).
1 change: 0 additions & 1 deletion pkg-manager/package-requester/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 3 additions & 2 deletions pkg-manager/package-requester/src/packageRequester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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.substring(0, filePath.length - 11)}${process.pid}`
await gfs.writeFile(temp, JSON.stringify(data))
await optimisticRenameOverwrite(temp, filePath)
}
Expand Down

0 comments on commit de2a618

Please sign in to comment.