cacache 17.0.7 → 17.1.1
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/README.md +1 -1
- package/lib/content/write.js +25 -14
- package/lib/entry-index.js +2 -2
- package/lib/verify.js +6 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -101,7 +101,7 @@ cacache.get.byDigest(cachePath, integrityHash).then(data => {
|
|
|
101
101
|
|
|
102
102
|
### Contributing
|
|
103
103
|
|
|
104
|
-
The cacache team enthusiastically welcomes contributions and project participation! There's a bunch of things you can do if you want to contribute!
|
|
104
|
+
The cacache team enthusiastically welcomes contributions and project participation! There's a bunch of things you can do if you want to contribute! Please don't hesitate to jump in if you'd like to, or even ask us questions if something isn't clear.
|
|
105
105
|
|
|
106
106
|
All participants and maintainers in this project are expected to follow [Code of Conduct](CODE_OF_CONDUCT.md), and just generally be excellent to each other.
|
|
107
107
|
|
package/lib/content/write.js
CHANGED
|
@@ -15,11 +15,11 @@ const fsm = require('fs-minipass')
|
|
|
15
15
|
|
|
16
16
|
module.exports = write
|
|
17
17
|
|
|
18
|
+
// Cache of move operations in process so we don't duplicate
|
|
19
|
+
const moveOperations = new Map()
|
|
20
|
+
|
|
18
21
|
async function write (cache, data, opts = {}) {
|
|
19
22
|
const { algorithms, size, integrity } = opts
|
|
20
|
-
if (algorithms && algorithms.length > 1) {
|
|
21
|
-
throw new Error('opts.algorithms only supports a single algorithm for now')
|
|
22
|
-
}
|
|
23
23
|
|
|
24
24
|
if (typeof size === 'number' && data.length !== size) {
|
|
25
25
|
throw sizeError(size, data.length)
|
|
@@ -30,16 +30,19 @@ async function write (cache, data, opts = {}) {
|
|
|
30
30
|
throw checksumError(integrity, sri)
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
for (const algo in sri) {
|
|
34
|
+
const tmp = await makeTmp(cache, opts)
|
|
35
|
+
const hash = sri[algo].toString()
|
|
36
|
+
try {
|
|
37
|
+
await fs.writeFile(tmp.target, data, { flag: 'wx' })
|
|
38
|
+
await moveToDestination(tmp, cache, hash, opts)
|
|
39
|
+
} finally {
|
|
40
|
+
if (!tmp.moved) {
|
|
41
|
+
await fs.rm(tmp.target, { recursive: true, force: true })
|
|
42
|
+
}
|
|
41
43
|
}
|
|
42
44
|
}
|
|
45
|
+
return { integrity: sri, size: data.length }
|
|
43
46
|
}
|
|
44
47
|
|
|
45
48
|
module.exports.stream = writeStream
|
|
@@ -159,15 +162,23 @@ async function makeTmp (cache, opts) {
|
|
|
159
162
|
async function moveToDestination (tmp, cache, sri, opts) {
|
|
160
163
|
const destination = contentPath(cache, sri)
|
|
161
164
|
const destDir = path.dirname(destination)
|
|
162
|
-
|
|
163
|
-
|
|
165
|
+
if (moveOperations.has(destination)) {
|
|
166
|
+
return moveOperations.get(destination)
|
|
167
|
+
}
|
|
168
|
+
moveOperations.set(
|
|
169
|
+
destination,
|
|
170
|
+
fs.mkdir(destDir, { recursive: true })
|
|
171
|
+
.then(() => moveFile(tmp.target, destination, { overwrite: false }))
|
|
172
|
+
)
|
|
164
173
|
try {
|
|
165
|
-
await
|
|
174
|
+
await moveOperations.get(destination)
|
|
166
175
|
tmp.moved = true
|
|
167
176
|
} catch (err) {
|
|
168
177
|
if (!err.message.startsWith('The destination file exists')) {
|
|
169
178
|
throw Object.assign(err, { code: 'EEXIST' })
|
|
170
179
|
}
|
|
180
|
+
} finally {
|
|
181
|
+
moveOperations.delete(destination)
|
|
171
182
|
}
|
|
172
183
|
}
|
|
173
184
|
|
package/lib/entry-index.js
CHANGED
|
@@ -109,12 +109,12 @@ async function compact (cache, key, matchFn, opts = {}) {
|
|
|
109
109
|
module.exports.insert = insert
|
|
110
110
|
|
|
111
111
|
async function insert (cache, key, integrity, opts = {}) {
|
|
112
|
-
const { metadata, size } = opts
|
|
112
|
+
const { metadata, size, time } = opts
|
|
113
113
|
const bucket = bucketPath(cache, key)
|
|
114
114
|
const entry = {
|
|
115
115
|
key,
|
|
116
116
|
integrity: integrity && ssri.stringify(integrity),
|
|
117
|
-
time: Date.now(),
|
|
117
|
+
time: time || Date.now(),
|
|
118
118
|
size,
|
|
119
119
|
metadata,
|
|
120
120
|
}
|
package/lib/verify.js
CHANGED
|
@@ -100,7 +100,11 @@ async function garbageCollect (cache, opts) {
|
|
|
100
100
|
return
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
|
|
103
|
+
// integrity is stringified, re-parse it so we can get each hash
|
|
104
|
+
const integrity = ssri.parse(entry.integrity)
|
|
105
|
+
for (const algo in integrity) {
|
|
106
|
+
liveContent.add(integrity[algo].toString())
|
|
107
|
+
}
|
|
104
108
|
})
|
|
105
109
|
await new Promise((resolve, reject) => {
|
|
106
110
|
indexStream.on('end', resolve).on('error', reject)
|
|
@@ -220,6 +224,7 @@ async function rebuildBucket (cache, bucket, stats, opts) {
|
|
|
220
224
|
await index.insert(cache, entry.key, entry.integrity, {
|
|
221
225
|
metadata: entry.metadata,
|
|
222
226
|
size: entry.size,
|
|
227
|
+
time: entry.time,
|
|
223
228
|
})
|
|
224
229
|
stats.totalEntries++
|
|
225
230
|
} catch (err) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cacache",
|
|
3
|
-
"version": "17.
|
|
3
|
+
"version": "17.1.1",
|
|
4
4
|
"cache-version": {
|
|
5
5
|
"content": "2",
|
|
6
6
|
"index": "5"
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@npmcli/eslint-config": "^4.0.0",
|
|
63
|
-
"@npmcli/template-oss": "4.
|
|
63
|
+
"@npmcli/template-oss": "4.15.1",
|
|
64
64
|
"tap": "^16.0.0"
|
|
65
65
|
},
|
|
66
66
|
"engines": {
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"templateOSS": {
|
|
70
70
|
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
|
|
71
71
|
"windowsCI": false,
|
|
72
|
-
"version": "4.
|
|
72
|
+
"version": "4.15.1",
|
|
73
73
|
"publish": "true"
|
|
74
74
|
},
|
|
75
75
|
"author": "GitHub Inc.",
|