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

Conversation

Meroje
Copy link
Contributor

@Meroje Meroje commented Mar 6, 2015

Related to #61, I found that the actual issue is currentMode gets its flags stripped by the bitwise comparison, but not the destination mode. This adds bitwise comparison to the dest mode to fix detection of different modes.

@yocontra
Copy link
Member

yocontra commented Mar 6, 2015

got a test?

@Meroje
Copy link
Contributor Author

Meroje commented Mar 6, 2015

Do you mean a test to prove current implementation breaks, or that it works in the PR ?

@yocontra
Copy link
Member

yocontra commented Mar 6, 2015

@Meroje - both, a test that fails currently and passes after this PR

@Meroje Meroje force-pushed the fix/consistent-mode-comparison branch from ac3fbe3 to ba57ce7 Compare March 9, 2015 16:03
@Meroje
Copy link
Contributor Author

Meroje commented Mar 9, 2015

I've got a failing test here, passing on this pull request.

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

yocontra pushed a commit that referenced this pull request Mar 10, 2015
@yocontra yocontra merged commit 96867b4 into gulpjs:master Mar 10, 2015
@yocontra
Copy link
Member

This is causing a failing test for me locally

  1) dest stream should see a file with special chmod (setuid/setgid/sticky) as matching:

      Uncaught AssertionError: expected 978 to be 2002
      + expected - actual

      +2002
      -978

      at Assertion.fail (/Users/contra/Projects/vinyl-fs/node_modules/should/lib/assertion.js:196:17)
      at Assertion.prop.(anonymous function) (/Users/contra/Projects/vinyl-fs/node_modules/should/lib/assertion.js:81:17)
      at DestroyableTransform.onEnd [as _flush] (/Users/contra/Projects/vinyl-fs/test/dest.js:746:56)
      at DestroyableTransform.<anonymous> (/Users/contra/Projects/vinyl-fs/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:135:12)
      at DestroyableTransform.g (events.js:257:16)
      at emitNone (events.js:67:13)
      at DestroyableTransform.emit (events.js:163:7)
      at finishMaybe (/Users/contra/Projects/vinyl-fs/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:371:12)
      at endWritable (/Users/contra/Projects/vinyl-fs/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:378:3)
      at DestroyableTransform.Writable.end (/Users/contra/Projects/vinyl-fs/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:356:5)
      at DestroyableTransform.onend (stream.js:60:10)
      at emitNone (events.js:72:20)
      at DestroyableTransform.emit (events.js:163:7)
      at /Users/contra/Projects/vinyl-fs/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:965:16
      at process._tickCallback (node.js:349:13)

@Meroje
Copy link
Contributor Author

Meroje commented Mar 23, 2015

Just saw it, the the chmod changes to 01722 on stream.end.
The whole thing being to not care about the first bit, I would change the expectedMode or remove the line realMode(fs.lstatSync(expectedPath).mode).should.equal(expectedMode); (was copy/pasted)

@yocontra
Copy link
Member

@Meroje PR?

@Meroje
Copy link
Contributor Author

Meroje commented Mar 23, 2015

It seems this is an osx thing, the test still passes on my ubuntu work machine, I will just remove the chmod equal expectation.

Meroje added a commit to Meroje/vinyl-fs that referenced this pull request Mar 23, 2015
It has been shown in gulpjs#62 this bit can be platform specific and is unreliable, testing fs.chmod is not called will be enough.
phated pushed a commit that referenced this pull request Nov 27, 2017
It has been shown in #62 this bit can be platform specific and is unreliable, testing fs.chmod is not called will be enough.
phated pushed a commit that referenced this pull request Nov 27, 2017
It has been shown in #62 this bit can be platform specific and is unreliable, testing fs.chmod is not called will be enough.
phated pushed a commit that referenced this pull request Nov 27, 2017
It has been shown in #62 this bit can be platform specific and is unreliable, testing fs.chmod is not called will be enough.
phated pushed a commit that referenced this pull request Nov 27, 2017
It has been shown in #62 this bit can be platform specific and is unreliable, testing fs.chmod is not called will be enough.
phated pushed a commit that referenced this pull request Nov 27, 2017
It has been shown in #62 this bit can be platform specific and is unreliable, testing fs.chmod is not called will be enough.
phated pushed a commit that referenced this pull request Nov 27, 2017
It has been shown in #62 this bit can be platform specific and is unreliable, testing fs.chmod is not called will be enough.
phated pushed a commit that referenced this pull request Nov 27, 2017
It has been shown in #62 this bit can be platform specific and is unreliable, testing fs.chmod is not called will be enough.
phated pushed a commit that referenced this pull request Nov 28, 2017
It has been shown in #62 this bit can be platform specific and is unreliable, testing fs.chmod is not called will be enough.
phated pushed a commit that referenced this pull request Nov 28, 2017
It has been shown in #62 this bit can be platform specific and is unreliable, testing fs.chmod is not called will be enough.
phated pushed a commit that referenced this pull request Nov 28, 2017
It has been shown in #62 this bit can be platform specific and is unreliable, testing fs.chmod is not called will be enough.
phated pushed a commit that referenced this pull request Nov 28, 2017
It has been shown in #62 this bit can be platform specific and is unreliable, testing fs.chmod is not called will be enough.
phated pushed a commit that referenced this pull request Nov 28, 2017
It has been shown in #62 this bit can be platform specific and is unreliable, testing fs.chmod is not called will be enough.
phated pushed a commit that referenced this pull request Nov 28, 2017
It has been shown in #62 this bit can be platform specific and is unreliable, testing fs.chmod is not called will be enough.
phated pushed a commit that referenced this pull request Nov 28, 2017
It has been shown in #62 this bit can be platform specific and is unreliable, testing fs.chmod is not called will be enough.
phated pushed a commit that referenced this pull request Nov 28, 2017
It has been shown in #62 this bit can be platform specific and is unreliable, testing fs.chmod is not called will be enough.
phated pushed a commit that referenced this pull request Nov 28, 2017
It has been shown in #62 this bit can be platform specific and is unreliable, testing fs.chmod is not called will be enough.
phated pushed a commit that referenced this pull request Nov 28, 2017
It has been shown in #62 this bit can be platform specific and is unreliable, testing fs.chmod is not called will be enough.
phated pushed a commit that referenced this pull request Nov 28, 2017
It has been shown in #62 this bit can be platform specific and is unreliable, testing fs.chmod is not called will be enough.
phated pushed a commit that referenced this pull request Dec 5, 2017
phated pushed a commit that referenced this pull request Dec 5, 2017
It has been shown in #62 this bit can be platform specific and is unreliable, testing fs.chmod is not called will be enough.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants