Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mode comparison #62

Merged
merged 2 commits into from
Mar 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm this part doesnt click with me. if the mode is the same then the file contents wont get updated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parseInt is just there for readability, parseInt('07777', 8) would give 4095.
I changed it to 0777 to remove special bits, for example :

  • given a folder with sticky bit and setuid (5722)
  • if you then make a file with mode 644, it will become 5644
  • as of master, currentMode === file.stat.mode evaluates to false
  • vinyl-fs then tries to chmod the file, which fails when you are not the owner

My opinion is to let the filesystem handle the special bits and just deal with the actual permissions

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Meroje That wasn't my concern at all, not sure where that came from. My concern is that this is skipping file writes if the mode is the same, instead it should just not pass a mode into the file write if the mode is the same

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry I misread the diff - saw line 52 as fs.writeFile

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