Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

chownr

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chownr - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

104

chownr.js

@@ -1,52 +0,86 @@

module.exports = chownr
chownr.sync = chownrSync
'use strict'
const fs = require('fs')
const path = require('path')
var fs = require("fs")
, path = require("path")
/* istanbul ignore next */
const LCHOWN = fs.lchown ? 'lchown' : 'chown'
/* istanbul ignore next */
const LCHOWNSYNC = fs.lchownSync ? 'lchownSync' : 'chownSync'
function chownr (p, uid, gid, cb) {
fs.readdir(p, function (er, children) {
// 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)
})
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)
})
} 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 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)
if (er && er.code !== 'ENOTDIR') return cb(er)
if (er || !children.length) return fs[LCHOWN](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()
})
})
function then (er) {
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') 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

@@ -5,3 +5,3 @@ {

"description": "like `chown -R`",
"version": "1.0.1",
"version": "1.1.0",
"repository": {

@@ -18,8 +18,11 @@ "type": "git",

"rimraf": "",
"tap": "^1.2.0"
"tap": "^12.0.1"
},
"scripts": {
"test": "tap test/*.js"
"test": "tap test/*.js --cov",
"preversion": "npm test",
"postversion": "npm publish",
"postpublish": "git push origin --all; git push origin --tags"
},
"license": "ISC"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc