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

Support setting setuid/setgid/sticky in updateMetadata and adapt tests #162

Merged
merged 1 commit into from Apr 25, 2016
Merged

Support setting setuid/setgid/sticky in updateMetadata and adapt tests #162

merged 1 commit into from Apr 25, 2016

Conversation

tmcgee123
Copy link
Contributor

@tmcgee123 tmcgee123 commented Apr 20, 2016

Ref #156

Let me know if you need me to get rid of the merge commit, I can open a new branch and apply the changes there if need be.

Thanks everyone for the help!!

  • write tests to set special bits for files
  • write tests to set special bits for directories
  • fix test discrepancy of file mode on CI vs. local

@phated
Copy link
Member

phated commented Apr 20, 2016

@erikkemperman wouldn't there need to be tests added for those actually getting set on the files created?

@phated
Copy link
Member

phated commented Apr 20, 2016

This is failing on appveyor (windows)

@erikkemperman
Copy link
Member

Yes, maybe I should've mentioned that in the pr to @tmcgee123 's fork -- it was just quicker to fix the extant tests that now failed than describing it in words.

I don't have a Windows box, and am not familiar with appveyor, can we see those errors online somewhere?

@tmcgee123
Copy link
Contributor Author

If you post which tests are failing I could run these on a Windows box (I have Windows 7 and 10) and debug them. I can't seem to find the stacktrace or error log either on AppVeyor 😿

@erikkemperman
Copy link
Member

erikkemperman commented Apr 21, 2016

@tmcgee123 I found them, here. Seems like the mobile version of GH doesn't link these clearly.

getModeDiff now always returns 0 on Windows, which it didn't before, and this now fails since this is a general purpose function which is tested even on Windows.

Looking at your patch more closely (I just checked the failing tests yesterday) I am wondering why it would need to be anything more than simply changing the mask to 7777? The isOwner call will still return false on Windows so it won't attempt to chmod, with or without setuid/setgid/sticky bits.

Am I missing something obvious?

@tmcgee123
Copy link
Contributor Author

@erikkemperman I found the broken tests, sorry I didn't know I needed to click on the node environments it was running in (derp).

In regards to the other changes than the mask, I made them because of the inner functionality of updateMetaData (the inner onStat):

I was trying to return correctly here, since Windows doesn't have file modes.

   if (!modeDiff && !timesDiff) {
      return callback(null, fd);
    }

I was also concerned that if for some reason if the timesDiff was true and made it to this point, that mode would be invoked and didn't know if that would effect anything else.

    if (modeDiff) {
      return mode();
    }

@erikkemperman
Copy link
Member

I think mode() will never be invoked if isOwner() returns false, which it does on Windows. So that would be all right, it seems to me, without any further guards.

@tmcgee123
Copy link
Contributor Author

tmcgee123 commented Apr 21, 2016

Gotcha, reverted my commits and squashed everything, hopefully the build passes this time!

@tmcgee123
Copy link
Contributor Author

After looking back at the code, if what you are saying is true can we combine the conditionals? For example:

    if (!modeDiff && !timesDiff) {
      return callback(null, fd);
    }

    // Check access, `futimes` and `fchmod` only work if we own the file,
    // or if we are effectively root.
    if (!isOwner(stat)) {
      return callback(null, fd);
    }

to this:

    /* Nothing to do.
       Check access, `futimes` and `fchmod` only work if we own the file,
       or if we are effectively root.
    */ 
    if ((!modeDiff && !timesDiff) || !isOwner(stat)) {
      return callback(null, fd);
    }

@erikkemperman
Copy link
Member

Yay, getting there! All tests pass!

Now, as @phated mentioned, tests ought to be added that actually set these special bits, both for files and directories...

@erikkemperman
Copy link
Member

That would be functionally identical but, imho, less legible.

@tmcgee123
Copy link
Contributor Author

tmcgee123 commented Apr 21, 2016

@erikkemperman that makes sense. I've went ahead and added tests to the destModes to cover the areas you've said (I went ahead an added on to fileOperations test as well).

So, there's something interesting happening with the tests that I need help with. On the CI, the tests pass. But locally (Mac OS X 10.11.1) the test fails with. Quite strange actually, if you look at the failed build: https://travis-ci.org/gulpjs/vinyl-fs/builds/124775406 and then compare to what you are seeing locally with the update test, their results are flopped.

Sorry to take so much time with this small change, but I am very glad this repo enforces TDD standards. Thanks for the help!

@erikkemperman
Copy link
Member

@tmcgee123 Sorry, I don't have the time for this that it deserves... Still buried in a project at work.

But just a guess: OS-specific differences could be due to mkdirp (which is used to create directories) using process.umask, see here.

Not sure if we should adapt the tests and/or fileOperations.js itself to account for this, though, if that is in fact the issue here.

@phated
Copy link
Member

phated commented Apr 21, 2016

It looks like both platforms are passing with that last commit. I'm not sure when I'll have a chance to review. Hopefully tomorrow but it might be next week. Thanks for the work on this.

@erikkemperman
Copy link
Member

Yes, but now it fails npm test on macosx :-(

@tmcgee123
Copy link
Contributor Author

I can look into this more today and tomorrow. I was able to figure out the "Linux" file mode by using http://permissions-calculator.org/decode/ which is why the test is passing on CI now and not locally. I think @erikkemperman is on the right track with the umask.

In terms of accounting for this in fileOperations.js, if the modes that are being set are invalid then I would say we should definitely account for this. Either way, I think it would be smart to have a unit test for this either way to show that directories get assigned a different file mode for Mac vs Linux.

@tmcgee123
Copy link
Contributor Author

@erikkemperman do you think this could be the cause of what we are seeing? https://github.com/substack/node-mkdirp/issues/80

@erikkemperman
Copy link
Member

Could be, it seems that issue is about new directories vs calling mkdirp on existing directories. It looks like @contra would like mkdirp to just do a chmod in the latter case?

Just had a casual glance at it though, I might be way off... Busy busy busy, sorry about that.

@phated
Copy link
Member

phated commented Apr 22, 2016

It looks like we don't handle that correctly anyway? Maybe we should write a test for it and skip it with a comment saying that it doesn't work for directories that already exist and point at that issue? I haven't run this locally to test yet.

@tmcgee123
Copy link
Contributor Author

I wrote a simple catch like there was for Windows to see if it was Darwin. Let me know if this is acceptable for the time being or if you'd like me to add anything else.

Thanks!

@erikkemperman
Copy link
Member

I am now thinking it's not even an OS issue, per se. They might have different defaults for umask but users or admins can override it.

So my feeling now is that vinyl-fs should account for it much like mkdirp does. That would mean a more fundamental change than the scope of this issue/pr though...

https://en.m.wikipedia.org/wiki/Umask

About the issue in the mkdirp repo, contra's suggestion makes sense to me. There's been no response though, maybe it would help if there was a concrete PR for it.

@phated
Copy link
Member

phated commented Apr 24, 2016

@erikkemperman the node.js platform's builtin methods already account for umask, so I don't think we need to.

@erikkemperman
Copy link
Member

@phated Yes but the tests seem to be assuming the umask to be 022 (or a submask of that like 002), which is apparently the usual default but users/admins might have changed that. See the literals 755 and 655 in the mode tests, which conveniently pre-exclude the default umask.

But if the umask includes any of the other bits, the tests will fail:

$ umask
0022
$ npm test
[pass]
$ umask 0033
$ umask
0033
$ npm test
[FAIL]
$ umask 0022 # don't forget to restore to whatever the first one returned

@erikkemperman
Copy link
Member

erikkemperman commented Apr 24, 2016

And also, if the effective umask restricts what folks pass into dest when writing to disk, should the vinyl object not reflect this?

EDIT Sorry, never mind, the above is already handled correctly since updateMetadata always updates file.stat to reflect the attributes on disk. (Should've known, I think I introduced this myself at one point during the earlier metadata efforts :-))

The question about literals in the tests stands, though.

Adapt tests to support for setuid/setgid/sticky bits
Relates to #156
@phated
Copy link
Member

phated commented Apr 25, 2016

@erikkemperman I think process.umask and some weirdness around mkdir modes on OSX are out of scope for this PR/issue combination. I'll open some other issues.

@phated
Copy link
Member

phated commented Apr 25, 2016

I'm happy where this is at. Merging.

@phated phated merged commit 3f9b9c1 into gulpjs:master Apr 25, 2016
@phated
Copy link
Member

phated commented Apr 25, 2016

@tmcgee123 thanks for this!

@tmcgee123
Copy link
Contributor Author

@phated glad to help! Sorry for the delayed response, work has been busy the last week. Hopefully I'll have time to contribute some more, cheers! 🍻

phated pushed a commit that referenced this pull request Nov 27, 2017
Adapt tests to support for setuid/setgid/sticky bits
Relates to #156
phated pushed a commit that referenced this pull request Nov 27, 2017
Adapt tests to support for setuid/setgid/sticky bits
Relates to #156
phated pushed a commit that referenced this pull request Nov 27, 2017
Adapt tests to support for setuid/setgid/sticky bits
Relates to #156
phated pushed a commit that referenced this pull request Nov 27, 2017
Adapt tests to support for setuid/setgid/sticky bits
Relates to #156
phated pushed a commit that referenced this pull request Nov 27, 2017
Adapt tests to support for setuid/setgid/sticky bits
Relates to #156
phated pushed a commit that referenced this pull request Nov 27, 2017
Adapt tests to support for setuid/setgid/sticky bits
Relates to #156
phated pushed a commit that referenced this pull request Nov 28, 2017
Adapt tests to support for setuid/setgid/sticky bits
Relates to #156
phated pushed a commit that referenced this pull request Nov 28, 2017
Adapt tests to support for setuid/setgid/sticky bits
Relates to #156
phated pushed a commit that referenced this pull request Nov 28, 2017
Adapt tests to support for setuid/setgid/sticky bits
Relates to #156
phated pushed a commit that referenced this pull request Nov 28, 2017
Adapt tests to support for setuid/setgid/sticky bits
Relates to #156
phated pushed a commit that referenced this pull request Nov 28, 2017
Adapt tests to support for setuid/setgid/sticky bits
Relates to #156
phated pushed a commit that referenced this pull request Nov 28, 2017
Adapt tests to support for setuid/setgid/sticky bits
Relates to #156
phated pushed a commit that referenced this pull request Nov 28, 2017
Adapt tests to support for setuid/setgid/sticky bits
Relates to #156
phated pushed a commit that referenced this pull request Nov 28, 2017
Adapt tests to support for setuid/setgid/sticky bits
Relates to #156
phated pushed a commit that referenced this pull request Nov 28, 2017
Adapt tests to support for setuid/setgid/sticky bits
Relates to #156
phated pushed a commit that referenced this pull request Nov 28, 2017
Adapt tests to support for setuid/setgid/sticky bits
Relates to #156
phated pushed a commit that referenced this pull request Nov 28, 2017
Adapt tests to support for setuid/setgid/sticky bits
Relates to #156
phated pushed a commit that referenced this pull request Nov 28, 2017
Adapt tests to support for setuid/setgid/sticky bits
Relates to #156
phated pushed a commit that referenced this pull request Nov 28, 2017
Adapt tests to support for setuid/setgid/sticky bits
Relates to #156
phated pushed a commit that referenced this pull request Nov 28, 2017
Adapt tests to support for setuid/setgid/sticky bits
Relates to #156
phated pushed a commit that referenced this pull request Nov 28, 2017
Adapt tests to support for setuid/setgid/sticky bits
Relates to #156
phated pushed a commit that referenced this pull request Nov 28, 2017
Adapt tests to support for setuid/setgid/sticky bits
Relates to #156
phated pushed a commit that referenced this pull request Nov 28, 2017
Adapt tests to support for setuid/setgid/sticky bits
Relates to #156
phated pushed a commit that referenced this pull request Nov 28, 2017
Adapt tests to support for setuid/setgid/sticky bits
Relates to #156
phated pushed a commit that referenced this pull request Nov 28, 2017
Adapt tests to support for setuid/setgid/sticky bits
Relates to #156
phated pushed a commit that referenced this pull request Nov 30, 2017
Adapt tests to support for setuid/setgid/sticky bits
Relates to #156
phated pushed a commit that referenced this pull request Nov 30, 2017
Adapt tests to support for setuid/setgid/sticky bits
Relates to #156
phated pushed a commit that referenced this pull request Nov 30, 2017
Adapt tests to support for setuid/setgid/sticky bits
Relates to #156
phated pushed a commit that referenced this pull request Nov 30, 2017
Adapt tests to support for setuid/setgid/sticky bits
Relates to #156
phated pushed a commit that referenced this pull request Dec 5, 2017
Adapt tests to support for setuid/setgid/sticky bits
Relates to #156
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.

None yet

3 participants