From 9aba4d4ab251bee14a93044b3070232ff6acc315 Mon Sep 17 00:00:00 2001 From: "Liam (GH:rezonant)" Date: Wed, 26 Aug 2015 14:17:57 -0400 Subject: [PATCH 1/5] Adds more tests --- test/chmod.js | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/test/chmod.js b/test/chmod.js index 521ed4c..14e129b 100644 --- a/test/chmod.js +++ b/test/chmod.js @@ -77,4 +77,48 @@ assert.equal(fs.statSync('resources/chmod/b/a').mode & parseInt('700', 8), parse shell.chmod('-R', 'u+w', 'resources/chmod/a/b'); fs.unlinkSync('resources/chmod/a/b/c/link'); -shell.exit(123); \ No newline at end of file +// Test combinations +shell.chmod('a-rwx', 'resources/chmod/file1'); +assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('000', 8), parseInt('000', 8)); +shell.chmod('644', 'resources/chmod/file1'); + +shell.chmod('a-rwx,u+r', 'resources/chmod/file1'); +assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('400', 8), parseInt('400', 8)); +shell.chmod('644', 'resources/chmod/file1'); + +shell.chmod('a-rwx,u+rw', 'resources/chmod/file1'); +assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('600', 8), parseInt('600', 8)); +shell.chmod('644', 'resources/chmod/file1'); + +shell.chmod('a-rwx,u+rwx', 'resources/chmod/file1'); +assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('700', 8), parseInt('700', 8)); +shell.chmod('644', 'resources/chmod/file1'); + +shell.chmod('000', 'resources/chmod/file1'); +shell.chmod('u+rw', 'resources/chmod/file1'); +assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('600', 8), parseInt('600', 8)); +shell.chmod('644', 'resources/chmod/file1'); + +shell.chmod('000', 'resources/chmod/file1'); +shell.chmod('u+wx', 'resources/chmod/file1'); +assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('300', 8), parseInt('300', 8)); +shell.chmod('644', 'resources/chmod/file1'); + +shell.chmod('000', 'resources/chmod/file1'); +shell.chmod('u+r,g+w,o+x', 'resources/chmod/file1'); +assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('421', 8), parseInt('421', 8)); +shell.chmod('644', 'resources/chmod/file1'); + +shell.chmod('000', 'resources/chmod/file1'); +shell.chmod('u+rw,g+wx', 'resources/chmod/file1'); +assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('462', 8), parseInt('630', 8)); +shell.chmod('644', 'resources/chmod/file1'); + +shell.chmod('700', 'resources/chmod/file1'); +shell.chmod('u-x,g+rw', 'resources/chmod/file1'); +assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('660', 8), parseInt('660', 8)); +shell.chmod('644', 'resources/chmod/file1'); + + + +shell.exit(123); From e4e026dac44d15e76f85de8952382f1b2287e12b Mon Sep 17 00:00:00 2001 From: "Liam (GH:rezonant)" Date: Wed, 26 Aug 2015 14:20:07 -0400 Subject: [PATCH 2/5] Fixes incorrect mask --- test/chmod.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/chmod.js b/test/chmod.js index 14e129b..d340aa4 100644 --- a/test/chmod.js +++ b/test/chmod.js @@ -111,7 +111,7 @@ shell.chmod('644', 'resources/chmod/file1'); shell.chmod('000', 'resources/chmod/file1'); shell.chmod('u+rw,g+wx', 'resources/chmod/file1'); -assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('462', 8), parseInt('630', 8)); +assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('630', 8), parseInt('630', 8)); shell.chmod('644', 'resources/chmod/file1'); shell.chmod('700', 'resources/chmod/file1'); From 55225d9a0d05884376635db4bf88ce8bcfa667d3 Mon Sep 17 00:00:00 2001 From: "Liam (GH:rezonant)" Date: Wed, 26 Aug 2015 15:00:33 -0400 Subject: [PATCH 3/5] A broken test --- test/chmod.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/chmod.js b/test/chmod.js index d340aa4..cbc1411 100644 --- a/test/chmod.js +++ b/test/chmod.js @@ -119,6 +119,12 @@ shell.chmod('u-x,g+rw', 'resources/chmod/file1'); assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('660', 8), parseInt('660', 8)); shell.chmod('644', 'resources/chmod/file1'); +shell.chmod('a-rwx,u+rw', 'resources/chmod/file1'); +assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('600', 8), parseInt('600', 8)); +shell.chmod('a-rwx,u+rw', 'resources/chmod/file1'); +assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('600', 8), parseInt('600', 8)); +shell.chmod('644', 'resources/chmod/file1'); + shell.exit(123); From 670420c90e1c5e4a0dad70a929dcb4f33cab3c4d Mon Sep 17 00:00:00 2001 From: "Liam (GH:rezonant)" Date: Wed, 26 Aug 2015 15:01:04 -0400 Subject: [PATCH 4/5] Fixes said broken test --- src/chmod.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/chmod.js b/src/chmod.js index f288893..be0f3c9 100644 --- a/src/chmod.js +++ b/src/chmod.js @@ -185,6 +185,7 @@ function _chmod(options, mode, filePattern) { log(file + ' -> ' + newPerms.toString(8)); } fs.chmodSync(file, newPerms); + //perms = newPerms; // for the next round of changes! } } else { From 865a8d7c80eb36a690e445546e1e915ae147df32 Mon Sep 17 00:00:00 2001 From: "Liam (GH:rezonant)" Date: Wed, 26 Aug 2015 15:08:20 -0400 Subject: [PATCH 5/5] Oops, was commented out for verification --- src/chmod.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chmod.js b/src/chmod.js index be0f3c9..30aa904 100644 --- a/src/chmod.js +++ b/src/chmod.js @@ -185,7 +185,7 @@ function _chmod(options, mode, filePattern) { log(file + ' -> ' + newPerms.toString(8)); } fs.chmodSync(file, newPerms); - //perms = newPerms; // for the next round of changes! + perms = newPerms; // for the next round of changes! } } else {