From 9d4776836a4eaa4b19701b4e4f00cd64578bf078 Mon Sep 17 00:00:00 2001 From: Audrey Eschright Date: Mon, 7 Jan 2019 17:41:49 -0800 Subject: [PATCH] chownr@1.1.1 --- node_modules/chownr/chownr.js | 112 ++++++++++++++++++++----------- node_modules/chownr/package.json | 43 ++++++------ package-lock.json | 6 +- package.json | 2 +- 4 files changed, 98 insertions(+), 65 deletions(-) diff --git a/node_modules/chownr/chownr.js b/node_modules/chownr/chownr.js index ecd7b452df57d..7e63928827e2c 100644 --- a/node_modules/chownr/chownr.js +++ b/node_modules/chownr/chownr.js @@ -1,52 +1,88 @@ -module.exports = chownr -chownr.sync = chownrSync +'use strict' +const fs = require('fs') +const path = require('path') + +/* istanbul ignore next */ +const LCHOWN = fs.lchown ? 'lchown' : 'chown' +/* istanbul ignore next */ +const LCHOWNSYNC = fs.lchownSync ? 'lchownSync' : 'chownSync' + +// fs.readdir could only accept an options object as of node v6 +const nodeVersion = process.version +let readdir = (path, options, cb) => fs.readdir(path, options, cb) +let readdirSync = (path, options) => fs.readdirSync(path, options) +/* istanbul ignore next */ +if (/^v4\./.test(nodeVersion)) + readdir = (path, options, cb) => fs.readdir(path, cb) + +const chownrKid = (p, child, uid, gid, cb) => { + if (typeof child === 'string') + return fs.lstat(path.resolve(p, child), (er, stats) => { + if (er) + return cb(er) + stats.name = child + chownrKid(p, stats, uid, gid, cb) + }) -var fs = require("fs") -, path = require("path") - -function chownr (p, uid, gid, cb) { - fs.readdir(p, function (er, children) { - // any error other than ENOTDIR means it's not readable, or - // doesn't exist. give up. - if (er && er.code !== "ENOTDIR") return cb(er) - if (er || !children.length) return fs.chown(p, uid, gid, cb) - - var len = children.length - , errState = null - children.forEach(function (child) { - var pathChild = path.resolve(p, child); - fs.lstat(pathChild, function(er, stats) { - if (er) - return cb(er) - if (!stats.isSymbolicLink()) - chownr(pathChild, uid, gid, then) - else - then() - }) + if (child.isDirectory()) { + chownr(path.resolve(p, child.name), uid, gid, er => { + if (er) + return cb(er) + fs[LCHOWN](path.resolve(p, child.name), uid, gid, cb) }) - function then (er) { + } else + fs[LCHOWN](path.resolve(p, child.name), uid, gid, cb) +} + + +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 || !children.length) return fs[LCHOWN](p, uid, gid, cb) + + let len = children.length + let errState = null + const then = er => { if (errState) return if (er) return cb(errState = er) - if (-- len === 0) return fs.chown(p, uid, gid, cb) + if (-- len === 0) return fs[LCHOWN](p, uid, gid, cb) } + + children.forEach(child => chownrKid(p, child, uid, gid, then)) }) } -function chownrSync (p, uid, gid) { - var children +const chownrKidSync = (p, child, uid, gid) => { + if (typeof child === 'string') { + const stats = fs.lstatSync(path.resolve(p, child)) + stats.name = child + child = stats + } + + if (child.isDirectory()) + chownrSync(path.resolve(p, child.name), uid, gid) + + fs[LCHOWNSYNC](path.resolve(p, child.name), uid, gid) +} + +const chownrSync = (p, uid, gid) => { + let children try { - children = fs.readdirSync(p) + children = readdirSync(p, { withFileTypes: true }) } catch (er) { - if (er && er.code === "ENOTDIR") return fs.chownSync(p, uid, gid) + if (er && er.code === 'ENOTDIR' && er.code !== 'ENOTSUP') + return fs[LCHOWNSYNC](p, uid, gid) throw er } - if (!children.length) return fs.chownSync(p, uid, gid) - children.forEach(function (child) { - var pathChild = path.resolve(p, child) - var stats = fs.lstatSync(pathChild) - if (!stats.isSymbolicLink()) - chownrSync(pathChild, uid, gid) - }) - return fs.chownSync(p, uid, gid) + if (children.length) + children.forEach(child => chownrKidSync(p, child, uid, gid)) + + return fs[LCHOWNSYNC](p, uid, gid) } + +module.exports = chownr +chownr.sync = chownrSync diff --git a/node_modules/chownr/package.json b/node_modules/chownr/package.json index f9a67c82435f9..0004fa0e1eb00 100644 --- a/node_modules/chownr/package.json +++ b/node_modules/chownr/package.json @@ -1,36 +1,28 @@ { - "_args": [ - [ - "chownr@1.0.1", - "/Users/rebecca/code/npm" - ] - ], - "_from": "chownr@1.0.1", - "_id": "chownr@1.0.1", + "_from": "chownr@1.1.1", + "_id": "chownr@1.1.1", "_inBundle": false, - "_integrity": "sha1-4qdQQqlVGQi+vSW4Uj1fl2nXkYE=", + "_integrity": "sha512-j38EvO5+LHX84jlo6h4UzmOwi0UgW61WRyPtJz4qaadK5eY3BTS5TY/S1Stc3Uk2lIM6TPevAlULiEJwie860g==", "_location": "/chownr", "_phantomChildren": {}, "_requested": { "type": "version", "registry": true, - "raw": "chownr@1.0.1", + "raw": "chownr@1.1.1", "name": "chownr", "escapedName": "chownr", - "rawSpec": "1.0.1", + "rawSpec": "1.1.1", "saveSpec": null, - "fetchSpec": "1.0.1" + "fetchSpec": "1.1.1" }, "_requiredBy": [ - "/", - "/cacache", - "/npm-profile/cacache", - "/npm-registry-fetch/cacache", - "/tar" + "#USER", + "/" ], - "_resolved": "https://registry.npmjs.org/chownr/-/chownr-1.0.1.tgz", - "_spec": "1.0.1", - "_where": "/Users/rebecca/code/npm", + "_resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.1.tgz", + "_shasum": "54726b8b8fff4df053c42187e801fb4412df1494", + "_spec": "chownr@1.1.1", + "_where": "/Users/aeschright/code/cli", "author": { "name": "Isaac Z. Schlueter", "email": "i@izs.me", @@ -39,11 +31,13 @@ "bugs": { "url": "https://github.com/isaacs/chownr/issues" }, + "bundleDependencies": false, + "deprecated": false, "description": "like `chown -R`", "devDependencies": { "mkdirp": "0.3", "rimraf": "", - "tap": "^1.2.0" + "tap": "^12.0.1" }, "files": [ "chownr.js" @@ -57,7 +51,10 @@ "url": "git://github.com/isaacs/chownr.git" }, "scripts": { - "test": "tap test/*.js" + "postpublish": "git push origin --all; git push origin --tags", + "postversion": "npm publish", + "preversion": "npm test", + "test": "tap test/*.js --cov" }, - "version": "1.0.1" + "version": "1.1.1" } diff --git a/package-lock.json b/package-lock.json index 2c990367d23fd..1fc79c47461f3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -485,9 +485,9 @@ "dev": true }, "chownr": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/chownr/-/chownr-1.0.1.tgz", - "integrity": "sha1-4qdQQqlVGQi+vSW4Uj1fl2nXkYE=" + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.1.tgz", + "integrity": "sha512-j38EvO5+LHX84jlo6h4UzmOwi0UgW61WRyPtJz4qaadK5eY3BTS5TY/S1Stc3Uk2lIM6TPevAlULiEJwie860g==" }, "ci-info": { "version": "1.6.0", diff --git a/package.json b/package.json index d47eaa2ecea99..34aa3f849b362 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "byte-size": "^5.0.1", "cacache": "^11.3.2", "call-limit": "~1.1.0", - "chownr": "~1.0.1", + "chownr": "^1.1.1", "ci-info": "^1.6.0", "cli-columns": "^3.1.2", "cli-table3": "^0.5.0",