Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: npm/cacache
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 555114e87a79f5c6115b5fde8e74b3fb62bc4a33
Choose a base ref
...
head repository: npm/cacache
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 41e12c1bba2fd9e296ad98f1e26567f76d3e9e01
Choose a head ref
  • 9 commits
  • 19 files changed
  • 1 contributor

Commits on Apr 9, 2018

  1. deps: bump deps

    zkat committed Apr 9, 2018

    Verified

    This commit was signed with the committer’s verified signature.
    pellared Robert Pająk
    Copy the full SHA
    a7d25b4 View commit details
  2. deps: bump devDeps

    zkat committed Apr 9, 2018

    Verified

    This commit was signed with the committer’s verified signature.
    pellared Robert Pająk
    Copy the full SHA
    3817b7a View commit details
  3. standard: --fix for standard@11

    zkat committed Apr 9, 2018

    Verified

    This commit was signed with the committer’s verified signature.
    pellared Robert Pająk
    Copy the full SHA
    109ff93 View commit details
  4. test: use nyc through tap

    zkat committed Apr 9, 2018
    Copy the full SHA
    4446327 View commit details
  5. meta: drop support for node@4

    BREAKING CHANGE: node@4 is no longer supported
    zkat committed Apr 9, 2018
    Copy the full SHA
    529f347 View commit details
  6. Copy the full SHA
    33d4eed View commit details
  7. chore(release): 11.0.0

    zkat committed Apr 9, 2018
    Copy the full SHA
    aa59d82 View commit details

Commits on Apr 10, 2018

  1. deps: bump ssri

    zkat committed Apr 10, 2018
    Copy the full SHA
    208b7bd View commit details
  2. chore(release): 11.0.1

    zkat committed Apr 10, 2018
    Copy the full SHA
    41e12c1 View commit details
Showing with 2,316 additions and 1,061 deletions.
  1. +1 −1 .travis.yml
  2. +25 −0 CHANGELOG.md
  3. +2 −2 appveyor.yml
  4. +22 −14 get.js
  5. +29 −24 lib/content/read.js
  6. +3 −1 lib/content/write.js
  7. +14 −6 lib/entry-index.js
  8. +10 −2 lib/util/tmp.js
  9. +25 −12 lib/verify.js
  10. +2,076 −902 package-lock.json
  11. +10 −10 package.json
  12. +20 −8 put.js
  13. +18 −18 test/benchmarks/content.read.js
  14. +8 −8 test/benchmarks/get.js
  15. +8 −8 test/benchmarks/index.js
  16. +10 −10 test/content.read.js
  17. +1 −1 test/content.write.js
  18. +19 −19 test/get.js
  19. +15 −15 test/ls.js
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: node_js
sudo: false
node_js:
- "9"
- "8"
- "6"
- "4"
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,31 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

<a name="11.0.1"></a>
## [11.0.1](https://github.com/zkat/cacache/compare/v11.0.0...v11.0.1) (2018-04-10)



<a name="11.0.0"></a>
# [11.0.0](https://github.com/zkat/cacache/compare/v10.0.4...v11.0.0) (2018-04-09)


### Features

* **opts:** use figgy-pudding for opts ([#128](https://github.com/zkat/cacache/issues/128)) ([33d4eed](https://github.com/zkat/cacache/commit/33d4eed))


### meta

* drop support for node@4 ([529f347](https://github.com/zkat/cacache/commit/529f347))


### BREAKING CHANGES

* node@4 is no longer supported



<a name="10.0.4"></a>
## [10.0.4](https://github.com/zkat/cacache/compare/v10.0.3...v10.0.4) (2018-02-16)

4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
environment:
matrix:
- nodejs_version: "9"
- nodejs_version: "8"
- nodejs_version: "6"
- nodejs_version: "4"

platform:
- x64
@@ -17,5 +17,5 @@ test_script:

matrix:
fast_finish: true

build: off
36 changes: 22 additions & 14 deletions get.js
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@

const BB = require('bluebird')

const figgyPudding = require('figgy-pudding')
const fs = require('fs')
const index = require('./lib/entry-index')
const memo = require('./lib/memoization')
@@ -10,18 +11,24 @@ const pipeline = require('mississippi').pipeline
const read = require('./lib/content/read')
const through = require('mississippi').through

const GetOpts = figgyPudding({
integrity: {},
memoize: {},
size: {}
})

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) {
opts = opts || {}
opts = GetOpts(opts)
const memoized = (
byDigest
? memo.get.byDigest(cache, key, opts)
: memo.get(cache, key, opts)
? memo.get.byDigest(cache, key, opts)
: memo.get(cache, key, opts)
)
if (memoized && opts.memoize !== false) {
return BB.resolve(byDigest ? memoized : {
@@ -58,7 +65,7 @@ function getData (byDigest, cache, key, opts) {

module.exports.stream = getStream
function getStream (cache, key, opts) {
opts = opts || {}
opts = GetOpts(opts)
let stream = through()
const memoized = memo.get(cache, key, opts)
if (memoized && opts.memoize !== false) {
@@ -91,7 +98,6 @@ function getStream (cache, key, opts) {
} else {
memoStream = through()
}
opts.size = opts.size == null ? entry.size : opts.size
stream.emit('metadata', entry.metadata)
stream.emit('integrity', entry.integrity)
stream.emit('size', entry.size)
@@ -101,7 +107,9 @@ function getStream (cache, key, opts) {
ev === 'size' && cb(entry.size)
})
pipe(
read.readStream(cache, entry.integrity, opts),
read.readStream(cache, entry.integrity, opts.concat({
size: opts.size == null ? entry.size : opts.size
})),
memoStream,
stream
)
@@ -111,7 +119,7 @@ function getStream (cache, key, opts) {

module.exports.stream.byDigest = getStreamDigest
function getStreamDigest (cache, integrity, opts) {
opts = opts || {}
opts = GetOpts(opts)
const memoized = memo.get.byDigest(cache, integrity, opts)
if (memoized && opts.memoize !== false) {
const stream = through()
@@ -143,7 +151,7 @@ function getStreamDigest (cache, integrity, opts) {

module.exports.info = info
function info (cache, key, opts) {
opts = opts || {}
opts = GetOpts(opts)
const memoized = memo.get(cache, key, opts)
if (memoized && opts.memoize !== false) {
return BB.resolve(memoized.entry)
@@ -161,7 +169,7 @@ module.exports.copy.byDigest = function cpDigest (cache, digest, dest, opts) {
return copy(true, cache, digest, dest, opts)
}
function copy (byDigest, cache, key, dest, opts) {
opts = opts || {}
opts = GetOpts(opts)
if (read.copy) {
return (
byDigest ? BB.resolve(null) : index.find(cache, key, opts)
@@ -180,11 +188,11 @@ function copy (byDigest, cache, key, dest, opts) {
} else {
return getData(byDigest, cache, key, opts).then(res => {
return fs.writeFileAsync(dest, byDigest ? res : res.data)
.then(() => byDigest ? key : {
metadata: res.metadata,
size: res.size,
integrity: res.integrity
})
.then(() => byDigest ? key : {
metadata: res.metadata,
size: res.size,
integrity: res.integrity
})
})
}
}
53 changes: 29 additions & 24 deletions lib/content/read.js
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
const BB = require('bluebird')

const contentPath = require('./path')
const figgyPudding = require('figgy-pudding')
const fs = require('graceful-fs')
const PassThrough = require('stream').PassThrough
const pipe = BB.promisify(require('mississippi').pipe)
@@ -11,9 +12,13 @@ const Y = require('../util/y.js')

BB.promisifyAll(fs)

const ReadOpts = figgyPudding({
size: {}
})

module.exports = read
function read (cache, integrity, opts) {
opts = opts || {}
opts = ReadOpts(opts)
return pickContentSri(cache, integrity).then(content => {
const sri = content.sri
const cpath = contentPath(cache, sri)
@@ -32,7 +37,7 @@ function read (cache, integrity, opts) {
module.exports.stream = readStream
module.exports.readStream = readStream
function readStream (cache, integrity, opts) {
opts = opts || {}
opts = ReadOpts(opts)
const stream = new PassThrough()
pickContentSri(
cache, integrity
@@ -56,7 +61,7 @@ if (fs.copyFile) {
module.exports.copy = copy
}
function copy (cache, integrity, dest, opts) {
opts = opts || {}
opts = ReadOpts(opts)
return pickContentSri(cache, integrity).then(content => {
const sri = content.sri
const cpath = contentPath(cache, sri)
@@ -68,17 +73,17 @@ module.exports.hasContent = hasContent
function hasContent (cache, integrity) {
if (!integrity) { return BB.resolve(false) }
return pickContentSri(cache, integrity)
.catch({code: 'ENOENT'}, () => false)
.catch({code: 'EPERM'}, err => {
if (process.platform !== 'win32') {
throw err
} else {
return false
}
}).then(content => {
if (!content.sri) return false
return ({ sri: content.sri, size: content.stat.size })
})
.catch({code: 'ENOENT'}, () => false)
.catch({code: 'EPERM'}, err => {
if (process.platform !== 'win32') {
throw err
} else {
return false
}
}).then(content => {
if (!content.sri) return false
return ({ sri: content.sri, size: content.stat.size })
})
}

module.exports._pickContentSri = pickContentSri
@@ -95,16 +100,16 @@ function pickContentSri (cache, integrity) {
return BB.any(sri[sri.pickAlgorithm()].map(meta => {
return pickContentSri(cache, meta)
}))
.catch(err => {
if ([].some.call(err, e => e.code === 'ENOENT')) {
throw Object.assign(
new Error('No matching content found for ' + sri.toString()),
{code: 'ENOENT'}
)
} else {
throw err[0]
}
})
.catch(err => {
if ([].some.call(err, e => e.code === 'ENOENT')) {
throw Object.assign(
new Error('No matching content found for ' + sri.toString()),
{code: 'ENOENT'}
)
} else {
throw err[0]
}
})
}
}

4 changes: 3 additions & 1 deletion lib/content/write.js
Original file line number Diff line number Diff line change
@@ -28,7 +28,9 @@ function write (cache, data, opts) {
if (typeof opts.size === 'number' && data.length !== opts.size) {
return BB.reject(sizeError(opts.size, data.length))
}
const sri = ssri.fromData(data, opts)
const sri = ssri.fromData(data, {
algorithms: opts.algorithms
})
if (opts.integrity && !ssri.checkData(data, opts.integrity, opts)) {
return BB.reject(checksumError(opts.integrity, sri))
}
20 changes: 14 additions & 6 deletions lib/entry-index.js
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ const BB = require('bluebird')

const contentPath = require('./content/path')
const crypto = require('crypto')
const figgyPudding = require('figgy-pudding')
const fixOwner = require('./util/fix-owner')
const fs = require('graceful-fs')
const hashToSegments = require('./util/hash-to-segments')
@@ -29,9 +30,16 @@ module.exports.NotFoundError = class NotFoundError extends Error {
}
}

const IndexOpts = figgyPudding({
metadata: {},
size: {},
uid: {},
gid: {}
})

module.exports.insert = insert
function insert (cache, key, integrity, opts) {
opts = opts || {}
opts = IndexOpts(opts)
const bucket = bucketPath(cache, key)
const entry = {
key,
@@ -197,9 +205,9 @@ function hashEntry (str) {

function hash (str, digest) {
return crypto
.createHash(digest)
.update(str)
.digest('hex')
.createHash(digest)
.update(str)
.digest('hex')
}

function formatEntry (cache, entry) {
@@ -217,8 +225,8 @@ function formatEntry (cache, entry) {

function readdirOrEmpty (dir) {
return readdirAsync(dir)
.catch({code: 'ENOENT'}, () => [])
.catch({code: 'ENOTDIR'}, () => [])
.catch({code: 'ENOENT'}, () => [])
.catch({code: 'ENOTDIR'}, () => [])
}

function nop () {
12 changes: 10 additions & 2 deletions lib/util/tmp.js
Original file line number Diff line number Diff line change
@@ -2,14 +2,21 @@

const BB = require('bluebird')

const figgyPudding = require('figgy-pudding')
const fixOwner = require('./fix-owner')
const path = require('path')
const rimraf = BB.promisify(require('rimraf'))
const uniqueFilename = require('unique-filename')

const TmpOpts = figgyPudding({
tmpPrefix: {},
uid: {},
gid: {}
})

module.exports.mkdir = mktmpdir
function mktmpdir (cache, opts) {
opts = opts || {}
opts = TmpOpts(opts)
const tmpTarget = uniqueFilename(path.join(cache, 'tmp'), opts.tmpPrefix)
return fixOwner.mkdirfix(tmpTarget, opts.uid, opts.gid).then(() => {
return tmpTarget
@@ -22,11 +29,12 @@ function withTmp (cache, opts, cb) {
cb = opts
opts = null
}
opts = opts || {}
opts = TmpOpts(opts)
return BB.using(mktmpdir(cache, opts).disposer(rimraf), cb)
}

module.exports.fix = fixtmpdir
function fixtmpdir (cache, opts) {
opts = TmpOpts(opts)
return fixOwner(path.join(cache, 'tmp'), opts.uid, opts.gid)
}
Loading