Comparing version 15.2.0 to 15.3.0
238
get.js
'use strict' | ||
const Collect = require('minipass-collect') | ||
const Minipass = require('minipass') | ||
const Pipeline = require('minipass-pipeline') | ||
const fs = require('fs') | ||
const util = require('util') | ||
const fs = require('fs') | ||
const index = require('./lib/entry-index') | ||
@@ -9,104 +13,75 @@ const memo = require('./lib/memoization') | ||
const Minipass = require('minipass') | ||
const Collect = require('minipass-collect') | ||
const Pipeline = require('minipass-pipeline') | ||
const writeFile = util.promisify(fs.writeFile) | ||
module.exports = function get (cache, key, opts) { | ||
return getData(false, cache, key, opts) | ||
} | ||
module.exports.byDigest = function getByDigest (cache, digest, opts) { | ||
return getData(true, cache, digest, opts) | ||
} | ||
function getData (byDigest, cache, key, opts = {}) { | ||
function getData (cache, key, opts = {}) { | ||
const { integrity, memoize, size } = opts | ||
const memoized = byDigest | ||
? memo.get.byDigest(cache, key, opts) | ||
: memo.get(cache, key, opts) | ||
const memoized = memo.get(cache, key, opts) | ||
if (memoized && memoize !== false) { | ||
return Promise.resolve( | ||
byDigest | ||
? memoized | ||
: { | ||
metadata: memoized.entry.metadata, | ||
data: memoized.data, | ||
integrity: memoized.entry.integrity, | ||
size: memoized.entry.size, | ||
} | ||
) | ||
return Promise.resolve({ | ||
metadata: memoized.entry.metadata, | ||
data: memoized.data, | ||
integrity: memoized.entry.integrity, | ||
size: memoized.entry.size, | ||
}) | ||
} | ||
return (byDigest ? Promise.resolve(null) : index.find(cache, key, opts)).then( | ||
(entry) => { | ||
if (!entry && !byDigest) | ||
throw new index.NotFoundError(cache, key) | ||
return read(cache, byDigest ? key : entry.integrity, { | ||
integrity, | ||
size, | ||
}) | ||
.then((data) => | ||
byDigest | ||
? data | ||
: { | ||
data, | ||
metadata: entry.metadata, | ||
size: entry.size, | ||
integrity: entry.integrity, | ||
} | ||
) | ||
.then((res) => { | ||
if (memoize && byDigest) | ||
memo.put.byDigest(cache, key, res, opts) | ||
else if (memoize) | ||
memo.put(cache, entry, res.data, opts) | ||
return index.find(cache, key, opts).then((entry) => { | ||
if (!entry) | ||
throw new index.NotFoundError(cache, key) | ||
return res | ||
}) | ||
} | ||
) | ||
return read(cache, entry.integrity, { integrity, size }).then((data) => { | ||
if (memoize) | ||
memo.put(cache, entry, data, opts) | ||
return { | ||
data, | ||
metadata: entry.metadata, | ||
size: entry.size, | ||
integrity: entry.integrity, | ||
} | ||
}) | ||
}) | ||
} | ||
module.exports = getData | ||
module.exports.sync = function get (cache, key, opts) { | ||
return getDataSync(false, cache, key, opts) | ||
function getDataByDigest (cache, key, opts = {}) { | ||
const { integrity, memoize, size } = opts | ||
const memoized = memo.get.byDigest(cache, key, opts) | ||
if (memoized && memoize !== false) | ||
return Promise.resolve(memoized) | ||
return read(cache, key, { integrity, size }).then((res) => { | ||
if (memoize) | ||
memo.put.byDigest(cache, key, res, opts) | ||
return res | ||
}) | ||
} | ||
module.exports.sync.byDigest = function getByDigest (cache, digest, opts) { | ||
return getDataSync(true, cache, digest, opts) | ||
} | ||
module.exports.byDigest = getDataByDigest | ||
function getDataSync (byDigest, cache, key, opts = {}) { | ||
function getDataSync (cache, key, opts = {}) { | ||
const { integrity, memoize, size } = opts | ||
const memoized = byDigest | ||
? memo.get.byDigest(cache, key, opts) | ||
: memo.get(cache, key, opts) | ||
const memoized = memo.get(cache, key, opts) | ||
if (memoized && memoize !== false) { | ||
return byDigest | ||
? memoized | ||
: { | ||
metadata: memoized.entry.metadata, | ||
data: memoized.data, | ||
integrity: memoized.entry.integrity, | ||
size: memoized.entry.size, | ||
} | ||
return { | ||
metadata: memoized.entry.metadata, | ||
data: memoized.data, | ||
integrity: memoized.entry.integrity, | ||
size: memoized.entry.size, | ||
} | ||
} | ||
const entry = !byDigest && index.find.sync(cache, key, opts) | ||
if (!entry && !byDigest) | ||
const entry = index.find.sync(cache, key, opts) | ||
if (!entry) | ||
throw new index.NotFoundError(cache, key) | ||
const data = read.sync(cache, byDigest ? key : entry.integrity, { | ||
const data = read.sync(cache, entry.integrity, { | ||
integrity: integrity, | ||
size: size, | ||
}) | ||
const res = byDigest | ||
? data | ||
: { | ||
metadata: entry.metadata, | ||
data: data, | ||
size: entry.size, | ||
integrity: entry.integrity, | ||
} | ||
if (memoize && byDigest) | ||
memo.put.byDigest(cache, key, res, opts) | ||
else if (memoize) | ||
const res = { | ||
metadata: entry.metadata, | ||
data: data, | ||
size: entry.size, | ||
integrity: entry.integrity, | ||
} | ||
if (memoize) | ||
memo.put(cache, entry, res.data, opts) | ||
@@ -117,4 +92,22 @@ | ||
module.exports.stream = getStream | ||
module.exports.sync = getDataSync | ||
function getDataByDigestSync (cache, digest, opts = {}) { | ||
const { integrity, memoize, size } = opts | ||
const memoized = memo.get.byDigest(cache, digest, opts) | ||
if (memoized && memoize !== false) | ||
return memoized | ||
const res = read.sync(cache, digest, { | ||
integrity: integrity, | ||
size: size, | ||
}) | ||
if (memoize) | ||
memo.put.byDigest(cache, digest, res, opts) | ||
return res | ||
} | ||
module.exports.sync.byDigest = getDataByDigestSync | ||
const getMemoizedStream = (memoized) => { | ||
@@ -171,3 +164,3 @@ const stream = new Minipass() | ||
module.exports.stream.byDigest = getStreamDigest | ||
module.exports.stream = getStream | ||
@@ -197,3 +190,3 @@ function getStreamDigest (cache, integrity, opts = {}) { | ||
module.exports.info = info | ||
module.exports.stream.byDigest = getStreamDigest | ||
@@ -208,36 +201,16 @@ function info (cache, key, opts = {}) { | ||
} | ||
module.exports.info = info | ||
module.exports.hasContent = read.hasContent | ||
function cp (cache, key, dest, opts) { | ||
return copy(false, cache, key, dest, opts) | ||
} | ||
module.exports.copy = cp | ||
function cpDigest (cache, digest, dest, opts) { | ||
return copy(true, cache, digest, dest, opts) | ||
} | ||
module.exports.copy.byDigest = cpDigest | ||
function copy (byDigest, cache, key, dest, opts = {}) { | ||
function copy (cache, key, dest, opts = {}) { | ||
if (read.copy) { | ||
return (byDigest | ||
? Promise.resolve(null) | ||
: index.find(cache, key, opts) | ||
).then((entry) => { | ||
if (!entry && !byDigest) | ||
return index.find(cache, key, opts).then((entry) => { | ||
if (!entry) | ||
throw new index.NotFoundError(cache, key) | ||
return read | ||
.copy(cache, byDigest ? key : entry.integrity, dest, opts) | ||
return read.copy(cache, entry.integrity, dest, opts) | ||
.then(() => { | ||
return byDigest | ||
? key | ||
: { | ||
metadata: entry.metadata, | ||
size: entry.size, | ||
integrity: entry.integrity, | ||
} | ||
return { | ||
metadata: entry.metadata, | ||
size: entry.size, | ||
integrity: entry.integrity, | ||
} | ||
}) | ||
@@ -247,13 +220,24 @@ }) | ||
return getData(byDigest, cache, key, opts).then((res) => { | ||
return writeFile(dest, byDigest ? res : res.data).then(() => { | ||
return byDigest | ||
? key | ||
: { | ||
metadata: res.metadata, | ||
size: res.size, | ||
integrity: res.integrity, | ||
} | ||
return getData(cache, key, opts).then((res) => { | ||
return writeFile(dest, res.data).then(() => { | ||
return { | ||
metadata: res.metadata, | ||
size: res.size, | ||
integrity: res.integrity, | ||
} | ||
}) | ||
}) | ||
} | ||
module.exports.copy = copy | ||
function copyByDigest (cache, key, dest, opts = {}) { | ||
if (read.copy) | ||
return read.copy(cache, key, dest, opts).then(() => key) | ||
return getDataByDigest(cache, key, opts).then((res) => { | ||
return writeFile(dest, res).then(() => key) | ||
}) | ||
} | ||
module.exports.copy.byDigest = copyByDigest | ||
module.exports.hasContent = read.hasContent |
'use strict' | ||
const util = require('util') | ||
const fs = require('@npmcli/fs') | ||
const fixOwner = require('./fix-owner') | ||
const path = require('path') | ||
const rimraf = util.promisify(require('rimraf')) | ||
const uniqueFilename = require('unique-filename') | ||
const { disposer } = require('./disposer') | ||
@@ -15,6 +12,9 @@ module.exports.mkdir = mktmpdir | ||
const { tmpPrefix } = opts | ||
const tmpTarget = uniqueFilename(path.join(cache, 'tmp'), tmpPrefix) | ||
return fixOwner.mkdirfix(cache, tmpTarget).then(() => { | ||
return tmpTarget | ||
}) | ||
const tmpDir = path.join(cache, 'tmp') | ||
return fs.mkdir(tmpDir, { recursive: true, owner: 'inherit' }) | ||
.then(() => { | ||
// do not use path.join(), it drops the trailing / if tmpPrefix is unset | ||
const target = `${tmpDir}${path.sep}${tmpPrefix || ''}` | ||
return fs.mkdtemp(target, { owner: 'inherit' }) | ||
}) | ||
} | ||
@@ -29,3 +29,3 @@ | ||
} | ||
return disposer(mktmpdir(cache, opts), rimraf, cb) | ||
return fs.withTempDir(path.join(cache, 'tmp'), cb, opts) | ||
} | ||
@@ -32,0 +32,0 @@ |
{ | ||
"name": "cacache", | ||
"version": "15.2.0", | ||
"version": "15.3.0", | ||
"cache-version": { | ||
@@ -46,2 +46,3 @@ "content": "2", | ||
"dependencies": { | ||
"@npmcli/fs": "^1.0.0", | ||
"@npmcli/move-file": "^1.0.1", | ||
@@ -48,0 +49,0 @@ "chownr": "^2.0.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
76264
18
1652
1
+ Added@npmcli/fs@^1.0.0
+ Added@gar/promisify@1.1.3(transitive)
+ Added@npmcli/fs@1.1.1(transitive)
+ Addedsemver@7.6.3(transitive)