Skip to content

Commit

Permalink
add some debug print to navigate segfault
Browse files Browse the repository at this point in the history
  • Loading branch information
jazelly committed Sep 11, 2024
1 parent daf67fe commit 1669d2a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
10 changes: 10 additions & 0 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3130,12 +3130,18 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo<Value>& args) {
ToNamespacedPath(env, &src);
THROW_IF_INSUFFICIENT_PERMISSIONS(
env, permission::PermissionScope::kFileSystemRead, src.ToStringView());

#ifdef _WIN32
auto src_path = std::filesystem::path(src.ToU8StringView());
#else
auto src_path = std::filesystem::path(src.ToStringView());
#endif

std::cout << src.ToStringView() << std::endl;
// auto a = std::filesystem::path(src.ToStringView());
// std::cout << "A.string: " + a.string() << std::endl;


BufferValue dest(isolate, args[1]);
CHECK_NOT_NULL(*dest);
ToNamespacedPath(env, &dest);
Expand Down Expand Up @@ -3166,7 +3172,9 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo<Value>& args) {
(src_status.type() == std::filesystem::file_type::directory) ||
(dereference && src_status.type() == std::filesystem::file_type::symlink);

std::cout << "before innfer " + error_code.message() << std::endl;
if (!error_code) {
std::cout << "inner " + error_code.message() << std::endl;
// Check if src and dest are identical.
if (std::filesystem::equivalent(src_path, dest_path)) {
std::string message =
Expand Down Expand Up @@ -3247,6 +3255,8 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo<Value>& args) {

// Optimization opportunity: Check if this "exists" call is good for
// performance.
std::cout << error_code << std::endl;
std::cout << dest_path.parent_path() << std::endl;
if (!dest_exists || !std::filesystem::exists(dest_path.parent_path())) {
std::filesystem::create_directories(dest_path.parent_path(), error_code);
}
Expand Down
12 changes: 6 additions & 6 deletions test/parallel/test-fs-cp.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ function nextdir() {
// Synchronous implementation of copy.

// It copies a nested folder containing UTF characters.
// {
// const src = './test/fixtures/copy/utf/新建文件';
// const dest = nextdir();
// cpSync(src, dest, mustNotMutateObjectDeep({ recursive: true }));
// assertDirEquivalent(src, dest);
// }
{
const src = './test/fixtures/copy/utf/新建文件夹';
const dest = nextdir();
cpSync(src, dest, mustNotMutateObjectDeep({ recursive: true }));
assertDirEquivalent(src, dest);
}

// It copies a nested folder structure with files and folders.
{
Expand Down

0 comments on commit 1669d2a

Please sign in to comment.