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 chmod function arguments #71

Merged
merged 2 commits into from
Jul 26, 2016
Merged

fix chmod function arguments #71

merged 2 commits into from
Jul 26, 2016

Conversation

thefourtheye
Copy link
Contributor

*chmod* functions accept only path and mode. As we were using
chownFix, it misinterprets callback function passed to chmod as gid.

Possible Fix for nodejs/node#7846

`*chmod*` functions accept only `path` and `mode`. As we were using
`chownFix`, it misinterprets callback function passed to `chmod` as `gid`.
@MylesBorins
Copy link

@thefourtheye there are still four failures in npm with this patch

test/tap/install-link-scripts.js ...................... 1/4
  plain install
  not ok TypeError: cb is not a function
    at:
      line: 210
      column: 7
      file: node_modules/graceful-fs/polyfills.js
    stack: |
      node_modules/graceful-fs/polyfills.js:210:7
      FSReqWrap.oncomplete (fs.js:123:15)
    test: plain install
    message: 'TypeError: cb is not a function'

  link
  not ok TypeError: cb is not a function
    at:
      line: 210
      column: 7
      file: node_modules/graceful-fs/polyfills.js
    stack: |
      node_modules/graceful-fs/polyfills.js:210:7
      FSReqWrap.oncomplete (fs.js:123:15)
    test: link
    message: 'TypeError: cb is not a function'

  install --link
  not ok TypeError: cb is not a function
    at:
      line: 210
      column: 7
      file: node_modules/graceful-fs/polyfills.js
    stack: |
      node_modules/graceful-fs/polyfills.js:210:7
      FSReqWrap.oncomplete (fs.js:123:15)
    test: install --link
    message: 'TypeError: cb is not a function'
test/tap/update-symlink.js .......................... 14/15 6s
  when update is called linked packages should be excluded
  not ok updated ok
    found: >+
      my-local-package@1.0.0
      /Users/thealphanerd/code/node/master/test-npm/test/tap/update-symlink

      `-- async@2.0.1

    pattern: /async@1.5.2/
    at:
      line: 64
      column: 9
      file: test/tap/update-symlink.js
    stack: |
      test/tap/update-symlink.js:64:9
      f (node_modules/once/once.js:17:25)
      ChildProcess.<anonymous> (test/common-tap.js:68:5)
      Pipe._handle.close [as _onclose] (net.js:492:12)

@ChALkeR
Copy link
Contributor

ChALkeR commented Jul 25, 2016

@thefourtheye Note that this patch actually makes callback argument mandratory for chmod even for older Node versions (e.g. v4 or v6), where it's not mandratory. Strictly speaking, this is a major change in graceful-fs.

For this to be not major, it should check if callback is being passed.

@MylesBorins
Copy link

@@ -205,6 +205,7 @@ function patchLutimes (fs) {
 function chmodFix (orig) {
   if (!orig) return orig
   return function (target, mode, cb) {
+    if (!cb) cb = function () {}
     return orig.call(fs, target, mode, function (er, res) {
       if (chownErOk(er)) er = null
       cb(er, res)

This diff will make this a semverpatch change. I think it would likely be in the spirit of graceful-fs to "gracefully" handle the case where to callback is given.

@isaacs do you consider a no-op graceful or should there be some sort of error / warning on platforms that require the callback?

@MylesBorins MylesBorins mentioned this pull request Jul 26, 2016
2 tasks
@thefourtheye
Copy link
Contributor Author

@thealphanerd Thanks. I included a fix to the problem now. PTAL.

@isaacs
Copy link
Owner

isaacs commented Jul 26, 2016

This patch doesn't seem offensive to me at all, but I'm not quite getting exactly what the problem is that it's addressing.

Can someone provide an example program or test that shows the specific behavior that this is addressing? Is it a node core change that needs to be taken into consideration? The link to nodejs/node#7846 is a bit confusing for me to follow.

@isaacs
Copy link
Owner

isaacs commented Jul 26, 2016

Basically, if it's "chownFix doesn't work for chmod", well... ok... how come it was working all this time, then? Was it always broken? If so, how was it broken?

I'm not trying to be difficult, I just have an excessive abundance of caution where it concerns this module, because it is so widely depended upon. Thanks for understanding :)

@MylesBorins
Copy link

@isaacs the TLDR on nodejs/node#7846 is that all fs async calls in a future major version will make the callback mandatory. This change is likely getting reverted right now as we assess ecosystem breakage

As for the the chownFix not working... it seems to me like it was working but my accident.

fs.chown(path, uid, gid, callback)
fs.chmod(path, mode, callback)

So the way it was being done before the callback was being passed as the gid and it just happened to work.

The unfortunate side effect of this was that the callback wrapper that checks the error and wraps it in chownErOk was never called. Our tests on the enforced callback revealed this bug. We can do a citgm run on this patch if it would help.

@isaacs
Copy link
Owner

isaacs commented Jul 26, 2016

Oh! I see, so if the chmod syscall raised EINVAL, ENOSYS, or EPERM, it'd fail, instead of silently being a no-op. Yeah, that's a bug, and I see how it would have been working by accident.

@isaacs isaacs merged commit 73a73fc into isaacs:master Jul 26, 2016
isaacs added a commit that referenced this pull request Jul 26, 2016
@isaacs
Copy link
Owner

isaacs commented Jul 26, 2016

Thanks! Landed with a test and published to 4.1.5.

@thefourtheye thefourtheye deleted the patch-1 branch July 26, 2016 19:10
thefourtheye added a commit to thefourtheye/npm that referenced this pull request Jul 27, 2016
graceful-fs had a bug fix, isaacs/node-graceful-fs#71,
which would fix the problem in Node.js nodejs/node#7846
iarna added a commit to npm/npm that referenced this pull request Aug 11, 2016
Fix bug in chmod wrapper that was tickled by recent node.js changes.
(nodejs/node#7846)

PR-URL: isaacs/node-graceful-fs#71
Credit: @thefourtheye
Reviewed-By: @isaacs
iarna pushed a commit to npm/npm that referenced this pull request Aug 11, 2016
graceful-fs had a bug fix, isaacs/node-graceful-fs#71,
which would fix the problem in Node.js nodejs/node#7846

PR-URL: #13497
Credit: @thefourtheye
Reviewed-By: @iarna
@zkat zkat mentioned this pull request Sep 22, 2016
4 tasks
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.

4 participants