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

Added support for changing uid/gid (fix #157) #188

Merged
merged 3 commits into from
Jul 6, 2016
Merged

Added support for changing uid/gid (fix #157) #188

merged 3 commits into from
Jul 6, 2016

Conversation

sleeuwen
Copy link
Contributor

@sleeuwen sleeuwen commented Jul 5, 2016

This PR adds support for changing the uid/gid of a file/directory.

Changing the uid/gid of a file is only possible as the root user and will fail silently if this run as a non root user.

What do you think we should do in this case?

@@ -66,6 +66,48 @@ function getTimesDiff(fsStat, vinylStat) {
return timesDiff;
}

function getOwnerDiff(fsStat, vinylStat) {
if (/^win/.test(process.platform)) {
Copy link
Member

Choose a reason for hiding this comment

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

there should be no reason to do this. In updateMetadata, we exit early on windows (it doesn't have process.getuid())

@phated
Copy link
Member

phated commented Jul 5, 2016

@stephanvl very nice work. I just had some suggestions and the appveyor CI is still failing. Let me know once you've had a chance to clean it up.

@sleeuwen
Copy link
Contributor Author

sleeuwen commented Jul 6, 2016

@phated I removed the latter 2 commits which added the windows specific code, added a isValidUnixId method to check the validity of the uid and gid and I added the return statement to fix the callback issue.

I also updated the owner method to expect one error instead of separate errors for the owner and times.

};
var expected = {
uid: 1001,
gid: undefined,
Copy link
Member

Choose a reason for hiding this comment

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

fs.fchown throws if uid or gid is undefined. Do we need to handle this by returning undefined if we don't have a complete diff?

@phated
Copy link
Member

phated commented Jul 6, 2016

@stephanvl this looks near perfect. Just 1 thing that I noticed while poking around in the node repl. Commented inline.

@sleeuwen
Copy link
Contributor Author

sleeuwen commented Jul 6, 2016

@phated Good catch, I will change it to return undefined when either uid or gid is undefined as there is no way of knowing what it should be at that point.

Then there is only the question what we should do about the fact that chown only works when the user is root (fail silently, throw an error or log a message and continue)?

@phated
Copy link
Member

phated commented Jul 6, 2016

@stephanvl we already handle that with our isOwner check inside the updateMetadata function. It checks the user owns the file or is effectively root.

@sleeuwen
Copy link
Contributor Author

sleeuwen commented Jul 6, 2016

@phated but you must be root for chown to work, being the owner of a file is not enough.

https://en.wikipedia.org/wiki/Chown

@phated
Copy link
Member

phated commented Jul 6, 2016

Those errors should be bubbled up, I believe.

@sleeuwen
Copy link
Contributor Author

sleeuwen commented Jul 6, 2016

graceful-fs gracefully ignores EPERM errors, which changing the owner as a non root user is

https://github.com/isaacs/node-graceful-fs/blob/master/polyfills.js#L245-L249

@phated
Copy link
Member

phated commented Jul 6, 2016

👍 I'm fine with that then

@phated phated merged commit 9fd1689 into gulpjs:master Jul 6, 2016
@phated
Copy link
Member

phated commented Jul 6, 2016

@stephanvl amazing work! Thanks a ton

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