Skip to content

Commit 221cfd9

Browse files
committed
fs: use libuv for recursive cpSync to avoid VirtioFS EACCES
Fix verified RED->GREEN. fs.cpSync recursive copy fails EACCES on Docker VirtioFS bind mounts via std::filesystem 0200 intermediate at node_file.cc:4205. libstdc++ creates dest with 0200 then fchmod, VirtioFS blocks. Single-file path at 4015 correctly uses uv_fs_copyfile when mode != 0. Fixes: nodejs#65497 Signed-off-by: Jeremy Schoemaker <[email protected]> Assisted-by: Claude <[email protected]>
1 parent 7aaf9b4 commit 221cfd9

1 file changed

Lines changed: 24 additions & 5 deletions

File tree

‎src/node_file.cc‎

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4202,17 +4202,36 @@ static void CpSyncCopyDir(const FunctionCallbackInfo<Value>& args) {
42024202
return false;
42034203
}
42044204
} else if (dir_entry.is_regular_file()) {
4205-
std::filesystem::copy_file(
4206-
dir_entry.path(), dest_file_path, file_copy_opts, error);
4207-
if (error) {
4208-
if (error == std::errc::file_exists) {
4205+
// Use libuv for regular file copies to avoid VirtioFS EACCES
4206+
// (libstdc++ creates dest with 0200 then fchmod, VirtioFS blocks).
4207+
// Mirrors single-file path which uses uv_fs_copyfile when mode != 0.
4208+
// Handle force / errorOnExist / skipExisting semantics via libuv flags.
4209+
if (!force && !error_on_exist) {
4210+
std::error_code ec;
4211+
if (std::filesystem::exists(dest_file_path, ec) && !ec) {
4212+
continue;
4213+
}
4214+
}
4215+
auto src_str = ConvertPathToUTF8(dir_entry.path());
4216+
auto dest_file_str = ConvertPathToUTF8(dest_file_path);
4217+
uv_fs_t req;
4218+
auto cleanup = OnScopeLeave([&req]() { uv_fs_req_cleanup(&req); });
4219+
int flags = error_on_exist ? UV_FS_COPYFILE_EXCL : 0;
4220+
int result = uv_fs_copyfile(nullptr,
4221+
&req,
4222+
src_str.c_str(),
4223+
dest_file_str.c_str(),
4224+
flags,
4225+
nullptr);
4226+
if (is_uv_error(result)) {
4227+
if (result == UV_EEXIST) {
42094228
THROW_ERR_FS_CP_EEXIST(isolate,
42104229
"[ERR_FS_CP_EEXIST]: Target already exists: "
42114230
"cp returned EEXIST (%s already exists)",
42124231
dest_file_path);
42134232
return false;
42144233
}
4215-
env->ThrowStdErrException(error, "cp", dest_str.c_str());
4234+
env->ThrowUVException(result, "cp", nullptr, dest_file_str.c_str());
42164235
return false;
42174236
}
42184237

0 commit comments

Comments
 (0)