Skip to content

Commit 3eec56e

Browse files
committedMay 3, 2023
deps: cacache@17.1.0
1 parent 7a2ce3f commit 3eec56e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+11376
-91
lines changed
 

‎node_modules/.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@
7777
!/buffer
7878
!/builtins
7979
!/cacache
80+
!/cacache/node_modules/
81+
/cacache/node_modules/*
82+
!/cacache/node_modules/foreground-child
83+
!/cacache/node_modules/glob
84+
!/cacache/node_modules/jackspeak
85+
!/cacache/node_modules/minimatch
86+
!/cacache/node_modules/minipass
87+
!/cacache/node_modules/signal-exit
8088
!/chalk
8189
!/chownr
8290
!/ci-info

‎node_modules/cacache/lib/content/write.js

+21-15
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ const events = require('events')
44

55
const contentPath = require('./path')
66
const fs = require('fs/promises')
7-
const moveFile = require('../util/move-file')
8-
const Minipass = require('minipass')
7+
const { moveFile } = require('@npmcli/fs')
8+
const { Minipass } = require('minipass')
99
const Pipeline = require('minipass-pipeline')
1010
const Flush = require('minipass-flush')
1111
const path = require('path')
@@ -17,9 +17,6 @@ module.exports = write
1717

1818
async function write (cache, data, opts = {}) {
1919
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-
}
2320

2421
if (typeof size === 'number' && data.length !== size) {
2522
throw sizeError(size, data.length)
@@ -30,16 +27,19 @@ async function write (cache, data, opts = {}) {
3027
throw checksumError(integrity, sri)
3128
}
3229

33-
const tmp = await makeTmp(cache, opts)
34-
try {
35-
await fs.writeFile(tmp.target, data, { flag: 'wx' })
36-
await moveToDestination(tmp, cache, sri, opts)
37-
return { integrity: sri, size: data.length }
38-
} finally {
39-
if (!tmp.moved) {
40-
await fs.rm(tmp.target, { recursive: true, force: true })
30+
for (const algo in sri) {
31+
const tmp = await makeTmp(cache, opts)
32+
const hash = sri[algo].toString()
33+
try {
34+
await fs.writeFile(tmp.target, data, { flag: 'wx' })
35+
await moveToDestination(tmp, cache, hash, opts)
36+
} finally {
37+
if (!tmp.moved) {
38+
await fs.rm(tmp.target, { recursive: true, force: true })
39+
}
4140
}
4241
}
42+
return { integrity: sri, size: data.length }
4343
}
4444

4545
module.exports.stream = writeStream
@@ -161,8 +161,14 @@ async function moveToDestination (tmp, cache, sri, opts) {
161161
const destDir = path.dirname(destination)
162162

163163
await fs.mkdir(destDir, { recursive: true })
164-
await moveFile(tmp.target, destination)
165-
tmp.moved = true
164+
try {
165+
await moveFile(tmp.target, destination, { overwrite: false })
166+
tmp.moved = true
167+
} catch (err) {
168+
if (!err.message.startsWith('The destination file exists')) {
169+
throw Object.assign(err, { code: 'EEXIST' })
170+
}
171+
}
166172
}
167173

168174
function sizeError (expected, found) {

0 commit comments

Comments
 (0)
Please sign in to comment.