Skip to content

Commit

Permalink
linux: fix ceph copy error truncating readonly files (#3920)
Browse files Browse the repository at this point in the history
Trying to copy a read-only file onto a ceph-fuse filesystem fails,
returning an `EACCES` error. This happens when the destination
doesn't exist yet, and a new file is created.

By checking that the error matches, and that the destination file
is empty, we can fix this issue while waiting for a proper Ceph
fix to be upstreamed.

Fixes: #3919
Refs: nodejs/node#37284
Refs: #3117
Refs: #3322
  • Loading branch information
Varstahl committed Mar 12, 2023
1 parent 9581e3d commit dfb206c
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/unix/fs.c
Expand Up @@ -1306,7 +1306,19 @@ static ssize_t uv__fs_copyfile(uv_fs_t* req) {
/* Truncate the file in case the destination already existed. */
if (ftruncate(dstfd, 0) != 0) {
err = UV__ERR(errno);
goto out;

/* ftruncate() on ceph-fuse fails with EACCES when the file is created
* with read only permissions. Since ftruncate() on a newly created
* file is a meaningless operation anyway, detect that condition
* and squelch the error.
*/
if (err != UV_EACCES)
goto out;

if (dst_statsbuf.st_size > 0)
goto out;

err = 0;
}
}

Expand Down

0 comments on commit dfb206c

Please sign in to comment.