diff --git a/src/chmod.js b/src/chmod.js index f288893..30aa904 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 { diff --git a/test/chmod.js b/test/chmod.js index 521ed4c..cbc1411 100644 --- a/test/chmod.js +++ b/test/chmod.js @@ -77,4 +77,54 @@ 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('630', 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.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);