Skip to content

Commit

Permalink
unix: squelch fchmod() EPERM on CIFS share
Browse files Browse the repository at this point in the history
uv_fs_copyfile() calls fchmod() to change the target file's permissions
to the source file's permissions but that operation errors with EPERM on
CIFS shares unless they are mounted with the "noperm" option.

Since UNIX-style permissions don't make sense for CIFS anyway, let's
handle the error in libuv by recognizing that it's a CIFS share and
continuing when that is the case.

The same logic probably applies to (a subset of) FUSE file systems but
those haven't been whitelisted yet.

Fixes: libuv#2596
Refs: nodejs/node#31170
  • Loading branch information
bnoordhuis committed Jan 5, 2020
1 parent 5cb8860 commit 6c0c9ce
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/unix/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,28 @@ static ssize_t uv__fs_copyfile(uv_fs_t* req) {

if (fchmod(dstfd, src_statsbuf.st_mode) == -1) {
err = UV__ERR(errno);
#ifdef __linux__
if (err != UV_EPERM)
goto out;

{
struct statfs s;

/* fchmod() on CIFS shares always fails with EPERM unless the share is
* mounted with "noperm". As fchmod() is a meaningless operation on such
* shares anyway, detect that condition and squelch the error.
*/
if (fstatfs(dstfd, &s) == -1)
goto out;

if (s.f_type != /* CIFS */ 0xFF534D42u)
goto out;
}

err = 0;
#else /* !__linux__ */
goto out;
#endif /* !__linux__ */
}

#ifdef FICLONE
Expand Down

0 comments on commit 6c0c9ce

Please sign in to comment.