fix: too long file names when writing to store

close #2605
PR #2607
This commit is contained in:
Zoltan Kochan
2020-06-03 22:33:09 +03:00
committed by GitHub
parent 2962c83bb4
commit a203bc1380
4 changed files with 23 additions and 6 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/package-requester": patch
---
The temporary file name to which the package index is written should not be longer than the target file name.

View File

@@ -48,12 +48,12 @@
"p-defer": "^3.0.0",
"p-limit": "2.3.0",
"p-queue": "^6.4.0",
"path-temp": "^2.0.0",
"promise-share": "1.0.0",
"ramda": "0.27.0",
"rename-overwrite": "^3.0.0",
"ssri": "6.0.1",
"symlink-dir": "^4.0.3",
"write-json-file": "4.0.0"
"symlink-dir": "^4.0.3"
},
"devDependencies": {
"@pnpm/local-resolver": "workspace:*",

View File

@@ -38,10 +38,11 @@ import * as fs from 'mz/fs'
import pDefer = require('p-defer')
import PQueue from 'p-queue'
import path = require('path')
import pathTemp = require('path-temp')
import pShare = require('promise-share')
import R = require('ramda')
import renameOverwrite = require('rename-overwrite')
import ssri = require('ssri')
import writeJsonFile = require('write-json-file')
import safeDeferredPromise from './safeDeferredPromise'
const TARBALL_INTEGRITY_FILENAME = 'tarball-integrity'
@@ -471,7 +472,7 @@ function fetchToStore (
}
})
)
await writeJsonFile(filesIndexFile, { files: integrity }, { indent: undefined })
await writeJsonFile(filesIndexFile, { files: integrity })
finishing.resolve(undefined)
if (isLocalTarballDep && opts.resolution['integrity']) { // tslint:disable-line:no-string-literal
@@ -492,6 +493,17 @@ function fetchToStore (
}
}
async function writeJsonFile (filePath: string, data: Object) {
const targetDir = path.dirname(filePath)
// TODO: use the API of @pnpm/cafs to write this file
// 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(targetDir)
await fs.writeFile(temp, JSON.stringify(data))
await renameOverwrite(temp, filePath)
}
async function readBundledManifest (pkgJsonPath: string): Promise<BundledManifest> {
return pickBundledManifest(await readPackage(pkgJsonPath) as DependencyManifest)
}

4
pnpm-lock.yaml generated
View File

@@ -1233,12 +1233,12 @@ importers:
p-defer: 3.0.0
p-limit: 2.3.0
p-queue: 6.4.0
path-temp: 2.0.0
promise-share: 1.0.0
ramda: 0.27.0
rename-overwrite: 3.0.0
ssri: 6.0.1
symlink-dir: 4.0.3
write-json-file: 4.0.0
devDependencies:
'@pnpm/local-resolver': 'link:../local-resolver'
'@pnpm/logger': 3.2.2
@@ -1286,6 +1286,7 @@ importers:
p-defer: ^3.0.0
p-limit: 2.3.0
p-queue: ^6.4.0
path-temp: ^2.0.0
promise-share: 1.0.0
ramda: 0.27.0
rename-overwrite: ^3.0.0
@@ -1293,7 +1294,6 @@ importers:
ssri: 6.0.1
symlink-dir: ^4.0.3
tempy: 0.5.0
write-json-file: 4.0.0
packages/package-store:
dependencies:
'@pnpm/cafs': 'link:../cafs'