Skip to content

Commit

Permalink
Merge pull request #62 from Meroje/fix/consistent-mode-comparison
Browse files Browse the repository at this point in the history
Fix mode comparison
  • Loading branch information
contra committed Mar 10, 2015
2 parents db025fe + ba57ce7 commit 96867b4
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/dest/writeContents/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ function writeContents(writePath, file, cb) {
if (err) {
return complete(err);
}
// octal 7777 = decimal 4095
var currentMode = (st.mode & 4095);
if (currentMode === file.stat.mode) {
var currentMode = (st.mode & parseInt('0777', 8));
var expectedMode = (file.stat.mode & parseInt('0777', 8));
if (currentMode === expectedMode) {
return complete();
}
fs.chmod(writePath, file.stat.mode, complete);
fs.chmod(writePath, expectedMode, complete);
});
}

Expand Down
50 changes: 50 additions & 0 deletions test/dest.js
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,56 @@ describe('dest stream', function() {
stream.end();
});

it('should see a file with special chmod (setuid/setgid/sticky) as matching', function(done) {
var inputPath = path.join(__dirname, './fixtures/test.coffee');
var inputBase = path.join(__dirname, './fixtures/');
var expectedPath = path.join(__dirname, './out-fixtures/test.coffee');
var expectedContents = fs.readFileSync(inputPath);
var expectedCwd = __dirname;
var expectedBase = path.join(__dirname, './out-fixtures');
var expectedMode = 03722;
var normalMode = 0722;

var expectedFile = new File({
base: inputBase,
cwd: __dirname,
path: inputPath,
contents: expectedContents,
stat: {
mode: normalMode
}
});

var expectedCount = 0;
spies.setError(function(mod, fn) {
if (fn === 'stat' && arguments[2] === expectedPath) {
expectedCount++;
}
});

var onEnd = function(){
expectedCount.should.equal(1);
should(chmodSpy.called).be.not.ok;
realMode(fs.lstatSync(expectedPath).mode).should.equal(expectedMode);
done();
};

fs.mkdirSync(expectedBase);
fs.closeSync(fs.openSync(expectedPath, 'w'));
fs.chmodSync(expectedPath, expectedMode);

statSpy.reset();
chmodSpy.reset();
var stream = vfs.dest('./out-fixtures/', {cwd: __dirname});

var buffered = [];
bufferStream = through.obj(dataWrap(buffered.push.bind(buffered)), onEnd);

stream.pipe(bufferStream);
stream.write(expectedFile);
stream.end();
});

it('should not overwrite files with overwrite option set to false', function(done) {
var inputPath = path.join(__dirname, './fixtures/test.coffee');
var inputBase = path.join(__dirname, './fixtures/');
Expand Down

0 comments on commit 96867b4

Please sign in to comment.