| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3326,6 +3326,38 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo<Value>& args) { | |||
| 3326 | 3326 | } | |
| 3327 | 3327 | } | |
| 3328 | 3328 | ||
| 3329 | + static bool CopyUtimes(const std::filesystem::path& src, | ||
| 3330 | + const std::filesystem::path& dest, | ||
| 3331 | + Environment* env) { | ||
| 3332 | + uv_fs_t req; | ||
| 3333 | + auto cleanup = OnScopeLeave([&req]() { uv_fs_req_cleanup(&req); }); | ||
| 3334 | + | ||
| 3335 | + auto src_path_str = PathToString(src); | ||
| 3336 | + int result = uv_fs_stat(nullptr, &req, src_path_str.c_str(), nullptr); | ||
| 3337 | + if (is_uv_error(result)) { | ||
| 3338 | + env->ThrowUVException(result, "stat", nullptr, src_path_str.c_str()); | ||
| 3339 | + return false; | ||
| 3340 | + } | ||
| 3341 | + | ||
| 3342 | + const uv_stat_t* const s = static_cast<const uv_stat_t*>(req.ptr); | ||
| 3343 | + const double source_atime = s->st_atim.tv_sec + s->st_atim.tv_nsec / 1e9; | ||
| 3344 | + const double source_mtime = s->st_mtim.tv_sec + s->st_mtim.tv_nsec / 1e9; | ||
| 3345 | + | ||
| 3346 | + auto dest_file_path_str = PathToString(dest); | ||
| 3347 | + int utime_result = uv_fs_utime(nullptr, | ||
| 3348 | + &req, | ||
| 3349 | + dest_file_path_str.c_str(), | ||
| 3350 | + source_atime, | ||
| 3351 | + source_mtime, | ||
| 3352 | + nullptr); | ||
| 3353 | + if (is_uv_error(utime_result)) { | ||
| 3354 | + env->ThrowUVException( | ||
| 3355 | + utime_result, "utime", nullptr, dest_file_path_str.c_str()); | ||
| 3356 | + return false; | ||
| 3357 | + } | ||
| 3358 | + return true; | ||
| 3359 | + } | ||
| 3360 | + | ||
| 3329 | 3361 | static void CpSyncOverrideFile(const FunctionCallbackInfo<Value>& args) { | |
| 3330 | 3362 | Environment* env = Environment::GetCurrent(args); | |
| 3331 | 3363 | Isolate* isolate = env->isolate(); | |
@@ -3373,22 +3405,7 @@ static void CpSyncOverrideFile(const FunctionCallbackInfo<Value>& args) { | |||
| 3373 | 3405 | } | |
| 3374 | 3406 | ||
| 3375 | 3407 | if (preserve_timestamps) { | |
| 3376 | - uv_fs_t req; | ||
| 3377 | - auto cleanup = OnScopeLeave([&req]() { uv_fs_req_cleanup(&req); }); | ||
| 3378 | - int result = uv_fs_stat(nullptr, &req, *src, nullptr); | ||
| 3379 | - if (is_uv_error(result)) { | ||
| 3380 | - return env->ThrowUVException(result, "stat", nullptr, *src); | ||
| 3381 | - } | ||
| 3382 | - | ||
| 3383 | - const uv_stat_t* const s = static_cast<const uv_stat_t*>(req.ptr); | ||
| 3384 | - const double source_atime = s->st_atim.tv_sec + s->st_atim.tv_nsec / 1e9; | ||
| 3385 | - const double source_mtime = s->st_mtim.tv_sec + s->st_mtim.tv_nsec / 1e9; | ||
| 3386 | - | ||
| 3387 | - int utime_result = | ||
| 3388 | - uv_fs_utime(nullptr, &req, *dest, source_atime, source_mtime, nullptr); | ||
| 3389 | - if (is_uv_error(utime_result)) { | ||
| 3390 | - return env->ThrowUVException(utime_result, "utime", nullptr, *dest); | ||
| 3391 | - } | ||
| 3408 | + CopyUtimes(*src, *dest, env); | ||
| 3392 | 3409 | } | |
| 3393 | 3410 | } | |
| 3394 | 3411 | ||
@@ -3569,37 +3586,9 @@ static void CpSyncCopyDir(const FunctionCallbackInfo<Value>& args) { | |||
| 3569 | 3586 | return false; | |
| 3570 | 3587 | } | |
| 3571 | 3588 | ||
| 3572 | - if (preserve_timestamps) { | ||
| 3573 | - uv_fs_t req; | ||
| 3574 | - auto cleanup = OnScopeLeave([&req]() { uv_fs_req_cleanup(&req); }); | ||
| 3575 | - | ||
| 3576 | - auto dir_entry_path_str = PathToString(dir_entry.path()); | ||
| 3577 | - int result = | ||
| 3578 | - uv_fs_stat(nullptr, &req, dir_entry_path_str.c_str(), nullptr); | ||
| 3579 | - if (is_uv_error(result)) { | ||
| 3580 | - env->ThrowUVException( | ||
| 3581 | - result, "stat", nullptr, dir_entry_path_str.c_str()); | ||
| 3582 | - return false; | ||
| 3583 | - } | ||
| 3584 | - | ||
| 3585 | - const uv_stat_t* const s = static_cast<const uv_stat_t*>(req.ptr); | ||
| 3586 | - const double source_atime = | ||
| 3587 | - s->st_atim.tv_sec + s->st_atim.tv_nsec / 1e9; | ||
| 3588 | - const double source_mtime = | ||
| 3589 | - s->st_mtim.tv_sec + s->st_mtim.tv_nsec / 1e9; | ||
| 3590 | - | ||
| 3591 | - auto dest_file_path_str = PathToString(dest_file_path); | ||
| 3592 | - int utime_result = uv_fs_utime(nullptr, | ||
| 3593 | - &req, | ||
| 3594 | - dest_file_path_str.c_str(), | ||
| 3595 | - source_atime, | ||
| 3596 | - source_mtime, | ||
| 3597 | - nullptr); | ||
| 3598 | - if (is_uv_error(utime_result)) { | ||
| 3599 | - env->ThrowUVException( | ||
| 3600 | - utime_result, "utime", nullptr, dest_file_path_str.c_str()); | ||
| 3601 | - return false; | ||
| 3602 | - } | ||
| 3589 | + if (preserve_timestamps && | ||
| 3590 | + !CopyUtimes(dir_entry.path(), dest_file_path, env)) { | ||
| 3591 | + return false; | ||
| 3603 | 3592 | } | |
| 3604 | 3593 | } | |
| 3605 | 3594 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments