Skip to content

Commit 2d80af9

Browse files
committed
fix: do not chown if not running as root
Fix: #3
1 parent 568d7eb commit 2d80af9

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lib/util/fix-owner.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,15 @@ function fixOwner (cache, filepath) {
3737
// This platform doesn't need ownership fixing
3838
return BB.resolve()
3939
}
40+
41+
getSelf()
42+
if (self.uid !== 0) {
43+
// almost certainly can't chown anyway
44+
return BB.resolve()
45+
}
46+
4047
return BB.resolve(inferOwner(cache)).then(owner => {
4148
const { uid, gid } = owner
42-
getSelf()
4349

4450
// No need to override if it's already what we used.
4551
if (self.uid === uid && self.gid === gid) {

test/content.write.chownr.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
'use strict'
22

3+
const NEWUID = process.getuid() + 1
4+
const NEWGID = process.getgid() + 1
5+
6+
process.getuid = () => 0
7+
38
const testDir = require('./util/test-dir')(__filename)
49
const path = require('path')
510
const CACHE = path.join(testDir, 'cache')
611
const fs = require('fs')
7-
8-
const NEWUID = process.getuid() + 1
9-
const NEWGID = process.getgid() + 1
1012
const stat = fs.lstat
1113
fs.lstat = (path, cb) => {
1214
stat(path, (er, st) => {

0 commit comments

Comments
 (0)