Skip to content

Commit 79a53c0

Browse files
committed
fix: prevent EMFILE error in environment low file descriptors limit
1 parent 49e75b8 commit 79a53c0

File tree

12 files changed

+17
-16
lines changed

12 files changed

+17
-16
lines changed

lib/content/read.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const fs = require('fs/promises')
3+
const fs = require('fs-extra')
44
const fsm = require('fs-minipass')
55
const ssri = require('ssri')
66
const contentPath = require('./path')

lib/content/rm.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const fs = require('fs/promises')
3+
const fs = require('fs-extra')
44
const contentPath = require('./path')
55
const { hasContent } = require('./read')
66

lib/content/write.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const events = require('events')
44

55
const contentPath = require('./path')
6-
const fs = require('fs/promises')
6+
const fs = require('fs-extra')
77
const { moveFile } = require('@npmcli/fs')
88
const { Minipass } = require('minipass')
99
const Pipeline = require('minipass-pipeline')

lib/entry-index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const {
88
readdir,
99
rm,
1010
writeFile,
11-
} = require('fs/promises')
11+
} = require('fs-extra')
1212
const { Minipass } = require('minipass')
1313
const path = require('path')
1414
const ssri = require('ssri')

lib/rm.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const { rm } = require('fs/promises')
3+
const { rm } = require('fs-extra')
44
const glob = require('./util/glob.js')
55
const index = require('./entry-index')
66
const memo = require('./memoization')

lib/util/tmp.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

33
const { withTempDir } = require('@npmcli/fs')
4-
const fs = require('fs/promises')
4+
const fs = require('fs-extra')
55
const path = require('path')
66

77
module.exports.mkdir = mktmpdir

lib/verify.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const {
77
stat,
88
truncate,
99
writeFile,
10-
} = require('fs/promises')
10+
} = require('fs-extra')
1111
const contentPath = require('./content/path')
1212
const fsm = require('fs-minipass')
1313
const glob = require('./util/glob.js')

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"license": "ISC",
4848
"dependencies": {
4949
"@npmcli/fs": "^4.0.0",
50+
"fs-extra": "^11.2.0",
5051
"fs-minipass": "^3.0.0",
5152
"glob": "^10.2.2",
5253
"lru-cache": "^10.0.1",

test/content/read.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const getReadStatFailure = (t, err) => getRead(t, {
2424
throw err
2525
},
2626
},
27-
'fs/promises': {
27+
'fs-extra': {
2828
...fs.promises,
2929
stat: async () => {
3030
throw err
@@ -219,7 +219,7 @@ t.test('read: returns only first result if other hashes fails', function (t) {
219219
t.test('read: opening large files', function (t) {
220220
const CACHE = t.testdir()
221221
const mockedRead = getRead(t, {
222-
'fs/promises': {
222+
'fs-extra': {
223223
...fs.promises,
224224
stat: async () => {
225225
return { size: Number.MAX_SAFE_INTEGER }

test/entry-index.insert.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ t.test('ENOENT from appendFile is ignored', async (t) => {
224224
const cache = t.testdir()
225225

226226
const indexMocked = t.mock('../lib/entry-index.js', {
227-
'fs/promises': {
227+
'fs-extra': {
228228
...fs,
229229
appendFile: async () => {
230230
throw Object.assign(new Error('fake enoent'), { code: 'ENOENT' })
@@ -239,7 +239,7 @@ t.test('generic error from appendFile rejects', async (t) => {
239239
const cache = t.testdir()
240240

241241
const indexMocked = t.mock('../lib/entry-index.js', {
242-
'fs/promises': {
242+
'fs-extra': {
243243
...fs,
244244
appendFile: async () => {
245245
throw Object.assign(new Error('fake eperm'), { code: 'EPERM' })

test/entry-index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ missingFileError.code = 'ENOENT'
1717

1818
const getEntryIndex = (t, opts) => t.mock('../lib/entry-index', opts)
1919
const getEntryIndexReadFileFailure = (t, err) => getEntryIndex(t, {
20-
'fs/promises': {
20+
'fs-extra': {
2121
...fs.promises,
2222
readFile: async () => {
2323
throw err
@@ -233,7 +233,7 @@ t.test('lsStream: missing files error', async (t) => {
233233
t.test('lsStream: unknown error reading dirs', (t) => {
234234
const cache = t.testdir(cacheContent)
235235
const { lsStream } = getEntryIndex(t, {
236-
'fs/promises': {
236+
'fs-extra': {
237237
...fs.promises,
238238
readdir: async () => {
239239
throw genericError

test/verify.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ t.test('missing file error when validating cache content', async t => {
216216
const missingFileError = new Error('ENOENT')
217217
missingFileError.code = 'ENOENT'
218218
const mockVerify = getVerify(t, {
219-
'fs/promises': Object.assign({}, fs, {
219+
'fs-extra': Object.assign({}, fs, {
220220
stat: async () => {
221221
throw missingFileError
222222
},
@@ -238,7 +238,7 @@ t.test('missing file error when validating cache content', async t => {
238238

239239
t.test('unknown error when validating content', async t => {
240240
const mockVerify = getVerify(t, {
241-
'fs/promises': Object.assign({}, fs, {
241+
'fs-extra': Object.assign({}, fs, {
242242
stat: async () => {
243243
throw genericError
244244
},
@@ -274,7 +274,7 @@ t.test('unknown error when rebuilding bucket', async t => {
274274
// shouldFail controls the right time to mock the error
275275
let shouldFail = false
276276
const mockVerify = getVerify(t, {
277-
'fs/promises': Object.assign({}, fs, {
277+
'fs-extra': Object.assign({}, fs, {
278278
stat: async (path) => {
279279
if (shouldFail) {
280280
throw genericError

0 commit comments

Comments
 (0)