-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b0849ab
commit 7af81c7
Showing
166 changed files
with
25,836 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
node_modules/@npmcli/metavuln-calculator/node_modules/cacache/LICENSE.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
ISC License | ||
|
||
Copyright (c) npm, Inc. | ||
|
||
Permission to use, copy, modify, and/or distribute this software for | ||
any purpose with or without fee is hereby granted, provided that the | ||
above copyright notice and this permission notice appear in all copies. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE COPYRIGHT HOLDER DISCLAIMS | ||
ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE | ||
COPYRIGHT HOLDER BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR | ||
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS | ||
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE | ||
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE | ||
USE OR PERFORMANCE OF THIS SOFTWARE. |
29 changes: 29 additions & 0 deletions
29
node_modules/@npmcli/metavuln-calculator/node_modules/cacache/lib/content/path.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict' | ||
|
||
const contentVer = require('../../package.json')['cache-version'].content | ||
const hashToSegments = require('../util/hash-to-segments') | ||
const path = require('path') | ||
const ssri = require('ssri') | ||
|
||
// Current format of content file path: | ||
// | ||
// sha512-BaSE64Hex= -> | ||
// ~/.my-cache/content-v2/sha512/ba/da/55deadbeefc0ffee | ||
// | ||
module.exports = contentPath | ||
|
||
function contentPath (cache, integrity) { | ||
const sri = ssri.parse(integrity, { single: true }) | ||
// contentPath is the *strongest* algo given | ||
return path.join( | ||
contentDir(cache), | ||
sri.algorithm, | ||
...hashToSegments(sri.hexDigest()) | ||
) | ||
} | ||
|
||
module.exports.contentDir = contentDir | ||
|
||
function contentDir (cache) { | ||
return path.join(cache, `content-v${contentVer}`) | ||
} |
166 changes: 166 additions & 0 deletions
166
node_modules/@npmcli/metavuln-calculator/node_modules/cacache/lib/content/read.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
'use strict' | ||
|
||
const fs = require('fs/promises') | ||
const fsm = require('fs-minipass') | ||
const ssri = require('ssri') | ||
const contentPath = require('./path') | ||
const Pipeline = require('minipass-pipeline') | ||
|
||
module.exports = read | ||
|
||
const MAX_SINGLE_READ_SIZE = 64 * 1024 * 1024 | ||
async function read (cache, integrity, opts = {}) { | ||
const { size } = opts | ||
const { stat, cpath, sri } = await withContentSri(cache, integrity, async (cpath, sri) => { | ||
// get size | ||
const stat = await fs.stat(cpath) | ||
return { stat, cpath, sri } | ||
}) | ||
if (typeof size === 'number' && stat.size !== size) { | ||
throw sizeError(size, stat.size) | ||
} | ||
|
||
if (stat.size > MAX_SINGLE_READ_SIZE) { | ||
return readPipeline(cpath, stat.size, sri, new Pipeline()).concat() | ||
} | ||
|
||
const data = await fs.readFile(cpath, { encoding: null }) | ||
if (!ssri.checkData(data, sri)) { | ||
throw integrityError(sri, cpath) | ||
} | ||
|
||
return data | ||
} | ||
|
||
const readPipeline = (cpath, size, sri, stream) => { | ||
stream.push( | ||
new fsm.ReadStream(cpath, { | ||
size, | ||
readSize: MAX_SINGLE_READ_SIZE, | ||
}), | ||
ssri.integrityStream({ | ||
integrity: sri, | ||
size, | ||
}) | ||
) | ||
return stream | ||
} | ||
|
||
module.exports.stream = readStream | ||
module.exports.readStream = readStream | ||
|
||
function readStream (cache, integrity, opts = {}) { | ||
const { size } = opts | ||
const stream = new Pipeline() | ||
// Set all this up to run on the stream and then just return the stream | ||
Promise.resolve().then(async () => { | ||
const { stat, cpath, sri } = await withContentSri(cache, integrity, async (cpath, sri) => { | ||
// just stat to ensure it exists | ||
const stat = await fs.stat(cpath) | ||
return { stat, cpath, sri } | ||
}) | ||
if (typeof size === 'number' && size !== stat.size) { | ||
return stream.emit('error', sizeError(size, stat.size)) | ||
} | ||
|
||
return readPipeline(cpath, stat.size, sri, stream) | ||
}).catch(err => stream.emit('error', err)) | ||
|
||
return stream | ||
} | ||
|
||
module.exports.copy = copy | ||
|
||
function copy (cache, integrity, dest) { | ||
return withContentSri(cache, integrity, (cpath, sri) => { | ||
return fs.copyFile(cpath, dest) | ||
}) | ||
} | ||
|
||
module.exports.hasContent = hasContent | ||
|
||
async function hasContent (cache, integrity) { | ||
if (!integrity) { | ||
return false | ||
} | ||
|
||
try { | ||
return await withContentSri(cache, integrity, async (cpath, sri) => { | ||
const stat = await fs.stat(cpath) | ||
return { size: stat.size, sri, stat } | ||
}) | ||
} catch (err) { | ||
if (err.code === 'ENOENT') { | ||
return false | ||
} | ||
|
||
if (err.code === 'EPERM') { | ||
/* istanbul ignore else */ | ||
if (process.platform !== 'win32') { | ||
throw err | ||
} else { | ||
return false | ||
} | ||
} | ||
} | ||
} | ||
|
||
async function withContentSri (cache, integrity, fn) { | ||
const sri = ssri.parse(integrity) | ||
// If `integrity` has multiple entries, pick the first digest | ||
// with available local data. | ||
const algo = sri.pickAlgorithm() | ||
const digests = sri[algo] | ||
|
||
if (digests.length <= 1) { | ||
const cpath = contentPath(cache, digests[0]) | ||
return fn(cpath, digests[0]) | ||
} else { | ||
// Can't use race here because a generic error can happen before | ||
// a ENOENT error, and can happen before a valid result | ||
const results = await Promise.all(digests.map(async (meta) => { | ||
try { | ||
return await withContentSri(cache, meta, fn) | ||
} catch (err) { | ||
if (err.code === 'ENOENT') { | ||
return Object.assign( | ||
new Error('No matching content found for ' + sri.toString()), | ||
{ code: 'ENOENT' } | ||
) | ||
} | ||
return err | ||
} | ||
})) | ||
// Return the first non error if it is found | ||
const result = results.find((r) => !(r instanceof Error)) | ||
if (result) { | ||
return result | ||
} | ||
|
||
// Throw the No matching content found error | ||
const enoentError = results.find((r) => r.code === 'ENOENT') | ||
if (enoentError) { | ||
throw enoentError | ||
} | ||
|
||
// Throw generic error | ||
throw results.find((r) => r instanceof Error) | ||
} | ||
} | ||
|
||
function sizeError (expected, found) { | ||
/* eslint-disable-next-line max-len */ | ||
const err = new Error(`Bad data size: expected inserted data to be ${expected} bytes, but got ${found} instead`) | ||
err.expected = expected | ||
err.found = found | ||
err.code = 'EBADSIZE' | ||
return err | ||
} | ||
|
||
function integrityError (sri, path) { | ||
const err = new Error(`Integrity verification failed for ${sri} (${path})`) | ||
err.code = 'EINTEGRITY' | ||
err.sri = sri | ||
err.path = path | ||
return err | ||
} |
18 changes: 18 additions & 0 deletions
18
node_modules/@npmcli/metavuln-calculator/node_modules/cacache/lib/content/rm.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use strict' | ||
|
||
const fs = require('fs/promises') | ||
const contentPath = require('./path') | ||
const { hasContent } = require('./read') | ||
|
||
module.exports = rm | ||
|
||
async function rm (cache, integrity) { | ||
const content = await hasContent(cache, integrity) | ||
// ~pretty~ sure we can't end up with a content lacking sri, but be safe | ||
if (content && content.sri) { | ||
await fs.rm(contentPath(cache, content.sri), { recursive: true, force: true }) | ||
return true | ||
} else { | ||
return false | ||
} | ||
} |
Oops, something went wrong.