isaacs/node-graceful-fs — Issue #4: EINVAL should not be a fatal error when chown-ing
Author: alanshields
Created: 2011-12-07 06:59:08+00:00
State: open

Per https://github.com/isaacs/npm/issues/1570

The problem is that some files cannot be chowned, even if you're root. The pertinent example here would be a squashed NFS mount - try as you will, you can't change the owner.

This will result in EINVAL. Here's me attempting to chown a squashed NFS-mounted file:

fchownat(AT_FDCWD, "resources.dot", 1000, 1000, 0) = -1 EINVAL (Invalid argument)

Here's the source for cp dealing with the same:

```
if (x->preserve_ownership)
{
if (lchown (dst_name, p->st.st_uid, p->st.st_gid) != 0)
{
if (! chown_failure_ok (x))
{
error (0, errno, _("failed to preserve ownership for %s"),
quote (dst_name));
return false;
}
/* Failing to preserve ownership is OK. Still, try to preserve
the group, but ignore the possible error. */
ignore_value (lchown (dst_name, -1, p->st.st_gid));
}
}
```

Specifically:

```
chown_failure_ok (struct cp_options const *x)
{
/* If non-root uses -p, it's ok if we can't preserve ownership.
But root probably wants to know, e.g. if NFS disallows it,
or if the target system doesn't support file ownership. */

return ((errno == EPERM || errno == EINVAL) && !x->chown_privileges);
}
```

Steps to reproduce: export a directory with at least these options: all_squash,anonuid=1000,anongid=1000

Mount the directory and attempt to install a package into that directory.