| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 20d3a80 commit 79ffefa
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3035,22 +3035,24 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo<Value>& args) { | |||
| 3035 | 3035 | ToNamespacedPath(env, &src); | |
| 3036 | 3036 | THROW_IF_INSUFFICIENT_PERMISSIONS( | |
| 3037 | 3037 | env, permission::PermissionScope::kFileSystemRead, src.ToStringView()); | |
| 3038 | - auto src_path = std::filesystem::path(src.ToStringView()); | ||
| 3038 | + | ||
| 3039 | + auto src_path = std::filesystem::path(src.ToU8StringView()); | ||
| 3039 | 3040 | ||
| 3040 | 3041 | BufferValue dest(isolate, args[1]); | |
| 3041 | 3042 | CHECK_NOT_NULL(*dest); | |
| 3042 | 3043 | ToNamespacedPath(env, &dest); | |
| 3043 | 3044 | THROW_IF_INSUFFICIENT_PERMISSIONS( | |
| 3044 | 3045 | env, permission::PermissionScope::kFileSystemWrite, dest.ToStringView()); | |
| 3045 | - auto dest_path = std::filesystem::path(dest.ToStringView()); | ||
| 3046 | 3046 | ||
| 3047 | + auto dest_path = std::filesystem::path(dest.ToU8StringView()); | ||
| 3047 | 3048 | bool dereference = args[2]->IsTrue(); | |
| 3048 | 3049 | bool recursive = args[3]->IsTrue(); | |
| 3049 | 3050 | ||
| 3050 | 3051 | std::error_code error_code; | |
| 3051 | 3052 | auto src_status = dereference | |
| 3052 | 3053 | ? std::filesystem::symlink_status(src_path, error_code) | |
| 3053 | 3054 | : std::filesystem::status(src_path, error_code); | |
| 3055 | + | ||
| 3054 | 3056 | if (error_code) { | |
| 3055 | 3057 | #ifdef _WIN32 | |
| 3056 | 3058 | int errorno = uv_translate_sys_error(error_code.value()); | |
@@ -3074,34 +3076,41 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo<Value>& args) { | |||
| 3074 | 3076 | if (!error_code) { | |
| 3075 | 3077 | // Check if src and dest are identical. | |
| 3076 | 3078 | if (std::filesystem::equivalent(src_path, dest_path)) { | |
| 3077 | - std::string message = | ||
| 3078 | - "src and dest cannot be the same " + dest_path.string(); | ||
| 3079 | - return THROW_ERR_FS_CP_EINVAL(env, message.c_str()); | ||
| 3079 | + std::u8string message = | ||
| 3080 | + u8"src and dest cannot be the same " + dest_path.u8string(); | ||
| 3081 | + return THROW_ERR_FS_CP_EINVAL( | ||
| 3082 | + env, reinterpret_cast<const char*>(message.c_str())); | ||
| 3080 | 3083 | } | |
| 3081 | 3084 | ||
| 3082 | 3085 | const bool dest_is_dir = | |
| 3083 | 3086 | dest_status.type() == std::filesystem::file_type::directory; | |
| 3084 | 3087 | ||
| 3085 | 3088 | if (src_is_dir && !dest_is_dir) { | |
| 3086 | - std::string message = "Cannot overwrite non-directory " + | ||
| 3087 | - src_path.string() + " with directory " + | ||
| 3088 | - dest_path.string(); | ||
| 3089 | - return THROW_ERR_FS_CP_DIR_TO_NON_DIR(env, message.c_str()); | ||
| 3089 | + std::u8string message = u8"Cannot overwrite non-directory " + | ||
| 3090 | + src_path.u8string() + u8" with directory " + | ||
| 3091 | + dest_path.u8string(); | ||
| 3092 | + return THROW_ERR_FS_CP_DIR_TO_NON_DIR( | ||
| 3093 | + env, reinterpret_cast<const char*>(message.c_str())); | ||
| 3090 | 3094 | } | |
| 3091 | 3095 | ||
| 3092 | 3096 | if (!src_is_dir && dest_is_dir) { | |
| 3093 | - std::string message = "Cannot overwrite directory " + dest_path.string() + | ||
| 3094 | - " with non-directory " + src_path.string(); | ||
| 3095 | - return THROW_ERR_FS_CP_NON_DIR_TO_DIR(env, message.c_str()); | ||
| 3097 | + std::u8string message = u8"Cannot overwrite directory " + | ||
| 3098 | + dest_path.u8string() + u8" with non-directory " + | ||
| 3099 | + src_path.u8string(); | ||
| 3100 | + return THROW_ERR_FS_CP_NON_DIR_TO_DIR( | ||
| 3101 | + env, reinterpret_cast<const char*>(message.c_str())); | ||
| 3096 | 3102 | } | |
| 3097 | 3103 | } | |
| 3098 | 3104 | ||
| 3099 | - std::string dest_path_str = dest_path.string(); | ||
| 3105 | + std::u8string dest_path_str = dest_path.u8string(); | ||
| 3106 | + | ||
| 3100 | 3107 | // Check if dest_path is a subdirectory of src_path. | |
| 3101 | - if (src_is_dir && dest_path_str.starts_with(src_path.string())) { | ||
| 3102 | - std::string message = "Cannot copy " + src_path.string() + | ||
| 3103 | - " to a subdirectory of self " + dest_path.string(); | ||
| 3104 | - return THROW_ERR_FS_CP_EINVAL(env, message.c_str()); | ||
| 3108 | + if (src_is_dir && dest_path_str.starts_with(src_path.u8string())) { | ||
| 3109 | + std::u8string message = u8"Cannot copy " + src_path.u8string() + | ||
| 3110 | + u8" to a subdirectory of self " + | ||
| 3111 | + dest_path.u8string(); | ||
| 3112 | + return THROW_ERR_FS_CP_EINVAL( | ||
| 3113 | + env, reinterpret_cast<const char*>(message.c_str())); | ||
| 3105 | 3114 | } | |
| 3106 | 3115 | ||
| 3107 | 3116 | auto dest_parent = dest_path.parent_path(); | |
@@ -3112,9 +3121,11 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo<Value>& args) { | |||
| 3112 | 3121 | dest_parent.parent_path() != dest_parent) { | |
| 3113 | 3122 | if (std::filesystem::equivalent( | |
| 3114 | 3123 | src_path, dest_path.parent_path(), error_code)) { | |
| 3115 | - std::string message = "Cannot copy " + src_path.string() + | ||
| 3116 | - " to a subdirectory of self " + dest_path.string(); | ||
| 3117 | - return THROW_ERR_FS_CP_EINVAL(env, message.c_str()); | ||
| 3124 | + std::u8string message = u8"Cannot copy " + src_path.u8string() + | ||
| 3125 | + u8" to a subdirectory of self " + | ||
| 3126 | + dest_path.u8string(); | ||
| 3127 | + return THROW_ERR_FS_CP_EINVAL( | ||
| 3128 | + env, reinterpret_cast<const char*>(message.c_str())); | ||
| 3118 | 3129 | } | |
| 3119 | 3130 | ||
| 3120 | 3131 | // If equivalent fails, it's highly likely that dest_parent does not exist | |
@@ -3126,25 +3137,29 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo<Value>& args) { | |||
| 3126 | 3137 | } | |
| 3127 | 3138 | ||
| 3128 | 3139 | if (src_is_dir && !recursive) { | |
| 3129 | - std::string message = | ||
| 3130 | - "Recursive option not enabled, cannot copy a directory: " + | ||
| 3131 | - src_path.string(); | ||
| 3132 | - return THROW_ERR_FS_EISDIR(env, message.c_str()); | ||
| 3140 | + std::u8string message = | ||
| 3141 | + u8"Recursive option not enabled, cannot copy a directory: " + | ||
| 3142 | + src_path.u8string(); | ||
| 3143 | + return THROW_ERR_FS_EISDIR(env, | ||
| 3144 | + reinterpret_cast<const char*>(message.c_str())); | ||
| 3133 | 3145 | } | |
| 3134 | 3146 | ||
| 3135 | 3147 | switch (src_status.type()) { | |
| 3136 | 3148 | case std::filesystem::file_type::socket: { | |
| 3137 | - std::string message = "Cannot copy a socket file: " + dest_path.string(); | ||
| 3138 | - return THROW_ERR_FS_CP_SOCKET(env, message.c_str()); | ||
| 3149 | + std::u8string message = u8"Cannot copy a socket file: " + dest_path_str; | ||
| 3150 | + return THROW_ERR_FS_CP_SOCKET( | ||
| 3151 | + env, reinterpret_cast<const char*>(message.c_str())); | ||
| 3139 | 3152 | } | |
| 3140 | 3153 | case std::filesystem::file_type::fifo: { | |
| 3141 | - std::string message = "Cannot copy a FIFO pipe: " + dest_path.string(); | ||
| 3142 | - return THROW_ERR_FS_CP_FIFO_PIPE(env, message.c_str()); | ||
| 3154 | + std::u8string message = u8"Cannot copy a FIFO pipe: " + dest_path_str; | ||
| 3155 | + return THROW_ERR_FS_CP_FIFO_PIPE( | ||
| 3156 | + env, reinterpret_cast<const char*>(message.c_str())); | ||
| 3143 | 3157 | } | |
| 3144 | 3158 | case std::filesystem::file_type::unknown: { | |
| 3145 | - std::string message = | ||
| 3146 | - "Cannot copy an unknown file type: " + dest_path.string(); | ||
| 3147 | - return THROW_ERR_FS_CP_UNKNOWN(env, message.c_str()); | ||
| 3159 | + std::u8string message = | ||
| 3160 | + u8"Cannot copy an unknown file type: " + dest_path_str; | ||
| 3161 | + return THROW_ERR_FS_CP_UNKNOWN( | ||
| 3162 | + env, reinterpret_cast<const char*>(message.c_str())); | ||
| 3148 | 3163 | } | |
| 3149 | 3164 | default: | |
| 3150 | 3165 | break; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -562,6 +562,10 @@ class BufferValue : public MaybeStackBuffer<char> { | |||
| 562 | 562 | inline std::string_view ToStringView() const { | |
| 563 | 563 | return std::string_view(out(), length()); | |
| 564 | 564 | } | |
| 565 | + inline std::u8string_view ToU8StringView() const { | ||
| 566 | + return std::u8string_view(reinterpret_cast<const char8_t*>(out()), | ||
| 567 | + length()); | ||
| 568 | + } | ||
| 565 | 569 | }; | |
| 566 | 570 | ||
| 567 | 571 | #define SPREAD_BUFFER_ARG(val, name) \ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,3 @@ | |||
| 1 | + module.exports = { | ||
| 2 | + purpose: 'testing copy' | ||
| 3 | + }; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,6 +30,14 @@ function nextdir() { | |||
| 30 | 30 | ||
| 31 | 31 | // Synchronous implementation of copy. | |
| 32 | 32 | ||
| 33 | + // It copies a nested folder containing UTF characters. | ||
| 34 | + { | ||
| 35 | + const src = './test/fixtures/copy/utf/新建文件夹'; | ||
| 36 | + const dest = nextdir(); | ||
| 37 | + cpSync(src, dest, mustNotMutateObjectDeep({ recursive: true })); | ||
| 38 | + assertDirEquivalent(src, dest); | ||
| 39 | + } | ||
| 40 | + | ||
| 33 | 41 | // It copies a nested folder structure with files and folders. | |
| 34 | 42 | { | |
| 35 | 43 | const src = './test/fixtures/copy/kitchen-sink'; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments