Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3147,7 +3147,14 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo<Value>& args) {
? std::filesystem::symlink_status(src_path, error_code)
: std::filesystem::status(src_path, error_code);
if (error_code) {
return env->ThrowUVException(EEXIST, "lstat", nullptr, src.out());
#ifdef _WIN32
int errorno = uv_translate_sys_error(error_code.value());
#else
int errorno =
error_code.value() > 0 ? -error_code.value() : error_code.value();
#endif
return env->ThrowUVException(
errorno, dereference ? "stat" : "lstat", nullptr, src.out());
}
auto dest_status =
dereference ? std::filesystem::symlink_status(dest_path, error_code)
Expand Down
20 changes: 20 additions & 0 deletions test/parallel/test-fs-cp.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,26 @@ if (!isWindows) {
);
}

// It throws an error when attempting to copy a file with a name that is too long.
{
const src = 'a'.repeat(5000);
const dest = nextdir();
assert.throws(
() => cpSync(src, dest),
{ code: isWindows ? 'ENOENT' : 'ENAMETOOLONG' }
);
}

// It throws an error when attempting to copy a dir that does not exist.
{
const src = nextdir();
const dest = nextdir();
assert.throws(
() => cpSync(src, dest, mustNotMutateObjectDeep({ recursive: true })),
{ code: 'ENOENT' }
);
}

// It makes file writeable when updating timestamp, if not writeable.
{
const src = nextdir();
Expand Down
Loading