Skip to content

Commit 766c2dd

Browse files
committed
Implements capital X (entry on directories)
1 parent 865a8d7 commit 766c2dd

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

src/chmod.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ function _chmod(options, mode, filePattern) {
114114
return;
115115
}
116116

117-
var perms = fs.statSync(file).mode;
117+
var stat = fs.statSync(file);
118+
var isDir = stat.isDirectory();
119+
var perms = stat.mode;
118120
var type = perms & PERMS.TYPE_MASK;
119121

120122
var newPerms = perms;
@@ -135,11 +137,15 @@ function _chmod(options, mode, filePattern) {
135137
var changeGroup = applyTo.indexOf('g') != -1 || applyTo === 'a' || applyTo === '';
136138
var changeOther = applyTo.indexOf('o') != -1 || applyTo === 'a' || applyTo === '';
137139

138-
var changeRead = change.indexOf('r') != -1;
139-
var changeWrite = change.indexOf('w') != -1;
140-
var changeExec = change.indexOf('x') != -1;
141-
var changeSticky = change.indexOf('t') != -1;
142-
var changeSetuid = change.indexOf('s') != -1;
140+
var changeRead = change.indexOf('r') != -1;
141+
var changeWrite = change.indexOf('w') != -1;
142+
var changeExec = change.indexOf('x') != -1;
143+
var changeExecDir = change.indexOf('X') != -1;
144+
var changeSticky = change.indexOf('t') != -1;
145+
var changeSetuid = change.indexOf('s') != -1;
146+
147+
if (changeExecDir && isDir)
148+
changeExec = true;
143149

144150
var mask = 0;
145151
if (changeOwner) {

test/chmod.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,17 @@ shell.chmod('a-rwx,u+rw', 'resources/chmod/file1');
125125
assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('600', 8), parseInt('600', 8));
126126
shell.chmod('644', 'resources/chmod/file1');
127127

128-
128+
// Support capital X ("entry" permission aka directory-only execute)
129+
130+
shell.chmod('744', 'resources/chmod/xdir');
131+
shell.chmod('644', 'resources/chmod/xdir/file');
132+
shell.chmod('744', 'resources/chmod/xdir/deep');
133+
shell.chmod('644', 'resources/chmod/xdir/deep/file');
134+
shell.chmod('-R', 'a+X', 'resources/chmod/xdir');
135+
136+
assert.equal(fs.statSync('resources/chmod/xdir').mode & parseInt('755', 8), parseInt('755', 8));
137+
assert.equal(fs.statSync('resources/chmod/xdir/file').mode & parseInt('644', 8), parseInt('644', 8));
138+
assert.equal(fs.statSync('resources/chmod/xdir/deep').mode & parseInt('755', 8), parseInt('755', 8));
139+
assert.equal(fs.statSync('resources/chmod/xdir/deep/file').mode & parseInt('644', 8), parseInt('644', 8));
129140

130141
shell.exit(123);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a file

test/resources/chmod/xdir/file

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a file

0 commit comments

Comments
 (0)