Skip to content

Commit 7af81c7

Browse files
committed
deps: cacache@18.0.0
1 parent b0849ab commit 7af81c7

File tree

166 files changed

+25836
-15
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

166 files changed

+25836
-15
lines changed

node_modules/.gitignore

+25
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
!/@npmcli/installed-package-contents
2929
!/@npmcli/map-workspaces
3030
!/@npmcli/metavuln-calculator
31+
!/@npmcli/metavuln-calculator/node_modules/
32+
/@npmcli/metavuln-calculator/node_modules/*
33+
!/@npmcli/metavuln-calculator/node_modules/cacache
3134
!/@npmcli/name-from-folder
3235
!/@npmcli/node-gyp
3336
!/@npmcli/package-json
@@ -71,6 +74,9 @@
7174
!/buffer
7275
!/builtins
7376
!/cacache
77+
!/cacache/node_modules/
78+
/cacache/node_modules/*
79+
!/cacache/node_modules/lru-cache
7480
!/chalk
7581
!/chownr
7682
!/ci-info
@@ -146,6 +152,9 @@
146152
!/just-diff
147153
!/lru-cache
148154
!/make-fetch-happen
155+
!/make-fetch-happen/node_modules/
156+
/make-fetch-happen/node_modules/*
157+
!/make-fetch-happen/node_modules/cacache
149158
!/minimatch
150159
!/minipass-collect
151160
!/minipass-collect/node_modules/
@@ -183,6 +192,13 @@
183192
!/node-gyp/node_modules/abbrev
184193
!/node-gyp/node_modules/are-we-there-yet
185194
!/node-gyp/node_modules/brace-expansion
195+
!/node-gyp/node_modules/cacache
196+
!/node-gyp/node_modules/cacache/node_modules/
197+
/node-gyp/node_modules/cacache/node_modules/*
198+
!/node-gyp/node_modules/cacache/node_modules/brace-expansion
199+
!/node-gyp/node_modules/cacache/node_modules/glob
200+
!/node-gyp/node_modules/cacache/node_modules/minimatch
201+
!/node-gyp/node_modules/cacache/node_modules/minipass
186202
!/node-gyp/node_modules/gauge
187203
!/node-gyp/node_modules/glob
188204
!/node-gyp/node_modules/make-fetch-happen
@@ -214,6 +230,7 @@
214230
!/pacote/node_modules/@npmcli/
215231
/pacote/node_modules/@npmcli/*
216232
!/pacote/node_modules/@npmcli/git
233+
!/pacote/node_modules/cacache
217234
!/parse-conflict-json
218235
!/path-is-absolute
219236
!/path-key
@@ -255,6 +272,10 @@
255272
!/sigstore
256273
!/sigstore/node_modules/
257274
/sigstore/node_modules/*
275+
!/sigstore/node_modules/cacache
276+
!/sigstore/node_modules/cacache/node_modules/
277+
/sigstore/node_modules/cacache/node_modules/*
278+
!/sigstore/node_modules/cacache/node_modules/minipass
258279
!/sigstore/node_modules/make-fetch-happen
259280
!/sigstore/node_modules/minipass
260281
!/smart-buffer
@@ -285,6 +306,10 @@
285306
!/tuf-js
286307
!/tuf-js/node_modules/
287308
/tuf-js/node_modules/*
309+
!/tuf-js/node_modules/cacache
310+
!/tuf-js/node_modules/cacache/node_modules/
311+
/tuf-js/node_modules/cacache/node_modules/*
312+
!/tuf-js/node_modules/cacache/node_modules/minipass
288313
!/tuf-js/node_modules/make-fetch-happen
289314
!/tuf-js/node_modules/minipass
290315
!/unique-filename
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
ISC License
2+
3+
Copyright (c) npm, Inc.
4+
5+
Permission to use, copy, modify, and/or distribute this software for
6+
any purpose with or without fee is hereby granted, provided that the
7+
above copyright notice and this permission notice appear in all copies.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS" AND THE COPYRIGHT HOLDER DISCLAIMS
10+
ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11+
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12+
COPYRIGHT HOLDER BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
13+
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
14+
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15+
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
16+
USE OR PERFORMANCE OF THIS SOFTWARE.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict'
2+
3+
const contentVer = require('../../package.json')['cache-version'].content
4+
const hashToSegments = require('../util/hash-to-segments')
5+
const path = require('path')
6+
const ssri = require('ssri')
7+
8+
// Current format of content file path:
9+
//
10+
// sha512-BaSE64Hex= ->
11+
// ~/.my-cache/content-v2/sha512/ba/da/55deadbeefc0ffee
12+
//
13+
module.exports = contentPath
14+
15+
function contentPath (cache, integrity) {
16+
const sri = ssri.parse(integrity, { single: true })
17+
// contentPath is the *strongest* algo given
18+
return path.join(
19+
contentDir(cache),
20+
sri.algorithm,
21+
...hashToSegments(sri.hexDigest())
22+
)
23+
}
24+
25+
module.exports.contentDir = contentDir
26+
27+
function contentDir (cache) {
28+
return path.join(cache, `content-v${contentVer}`)
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
'use strict'
2+
3+
const fs = require('fs/promises')
4+
const fsm = require('fs-minipass')
5+
const ssri = require('ssri')
6+
const contentPath = require('./path')
7+
const Pipeline = require('minipass-pipeline')
8+
9+
module.exports = read
10+
11+
const MAX_SINGLE_READ_SIZE = 64 * 1024 * 1024
12+
async function read (cache, integrity, opts = {}) {
13+
const { size } = opts
14+
const { stat, cpath, sri } = await withContentSri(cache, integrity, async (cpath, sri) => {
15+
// get size
16+
const stat = await fs.stat(cpath)
17+
return { stat, cpath, sri }
18+
})
19+
if (typeof size === 'number' && stat.size !== size) {
20+
throw sizeError(size, stat.size)
21+
}
22+
23+
if (stat.size > MAX_SINGLE_READ_SIZE) {
24+
return readPipeline(cpath, stat.size, sri, new Pipeline()).concat()
25+
}
26+
27+
const data = await fs.readFile(cpath, { encoding: null })
28+
if (!ssri.checkData(data, sri)) {
29+
throw integrityError(sri, cpath)
30+
}
31+
32+
return data
33+
}
34+
35+
const readPipeline = (cpath, size, sri, stream) => {
36+
stream.push(
37+
new fsm.ReadStream(cpath, {
38+
size,
39+
readSize: MAX_SINGLE_READ_SIZE,
40+
}),
41+
ssri.integrityStream({
42+
integrity: sri,
43+
size,
44+
})
45+
)
46+
return stream
47+
}
48+
49+
module.exports.stream = readStream
50+
module.exports.readStream = readStream
51+
52+
function readStream (cache, integrity, opts = {}) {
53+
const { size } = opts
54+
const stream = new Pipeline()
55+
// Set all this up to run on the stream and then just return the stream
56+
Promise.resolve().then(async () => {
57+
const { stat, cpath, sri } = await withContentSri(cache, integrity, async (cpath, sri) => {
58+
// just stat to ensure it exists
59+
const stat = await fs.stat(cpath)
60+
return { stat, cpath, sri }
61+
})
62+
if (typeof size === 'number' && size !== stat.size) {
63+
return stream.emit('error', sizeError(size, stat.size))
64+
}
65+
66+
return readPipeline(cpath, stat.size, sri, stream)
67+
}).catch(err => stream.emit('error', err))
68+
69+
return stream
70+
}
71+
72+
module.exports.copy = copy
73+
74+
function copy (cache, integrity, dest) {
75+
return withContentSri(cache, integrity, (cpath, sri) => {
76+
return fs.copyFile(cpath, dest)
77+
})
78+
}
79+
80+
module.exports.hasContent = hasContent
81+
82+
async function hasContent (cache, integrity) {
83+
if (!integrity) {
84+
return false
85+
}
86+
87+
try {
88+
return await withContentSri(cache, integrity, async (cpath, sri) => {
89+
const stat = await fs.stat(cpath)
90+
return { size: stat.size, sri, stat }
91+
})
92+
} catch (err) {
93+
if (err.code === 'ENOENT') {
94+
return false
95+
}
96+
97+
if (err.code === 'EPERM') {
98+
/* istanbul ignore else */
99+
if (process.platform !== 'win32') {
100+
throw err
101+
} else {
102+
return false
103+
}
104+
}
105+
}
106+
}
107+
108+
async function withContentSri (cache, integrity, fn) {
109+
const sri = ssri.parse(integrity)
110+
// If `integrity` has multiple entries, pick the first digest
111+
// with available local data.
112+
const algo = sri.pickAlgorithm()
113+
const digests = sri[algo]
114+
115+
if (digests.length <= 1) {
116+
const cpath = contentPath(cache, digests[0])
117+
return fn(cpath, digests[0])
118+
} else {
119+
// Can't use race here because a generic error can happen before
120+
// a ENOENT error, and can happen before a valid result
121+
const results = await Promise.all(digests.map(async (meta) => {
122+
try {
123+
return await withContentSri(cache, meta, fn)
124+
} catch (err) {
125+
if (err.code === 'ENOENT') {
126+
return Object.assign(
127+
new Error('No matching content found for ' + sri.toString()),
128+
{ code: 'ENOENT' }
129+
)
130+
}
131+
return err
132+
}
133+
}))
134+
// Return the first non error if it is found
135+
const result = results.find((r) => !(r instanceof Error))
136+
if (result) {
137+
return result
138+
}
139+
140+
// Throw the No matching content found error
141+
const enoentError = results.find((r) => r.code === 'ENOENT')
142+
if (enoentError) {
143+
throw enoentError
144+
}
145+
146+
// Throw generic error
147+
throw results.find((r) => r instanceof Error)
148+
}
149+
}
150+
151+
function sizeError (expected, found) {
152+
/* eslint-disable-next-line max-len */
153+
const err = new Error(`Bad data size: expected inserted data to be ${expected} bytes, but got ${found} instead`)
154+
err.expected = expected
155+
err.found = found
156+
err.code = 'EBADSIZE'
157+
return err
158+
}
159+
160+
function integrityError (sri, path) {
161+
const err = new Error(`Integrity verification failed for ${sri} (${path})`)
162+
err.code = 'EINTEGRITY'
163+
err.sri = sri
164+
err.path = path
165+
return err
166+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict'
2+
3+
const fs = require('fs/promises')
4+
const contentPath = require('./path')
5+
const { hasContent } = require('./read')
6+
7+
module.exports = rm
8+
9+
async function rm (cache, integrity) {
10+
const content = await hasContent(cache, integrity)
11+
// ~pretty~ sure we can't end up with a content lacking sri, but be safe
12+
if (content && content.sri) {
13+
await fs.rm(contentPath(cache, content.sri), { recursive: true, force: true })
14+
return true
15+
} else {
16+
return false
17+
}
18+
}

0 commit comments

Comments
 (0)