cacache 11.0.1 → 11.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +42 -0
- package/lib/content/read.js +102 -37
- package/lib/verify.js +2 -1
- package/package.json +5 -6
- package/put.js +5 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,48 @@
|
|
|
2
2
|
|
|
3
3
|
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.
|
|
4
4
|
|
|
5
|
+
<a name="11.2.0"></a>
|
|
6
|
+
# [11.2.0](https://github.com/zkat/cacache/compare/v11.1.0...v11.2.0) (2018-08-08)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **read:** add sync support to other internal read.js fns ([fe638b6](https://github.com/zkat/cacache/commit/fe638b6))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
<a name="11.1.0"></a>
|
|
16
|
+
# [11.1.0](https://github.com/zkat/cacache/compare/v11.0.3...v11.1.0) (2018-08-01)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Features
|
|
20
|
+
|
|
21
|
+
* **read:** add sync support for low-level content read ([b43af83](https://github.com/zkat/cacache/commit/b43af83))
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
<a name="11.0.3"></a>
|
|
26
|
+
## [11.0.3](https://github.com/zkat/cacache/compare/v11.0.2...v11.0.3) (2018-08-01)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
### Bug Fixes
|
|
30
|
+
|
|
31
|
+
* **config:** add ssri config options ([#136](https://github.com/zkat/cacache/issues/136)) ([10d5d9a](https://github.com/zkat/cacache/commit/10d5d9a))
|
|
32
|
+
* **perf:** refactor content.read to avoid lstats ([c5ac10e](https://github.com/zkat/cacache/commit/c5ac10e))
|
|
33
|
+
* **test:** oops when removing safe-buffer ([1950490](https://github.com/zkat/cacache/commit/1950490))
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
<a name="11.0.2"></a>
|
|
38
|
+
## [11.0.2](https://github.com/zkat/cacache/compare/v11.0.1...v11.0.2) (2018-05-07)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
### Bug Fixes
|
|
42
|
+
|
|
43
|
+
* **verify:** size param no longer lost in a verify ([#131](https://github.com/zkat/cacache/issues/131)) ([c614a19](https://github.com/zkat/cacache/commit/c614a19)), closes [#130](https://github.com/zkat/cacache/issues/130)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
5
47
|
<a name="11.0.1"></a>
|
|
6
48
|
## [11.0.1](https://github.com/zkat/cacache/compare/v11.0.0...v11.0.1) (2018-04-10)
|
|
7
49
|
|
package/lib/content/read.js
CHANGED
|
@@ -10,7 +10,8 @@ const pipe = BB.promisify(require('mississippi').pipe)
|
|
|
10
10
|
const ssri = require('ssri')
|
|
11
11
|
const Y = require('../util/y.js')
|
|
12
12
|
|
|
13
|
-
BB.
|
|
13
|
+
const lstatAsync = BB.promisify(fs.lstat)
|
|
14
|
+
const readFileAsync = BB.promisify(fs.readFile)
|
|
14
15
|
|
|
15
16
|
const ReadOpts = figgyPudding({
|
|
16
17
|
size: {}
|
|
@@ -19,10 +20,8 @@ const ReadOpts = figgyPudding({
|
|
|
19
20
|
module.exports = read
|
|
20
21
|
function read (cache, integrity, opts) {
|
|
21
22
|
opts = ReadOpts(opts)
|
|
22
|
-
return
|
|
23
|
-
|
|
24
|
-
const cpath = contentPath(cache, sri)
|
|
25
|
-
return fs.readFileAsync(cpath, null).then(data => {
|
|
23
|
+
return withContentSri(cache, integrity, (cpath, sri) => {
|
|
24
|
+
return readFileAsync(cpath, null).then(data => {
|
|
26
25
|
if (typeof opts.size === 'number' && opts.size !== data.length) {
|
|
27
26
|
throw sizeError(opts.size, data.length)
|
|
28
27
|
} else if (ssri.checkData(data, sri)) {
|
|
@@ -34,17 +33,31 @@ function read (cache, integrity, opts) {
|
|
|
34
33
|
})
|
|
35
34
|
}
|
|
36
35
|
|
|
36
|
+
module.exports.sync = readSync
|
|
37
|
+
function readSync (cache, integrity, opts) {
|
|
38
|
+
opts = ReadOpts(opts)
|
|
39
|
+
return withContentSriSync(cache, integrity, (cpath, sri) => {
|
|
40
|
+
const data = fs.readFileSync(cpath)
|
|
41
|
+
if (typeof opts.size === 'number' && opts.size !== data.length) {
|
|
42
|
+
throw sizeError(opts.size, data.length)
|
|
43
|
+
} else if (ssri.checkData(data, sri)) {
|
|
44
|
+
return data
|
|
45
|
+
} else {
|
|
46
|
+
throw integrityError(sri, cpath)
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
|
|
37
51
|
module.exports.stream = readStream
|
|
38
52
|
module.exports.readStream = readStream
|
|
39
53
|
function readStream (cache, integrity, opts) {
|
|
40
54
|
opts = ReadOpts(opts)
|
|
41
55
|
const stream = new PassThrough()
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
).then(
|
|
45
|
-
const sri = content.sri
|
|
56
|
+
withContentSri(cache, integrity, (cpath, sri) => {
|
|
57
|
+
return lstatAsync(cpath).then(stat => ({cpath, sri, stat}))
|
|
58
|
+
}).then(({cpath, sri, stat}) => {
|
|
46
59
|
return pipe(
|
|
47
|
-
fs.createReadStream(
|
|
60
|
+
fs.createReadStream(cpath),
|
|
48
61
|
ssri.integrityStream({
|
|
49
62
|
integrity: sri,
|
|
50
63
|
size: opts.size
|
|
@@ -57,37 +70,93 @@ function readStream (cache, integrity, opts) {
|
|
|
57
70
|
return stream
|
|
58
71
|
}
|
|
59
72
|
|
|
73
|
+
let copyFileAsync
|
|
60
74
|
if (fs.copyFile) {
|
|
61
75
|
module.exports.copy = copy
|
|
76
|
+
module.exports.copy.sync = copySync
|
|
77
|
+
copyFileAsync = BB.promisify(fs.copyFile)
|
|
62
78
|
}
|
|
79
|
+
|
|
63
80
|
function copy (cache, integrity, dest, opts) {
|
|
64
81
|
opts = ReadOpts(opts)
|
|
65
|
-
return
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
82
|
+
return withContentSri(cache, integrity, (cpath, sri) => {
|
|
83
|
+
return copyFileAsync(cpath, dest)
|
|
84
|
+
})
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function copySync (cache, integrity, dest, opts) {
|
|
88
|
+
opts = ReadOpts(opts)
|
|
89
|
+
return withContentSriSync(cache, integrity, (cpath, sri) => {
|
|
90
|
+
return fs.copyFileSync(cpath, dest)
|
|
69
91
|
})
|
|
70
92
|
}
|
|
71
93
|
|
|
72
94
|
module.exports.hasContent = hasContent
|
|
73
95
|
function hasContent (cache, integrity) {
|
|
74
96
|
if (!integrity) { return BB.resolve(false) }
|
|
75
|
-
return
|
|
76
|
-
.
|
|
77
|
-
|
|
97
|
+
return withContentSri(cache, integrity, (cpath, sri) => {
|
|
98
|
+
return lstatAsync(cpath).then(stat => ({size: stat.size, sri, stat}))
|
|
99
|
+
}).catch(err => {
|
|
100
|
+
if (err.code === 'ENOENT') { return false }
|
|
101
|
+
if (err.code === 'EPERM') {
|
|
78
102
|
if (process.platform !== 'win32') {
|
|
79
103
|
throw err
|
|
80
104
|
} else {
|
|
81
105
|
return false
|
|
82
106
|
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return ({ sri: content.sri, size: content.stat.size })
|
|
86
|
-
})
|
|
107
|
+
}
|
|
108
|
+
})
|
|
87
109
|
}
|
|
88
110
|
|
|
89
|
-
module.exports.
|
|
90
|
-
function
|
|
111
|
+
module.exports.hasContent.sync = hasContentSync
|
|
112
|
+
function hasContentSync (cache, integrity) {
|
|
113
|
+
if (!integrity) { return false }
|
|
114
|
+
return withContentSriSync(cache, integrity, (cpath, sri) => {
|
|
115
|
+
try {
|
|
116
|
+
const stat = fs.lstatSync(cpath)
|
|
117
|
+
return {size: stat.size, sri, stat}
|
|
118
|
+
} catch (err) {
|
|
119
|
+
if (err.code === 'ENOENT') { return false }
|
|
120
|
+
if (err.code === 'EPERM') {
|
|
121
|
+
if (process.platform !== 'win32') {
|
|
122
|
+
throw err
|
|
123
|
+
} else {
|
|
124
|
+
return false
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
})
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function withContentSri (cache, integrity, fn) {
|
|
132
|
+
return BB.try(() => {
|
|
133
|
+
const sri = ssri.parse(integrity)
|
|
134
|
+
// If `integrity` has multiple entries, pick the first digest
|
|
135
|
+
// with available local data.
|
|
136
|
+
const algo = sri.pickAlgorithm()
|
|
137
|
+
const digests = sri[algo]
|
|
138
|
+
if (digests.length <= 1) {
|
|
139
|
+
const cpath = contentPath(cache, digests[0])
|
|
140
|
+
return fn(cpath, digests[0])
|
|
141
|
+
} else {
|
|
142
|
+
return BB.any(sri[sri.pickAlgorithm()].map(meta => {
|
|
143
|
+
return withContentSri(cache, meta, fn)
|
|
144
|
+
}, {concurrency: 1}))
|
|
145
|
+
.catch(err => {
|
|
146
|
+
if ([].some.call(err, e => e.code === 'ENOENT')) {
|
|
147
|
+
throw Object.assign(
|
|
148
|
+
new Error('No matching content found for ' + sri.toString()),
|
|
149
|
+
{code: 'ENOENT'}
|
|
150
|
+
)
|
|
151
|
+
} else {
|
|
152
|
+
throw err[0]
|
|
153
|
+
}
|
|
154
|
+
})
|
|
155
|
+
}
|
|
156
|
+
})
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function withContentSriSync (cache, integrity, fn) {
|
|
91
160
|
const sri = ssri.parse(integrity)
|
|
92
161
|
// If `integrity` has multiple entries, pick the first digest
|
|
93
162
|
// with available local data.
|
|
@@ -95,21 +164,17 @@ function pickContentSri (cache, integrity) {
|
|
|
95
164
|
const digests = sri[algo]
|
|
96
165
|
if (digests.length <= 1) {
|
|
97
166
|
const cpath = contentPath(cache, digests[0])
|
|
98
|
-
return
|
|
167
|
+
return fn(cpath, digests[0])
|
|
99
168
|
} else {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
} else {
|
|
110
|
-
throw err[0]
|
|
111
|
-
}
|
|
112
|
-
})
|
|
169
|
+
let lastErr = null
|
|
170
|
+
for (const meta of sri[sri.pickAlgorithm()]) {
|
|
171
|
+
try {
|
|
172
|
+
return withContentSriSync(cache, meta, fn)
|
|
173
|
+
} catch (err) {
|
|
174
|
+
lastErr = err
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
if (lastErr) { throw lastErr }
|
|
113
178
|
}
|
|
114
179
|
}
|
|
115
180
|
|
package/lib/verify.js
CHANGED
|
@@ -197,7 +197,8 @@ function rebuildBucket (cache, bucket, stats, opts) {
|
|
|
197
197
|
return index.insert(cache, entry.key, entry.integrity, {
|
|
198
198
|
uid: opts.uid,
|
|
199
199
|
gid: opts.gid,
|
|
200
|
-
metadata: entry.metadata
|
|
200
|
+
metadata: entry.metadata,
|
|
201
|
+
size: entry.size
|
|
201
202
|
}).then(() => { stats.totalEntries++ })
|
|
202
203
|
}).catch({code: 'ENOENT'}, () => {
|
|
203
204
|
stats.rejectedEntries++
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cacache",
|
|
3
|
-
"version": "11.0
|
|
3
|
+
"version": "11.2.0",
|
|
4
4
|
"cache-version": {
|
|
5
5
|
"content": "2",
|
|
6
6
|
"index": "5"
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"figgy-pudding": "^3.1.0",
|
|
64
64
|
"glob": "^7.1.2",
|
|
65
65
|
"graceful-fs": "^4.1.11",
|
|
66
|
-
"lru-cache": "^4.1.
|
|
66
|
+
"lru-cache": "^4.1.3",
|
|
67
67
|
"mississippi": "^3.0.0",
|
|
68
68
|
"mkdirp": "^0.5.1",
|
|
69
69
|
"move-concurrently": "^1.0.1",
|
|
@@ -78,11 +78,10 @@
|
|
|
78
78
|
"chalk": "^2.3.2",
|
|
79
79
|
"cross-env": "^5.1.4",
|
|
80
80
|
"require-inject": "^1.4.2",
|
|
81
|
-
"safe-buffer": "^5.1.1",
|
|
82
81
|
"standard": "^11.0.1",
|
|
83
|
-
"standard-version": "^4.
|
|
84
|
-
"tacks": "^1.2.
|
|
85
|
-
"tap": "^
|
|
82
|
+
"standard-version": "^4.4.0",
|
|
83
|
+
"tacks": "^1.2.7",
|
|
84
|
+
"tap": "^12.0.1",
|
|
86
85
|
"weallbehave": "^1.2.0",
|
|
87
86
|
"weallcontribute": "^1.0.8"
|
|
88
87
|
},
|
package/put.js
CHANGED
|
@@ -13,10 +13,14 @@ const PutOpts = figgyPudding({
|
|
|
13
13
|
integrity: {},
|
|
14
14
|
memoize: {},
|
|
15
15
|
metadata: {},
|
|
16
|
+
pickAlgorithm: {},
|
|
16
17
|
size: {},
|
|
17
18
|
tmpPrefix: {},
|
|
18
19
|
uid: {},
|
|
19
|
-
gid: {}
|
|
20
|
+
gid: {},
|
|
21
|
+
single: {},
|
|
22
|
+
sep: {},
|
|
23
|
+
strict: {}
|
|
20
24
|
})
|
|
21
25
|
|
|
22
26
|
module.exports = putData
|