From a6789b1491b2b6ee57702a6118b7cd1fb10a5ce5 Mon Sep 17 00:00:00 2001 From: Darcy Clarke Date: Tue, 25 Feb 2020 10:59:52 -0500 Subject: [PATCH] chownr@1.1.4 --- node_modules/chownr/chownr.js | 74 +++++++++++++++++++++++++------- node_modules/chownr/package.json | 33 +++++++------- package-lock.json | 6 +-- package.json | 2 +- 4 files changed, 80 insertions(+), 35 deletions(-) diff --git a/node_modules/chownr/chownr.js b/node_modules/chownr/chownr.js index 9f04393b7f498..0d40932169654 100644 --- a/node_modules/chownr/chownr.js +++ b/node_modules/chownr/chownr.js @@ -7,10 +7,30 @@ const LCHOWN = fs.lchown ? 'lchown' : 'chown' /* istanbul ignore next */ const LCHOWNSYNC = fs.lchownSync ? 'lchownSync' : 'chownSync' +/* istanbul ignore next */ const needEISDIRHandled = fs.lchown && !process.version.match(/v1[1-9]+\./) && !process.version.match(/v10\.[6-9]/) +const lchownSync = (path, uid, gid) => { + try { + return fs[LCHOWNSYNC](path, uid, gid) + } catch (er) { + if (er.code !== 'ENOENT') + throw er + } +} + +/* istanbul ignore next */ +const chownSync = (path, uid, gid) => { + try { + return fs.chownSync(path, uid, gid) + } catch (er) { + if (er.code !== 'ENOENT') + throw er + } +} + /* istanbul ignore next */ const handleEISDIR = needEISDIRHandled ? (path, uid, gid, cb) => er => { @@ -28,14 +48,14 @@ const handleEISDIR = const handleEISDirSync = needEISDIRHandled ? (path, uid, gid) => { try { - return fs[LCHOWNSYNC](path, uid, gid) + return lchownSync(path, uid, gid) } catch (er) { if (er.code !== 'EISDIR') throw er - fs.chownSync(path, uid, gid) + chownSync(path, uid, gid) } } - : (path, uid, gid) => fs[LCHOWNSYNC](path, uid, gid) + : (path, uid, gid) => lchownSync(path, uid, gid) // fs.readdir could only accept an options object as of node v6 const nodeVersion = process.version @@ -45,11 +65,19 @@ let readdirSync = (path, options) => fs.readdirSync(path, options) if (/^v4\./.test(nodeVersion)) readdir = (path, options, cb) => fs.readdir(path, cb) +const chown = (cpath, uid, gid, cb) => { + fs[LCHOWN](cpath, uid, gid, handleEISDIR(cpath, uid, gid, er => { + // Skip ENOENT error + cb(er && er.code !== 'ENOENT' ? er : null) + })) +} + const chownrKid = (p, child, uid, gid, cb) => { if (typeof child === 'string') return fs.lstat(path.resolve(p, child), (er, stats) => { + // Skip ENOENT error if (er) - return cb(er) + return cb(er.code !== 'ENOENT' ? er : null) stats.name = child chownrKid(p, stats, uid, gid, cb) }) @@ -59,11 +87,11 @@ const chownrKid = (p, child, uid, gid, cb) => { if (er) return cb(er) const cpath = path.resolve(p, child.name) - fs[LCHOWN](cpath, uid, gid, handleEISDIR(cpath, uid, gid, cb)) + chown(cpath, uid, gid, cb) }) } else { const cpath = path.resolve(p, child.name) - fs[LCHOWN](cpath, uid, gid, handleEISDIR(cpath, uid, gid, cb)) + chown(cpath, uid, gid, cb) } } @@ -72,10 +100,14 @@ const chownr = (p, uid, gid, cb) => { readdir(p, { withFileTypes: true }, (er, children) => { // any error other than ENOTDIR or ENOTSUP means it's not readable, // or doesn't exist. give up. - if (er && er.code !== 'ENOTDIR' && er.code !== 'ENOTSUP') - return cb(er) + if (er) { + if (er.code === 'ENOENT') + return cb() + else if (er.code !== 'ENOTDIR' && er.code !== 'ENOTSUP') + return cb(er) + } if (er || !children.length) - return fs[LCHOWN](p, uid, gid, handleEISDIR(p, uid, gid, cb)) + return chown(p, uid, gid, cb) let len = children.length let errState = null @@ -85,7 +117,7 @@ const chownr = (p, uid, gid, cb) => { if (er) return cb(errState = er) if (-- len === 0) - return fs[LCHOWN](p, uid, gid, handleEISDIR(p, uid, gid, cb)) + return chown(p, uid, gid, cb) } children.forEach(child => chownrKid(p, child, uid, gid, then)) @@ -94,9 +126,16 @@ const chownr = (p, uid, gid, cb) => { const chownrKidSync = (p, child, uid, gid) => { if (typeof child === 'string') { - const stats = fs.lstatSync(path.resolve(p, child)) - stats.name = child - child = stats + try { + const stats = fs.lstatSync(path.resolve(p, child)) + stats.name = child + child = stats + } catch (er) { + if (er.code === 'ENOENT') + return + else + throw er + } } if (child.isDirectory()) @@ -110,12 +149,15 @@ const chownrSync = (p, uid, gid) => { try { children = readdirSync(p, { withFileTypes: true }) } catch (er) { - if (er && er.code === 'ENOTDIR' && er.code !== 'ENOTSUP') + if (er.code === 'ENOENT') + return + else if (er.code === 'ENOTDIR' || er.code === 'ENOTSUP') return handleEISDirSync(p, uid, gid) - throw er + else + throw er } - if (children.length) + if (children && children.length) children.forEach(child => chownrKidSync(p, child, uid, gid)) return handleEISDirSync(p, uid, gid) diff --git a/node_modules/chownr/package.json b/node_modules/chownr/package.json index cc48dc912cd7e..5c125f8447b54 100644 --- a/node_modules/chownr/package.json +++ b/node_modules/chownr/package.json @@ -1,19 +1,19 @@ { - "_from": "chownr@1.1.3", - "_id": "chownr@1.1.3", + "_from": "chownr@1.1.4", + "_id": "chownr@1.1.4", "_inBundle": false, - "_integrity": "sha512-i70fVHhmV3DtTl6nqvZOnIjbY0Pe4kAUjwHj8z0zAdgBtYrJyYwLKCCuRBQ5ppkyL0AkN7HKRnETdmdp1zqNXw==", + "_integrity": "sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg==", "_location": "/chownr", "_phantomChildren": {}, "_requested": { "type": "version", "registry": true, - "raw": "chownr@1.1.3", + "raw": "chownr@1.1.4", "name": "chownr", "escapedName": "chownr", - "rawSpec": "1.1.3", + "rawSpec": "1.1.4", "saveSpec": null, - "fetchSpec": "1.1.3" + "fetchSpec": "1.1.4" }, "_requiredBy": [ "#USER", @@ -23,10 +23,10 @@ "/pacote", "/tar" ], - "_resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.3.tgz", - "_shasum": "42d837d5239688d55f303003a508230fa6727142", - "_spec": "chownr@1.1.3", - "_where": "/Users/mperrotte/npminc/cli", + "_resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.4.tgz", + "_shasum": "6fc9d7b42d32a583596337666e7d08084da2cc6b", + "_spec": "chownr@1.1.4", + "_where": "/Users/darcyclarke/Documents/Repos/npm/cli", "author": { "name": "Isaac Z. Schlueter", "email": "i@izs.me", @@ -40,8 +40,8 @@ "description": "like `chown -R`", "devDependencies": { "mkdirp": "0.3", - "rimraf": "", - "tap": "^12.0.1" + "rimraf": "^2.7.1", + "tap": "^14.10.6" }, "files": [ "chownr.js" @@ -55,10 +55,13 @@ "url": "git://github.com/isaacs/chownr.git" }, "scripts": { - "postpublish": "git push origin --follow-tags", "postversion": "npm publish", + "prepublishOnly": "git push origin --follow-tags", "preversion": "npm test", - "test": "tap test/*.js --cov" + "test": "tap" }, - "version": "1.1.3" + "tap": { + "check-coverage": true + }, + "version": "1.1.4" } diff --git a/package-lock.json b/package-lock.json index 1bf5cd29e6e47..1509289584c64 100644 --- a/package-lock.json +++ b/package-lock.json @@ -666,9 +666,9 @@ "dev": true }, "chownr": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.3.tgz", - "integrity": "sha512-i70fVHhmV3DtTl6nqvZOnIjbY0Pe4kAUjwHj8z0zAdgBtYrJyYwLKCCuRBQ5ppkyL0AkN7HKRnETdmdp1zqNXw==" + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.4.tgz", + "integrity": "sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg==" }, "ci-info": { "version": "2.0.0", diff --git a/package.json b/package.json index 8997cd16071a5..56a3722390815 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "byte-size": "^5.0.1", "cacache": "^12.0.3", "call-limit": "^1.1.1", - "chownr": "^1.1.3", + "chownr": "^1.1.4", "ci-info": "^2.0.0", "cli-columns": "^3.1.2", "cli-table3": "^0.5.1",