Skip to content

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

Merged
phated merged 3 commits into
gulpjs:masterfrom
sleeuwen:master
Jul 6, 2016
Merged

Added support for changing uid/gid (fix #157)#188
phated merged 3 commits into
gulpjs:masterfrom
sleeuwen:master

Conversation

@sleeuwen

@sleeuwen sleeuwen commented Jul 5, 2016

Copy link
Copy Markdown
Contributor

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?

Comment thread lib/file-operations.js Outdated
}

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

Copy link
Copy Markdown
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

phated commented Jul 5, 2016

Copy link
Copy Markdown
Member

@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

sleeuwen commented Jul 6, 2016

Copy link
Copy Markdown
Contributor Author

@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.

Comment thread test/file-operations.js Outdated
};
var expected = {
uid: 1001,
gid: undefined,

Copy link
Copy Markdown
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

phated commented Jul 6, 2016

Copy link
Copy Markdown
Member

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

@sleeuwen

sleeuwen commented Jul 6, 2016

Copy link
Copy Markdown
Contributor Author

@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

phated commented Jul 6, 2016

Copy link
Copy Markdown
Member

@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

sleeuwen commented Jul 6, 2016

Copy link
Copy Markdown
Contributor Author

@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

phated commented Jul 6, 2016

Copy link
Copy Markdown
Member

Those errors should be bubbled up, I believe.

@sleeuwen

sleeuwen commented Jul 6, 2016

Copy link
Copy Markdown
Contributor Author

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

phated commented Jul 6, 2016

Copy link
Copy Markdown
Member

👍 I'm fine with that then

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

phated commented Jul 6, 2016

Copy link
Copy Markdown
Member

@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