| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,6 +6,7 @@ | |||
| 6 | 6 | #include "node_internals.h" | |
| 7 | 7 | #include "node_version.h" | |
| 8 | 8 | #include "path.h" | |
| 9 | + #include "util.h" | ||
| 9 | 10 | #include "zlib.h" | |
| 10 | 11 | ||
| 11 | 12 | #ifdef NODE_IMPLEMENTS_POSIX_CREDENTIALS | |
@@ -225,14 +226,11 @@ CompileCacheEntry* CompileCacheHandler::GetOrInsert( | |||
| 225 | 226 | compiler_cache_store_.emplace(key, std::make_unique<CompileCacheEntry>()); | |
| 226 | 227 | auto* result = emplaced.first->second.get(); | |
| 227 | 228 | ||
| 228 | - std::u8string cache_filename_u8 = | ||
| 229 | - (compile_cache_dir_ / Uint32ToHex(key)).u8string(); | ||
| 230 | 229 | result->code_hash = code_hash; | |
| 231 | 230 | result->code_size = code_utf8.length(); | |
| 232 | 231 | result->cache_key = key; | |
| 233 | 232 | result->cache_filename = | |
| 234 | - std::string(cache_filename_u8.begin(), cache_filename_u8.end()) + | ||
| 235 | - ".cache"; | ||
| 233 | + compile_cache_dir_ + kPathSeparator + Uint32ToHex(key); | ||
| 236 | 234 | result->source_filename = filename_utf8.ToString(); | |
| 237 | 235 | result->cache = nullptr; | |
| 238 | 236 | result->type = type; | |
@@ -452,43 +450,40 @@ CompileCacheEnableResult CompileCacheHandler::Enable(Environment* env, | |||
| 452 | 450 | const std::string& dir) { | |
| 453 | 451 | std::string cache_tag = GetCacheVersionTag(); | |
| 454 | 452 | std::string absolute_cache_dir_base = PathResolve(env, {dir}); | |
| 455 | - std::filesystem::path cache_dir_with_tag = | ||
| 456 | - std::filesystem::path(absolute_cache_dir_base) / cache_tag; | ||
| 457 | - std::u8string cache_dir_with_tag_u8 = cache_dir_with_tag.u8string(); | ||
| 458 | - std::string cache_dir_with_tag_str(cache_dir_with_tag_u8.begin(), | ||
| 459 | - cache_dir_with_tag_u8.end()); | ||
| 453 | + std::string cache_dir_with_tag = | ||
| 454 | + absolute_cache_dir_base + kPathSeparator + cache_tag; | ||
| 460 | 455 | CompileCacheEnableResult result; | |
| 461 | 456 | Debug("[compile cache] resolved path %s + %s -> %s\n", | |
| 462 | 457 | dir, | |
| 463 | 458 | cache_tag, | |
| 464 | - cache_dir_with_tag_str); | ||
| 459 | + cache_dir_with_tag); | ||
| 465 | 460 | ||
| 466 | 461 | if (UNLIKELY(!env->permission()->is_granted( | |
| 467 | 462 | env, | |
| 468 | 463 | permission::PermissionScope::kFileSystemWrite, | |
| 469 | - cache_dir_with_tag_str))) { | ||
| 464 | + cache_dir_with_tag))) { | ||
| 470 | 465 | result.message = "Skipping compile cache because write permission for " + | |
| 471 | - cache_dir_with_tag_str + " is not granted"; | ||
| 466 | + cache_dir_with_tag + " is not granted"; | ||
| 472 | 467 | result.status = CompileCacheEnableStatus::FAILED; | |
| 473 | 468 | return result; | |
| 474 | 469 | } | |
| 475 | 470 | ||
| 476 | 471 | if (UNLIKELY(!env->permission()->is_granted( | |
| 477 | 472 | env, | |
| 478 | 473 | permission::PermissionScope::kFileSystemRead, | |
| 479 | - cache_dir_with_tag_str))) { | ||
| 474 | + cache_dir_with_tag))) { | ||
| 480 | 475 | result.message = "Skipping compile cache because read permission for " + | |
| 481 | - cache_dir_with_tag_str + " is not granted"; | ||
| 476 | + cache_dir_with_tag + " is not granted"; | ||
| 482 | 477 | result.status = CompileCacheEnableStatus::FAILED; | |
| 483 | 478 | return result; | |
| 484 | 479 | } | |
| 485 | 480 | ||
| 486 | 481 | fs::FSReqWrapSync req_wrap; | |
| 487 | 482 | int err = fs::MKDirpSync( | |
| 488 | - nullptr, &(req_wrap.req), cache_dir_with_tag_str, 0777, nullptr); | ||
| 483 | + nullptr, &(req_wrap.req), cache_dir_with_tag, 0777, nullptr); | ||
| 489 | 484 | if (is_debug_) { | |
| 490 | 485 | Debug("[compile cache] creating cache directory %s...%s\n", | |
| 491 | - cache_dir_with_tag_str, | ||
| 486 | + cache_dir_with_tag, | ||
| 492 | 487 | err < 0 ? uv_strerror(err) : "success"); | |
| 493 | 488 | } | |
| 494 | 489 | if (err != 0 && err != UV_EEXIST) { | |
@@ -498,7 +493,6 @@ CompileCacheEnableResult CompileCacheHandler::Enable(Environment* env, | |||
| 498 | 493 | return result; | |
| 499 | 494 | } | |
| 500 | 495 | ||
| 501 | - compile_cache_dir_str_ = absolute_cache_dir_base; | ||
| 502 | 496 | result.cache_directory = absolute_cache_dir_base; | |
| 503 | 497 | compile_cache_dir_ = cache_dir_with_tag; | |
| 504 | 498 | result.status = CompileCacheEnableStatus::ENABLED; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,7 +4,6 @@ | |||
| 4 | 4 | #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS | |
| 5 | 5 | ||
| 6 | 6 | #include <cinttypes> | |
| 7 | - #include <filesystem> | ||
| 8 | 7 | #include <memory> | |
| 9 | 8 | #include <string> | |
| 10 | 9 | #include <string_view> | |
@@ -71,7 +70,7 @@ class CompileCacheHandler { | |||
| 71 | 70 | void MaybeSave(CompileCacheEntry* entry, | |
| 72 | 71 | v8::Local<v8::Module> mod, | |
| 73 | 72 | bool rejected); | |
| 74 | - std::string_view cache_dir() { return compile_cache_dir_str_; } | ||
| 73 | + std::string_view cache_dir() { return compile_cache_dir_; } | ||
| 75 | 74 | ||
| 76 | 75 | private: | |
| 77 | 76 | void ReadCacheFile(CompileCacheEntry* entry); | |
@@ -94,8 +93,7 @@ class CompileCacheHandler { | |||
| 94 | 93 | v8::Isolate* isolate_ = nullptr; | |
| 95 | 94 | bool is_debug_ = false; | |
| 96 | 95 | ||
| 97 | - std::string compile_cache_dir_str_; | ||
| 98 | - std::filesystem::path compile_cache_dir_; | ||
| 96 | + std::string compile_cache_dir_; | ||
| 99 | 97 | std::unordered_map<uint32_t, std::unique_ptr<CompileCacheEntry>> | |
| 100 | 98 | compiler_cache_store_; | |
| 101 | 99 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,7 +28,6 @@ | |||
| 28 | 28 | #include <atomic> | |
| 29 | 29 | #include <cinttypes> | |
| 30 | 30 | #include <cstdio> | |
| 31 | - #include <filesystem> | ||
| 32 | 31 | #include <iostream> | |
| 33 | 32 | #include <limits> | |
| 34 | 33 | #include <memory> | |
@@ -741,8 +740,7 @@ std::string Environment::GetCwd(const std::string& exec_path) { | |||
| 741 | 740 | ||
| 742 | 741 | // This can fail if the cwd is deleted. In that case, fall back to | |
| 743 | 742 | // exec_path. | |
| 744 | - return exec_path.substr( | ||
| 745 | - 0, exec_path.find_last_of(std::filesystem::path::preferred_separator)); | ||
| 743 | + return exec_path.substr(0, exec_path.find_last_of(kPathSeparator)); | ||
| 746 | 744 | } | |
| 747 | 745 | ||
| 748 | 746 | void Environment::add_refs(int64_t diff) { | |
@@ -2130,7 +2128,7 @@ size_t Environment::NearHeapLimitCallback(void* data, | |||
| 2130 | 2128 | dir = Environment::GetCwd(env->exec_path_); | |
| 2131 | 2129 | } | |
| 2132 | 2130 | DiagnosticFilename name(env, "Heap", "heapsnapshot"); | |
| 2133 | - std::string filename = (std::filesystem::path(dir) / (*name)).string(); | ||
| 2131 | + std::string filename = dir + kPathSeparator + (*name); | ||
| 2134 | 2132 | ||
| 2135 | 2133 | Debug(env, DebugCategory::DIAGNOSTICS, "Start generating %s...\n", *name); | |
| 2136 | 2134 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,7 +11,6 @@ | |||
| 11 | 11 | #include "v8-inspector.h" | |
| 12 | 12 | ||
| 13 | 13 | #include <cinttypes> | |
| 14 | - #include <filesystem> | ||
| 15 | 14 | #include <limits> | |
| 16 | 15 | #include <sstream> | |
| 17 | 16 | #include "simdutf.h" | |
@@ -249,7 +248,7 @@ void V8ProfilerConnection::WriteProfile(simdjson::ondemand::object* result) { | |||
| 249 | 248 | ||
| 250 | 249 | std::string filename = GetFilename(); | |
| 251 | 250 | DCHECK(!filename.empty()); | |
| 252 | - std::string path = (std::filesystem::path(directory) / filename).string(); | ||
| 251 | + std::string path = directory + kPathSeparator + filename; | ||
| 253 | 252 | ||
| 254 | 253 | WriteResult(env_, path.c_str(), profile); | |
| 255 | 254 | } | |
@@ -305,7 +304,7 @@ void V8CoverageConnection::WriteProfile(simdjson::ondemand::object* result) { | |||
| 305 | 304 | ||
| 306 | 305 | std::string filename = GetFilename(); | |
| 307 | 306 | DCHECK(!filename.empty()); | |
| 308 | - std::string path = (std::filesystem::path(directory) / filename).string(); | ||
| 307 | + std::string path = directory + kPathSeparator + filename; | ||
| 309 | 308 | ||
| 310 | 309 | // Only insert source map cache when there's source map data at all. | |
| 311 | 310 | if (!source_map_cache_v->IsUndefined()) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -82,6 +82,12 @@ using v8::Value; | |||
| 82 | 82 | # define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) | |
| 83 | 83 | #endif | |
| 84 | 84 | ||
| 85 | + #ifdef __POSIX__ | ||
| 86 | + constexpr char kPathSeparator = '/'; | ||
| 87 | + #else | ||
| 88 | + const char* const kPathSeparator = "\\/"; | ||
| 89 | + #endif | ||
| 90 | + | ||
| 85 | 91 | inline int64_t GetOffset(Local<Value> value) { | |
| 86 | 92 | return IsSafeJsInt(value) ? value.As<Integer>()->Value() : -1; | |
| 87 | 93 | } | |
@@ -1646,9 +1652,9 @@ int MKDirpSync(uv_loop_t* loop, | |||
| 1646 | 1652 | return err; | |
| 1647 | 1653 | } | |
| 1648 | 1654 | case UV_ENOENT: { | |
| 1649 | - auto filesystem_path = std::filesystem::path(next_path); | ||
| 1650 | - if (filesystem_path.has_parent_path()) { | ||
| 1651 | - std::string dirname = filesystem_path.parent_path().string(); | ||
| 1655 | + std::string dirname = | ||
| 1656 | + next_path.substr(0, next_path.find_last_of(kPathSeparator)); | ||
| 1657 | + if (dirname != next_path) { | ||
| 1652 | 1658 | req_wrap->continuation_data()->PushPath(std::move(next_path)); | |
| 1653 | 1659 | req_wrap->continuation_data()->PushPath(std::move(dirname)); | |
| 1654 | 1660 | } else if (req_wrap->continuation_data()->paths().empty()) { | |
@@ -1726,9 +1732,9 @@ int MKDirpAsync(uv_loop_t* loop, | |||
| 1726 | 1732 | break; | |
| 1727 | 1733 | } | |
| 1728 | 1734 | case UV_ENOENT: { | |
| 1729 | - auto filesystem_path = std::filesystem::path(path); | ||
| 1730 | - if (filesystem_path.has_parent_path()) { | ||
| 1731 | - std::string dirname = filesystem_path.parent_path().string(); | ||
| 1735 | + std::string dirname = | ||
| 1736 | + path.substr(0, path.find_last_of(kPathSeparator)); | ||
| 1737 | + if (dirname != path) { | ||
| 1732 | 1738 | req_wrap->continuation_data()->PushPath(path); | |
| 1733 | 1739 | req_wrap->continuation_data()->PushPath(std::move(dirname)); | |
| 1734 | 1740 | } else if (req_wrap->continuation_data()->paths().empty()) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -322,14 +322,13 @@ void BindingData::GetNearestParentPackageJSON( | |||
| 322 | 322 | BufferValue path_value(realm->isolate(), args[0]); | |
| 323 | 323 | // Check if the path has a trailing slash. If so, add it after | |
| 324 | 324 | // ToNamespacedPath() as it will be deleted by ToNamespacedPath() | |
| 325 | - bool slashCheck = path_value.ToStringView().ends_with( | ||
| 326 | - std::filesystem::path::preferred_separator); | ||
| 325 | + bool slashCheck = path_value.ToStringView().ends_with(kPathSeparator); | ||
| 327 | 326 | ||
| 328 | 327 | ToNamespacedPath(realm->env(), &path_value); | |
| 329 | 328 | ||
| 330 | 329 | std::string path_value_str = path_value.ToString(); | |
| 331 | 330 | if (slashCheck) { | |
| 332 | - path_value_str.push_back(std::filesystem::path::preferred_separator); | ||
| 331 | + path_value_str.push_back(kPathSeparator); | ||
| 333 | 332 | } | |
| 334 | 333 | ||
| 335 | 334 | auto package_json = | |
@@ -349,14 +348,13 @@ void BindingData::GetNearestParentPackageJSONType( | |||
| 349 | 348 | BufferValue path_value(realm->isolate(), args[0]); | |
| 350 | 349 | // Check if the path has a trailing slash. If so, add it after | |
| 351 | 350 | // ToNamespacedPath() as it will be deleted by ToNamespacedPath() | |
| 352 | - bool slashCheck = path_value.ToStringView().ends_with( | ||
| 353 | - std::filesystem::path::preferred_separator); | ||
| 351 | + bool slashCheck = path_value.ToStringView().ends_with(kPathSeparator); | ||
| 354 | 352 | ||
| 355 | 353 | ToNamespacedPath(realm->env(), &path_value); | |
| 356 | 354 | ||
| 357 | 355 | std::string path_value_str = path_value.ToString(); | |
| 358 | 356 | if (slashCheck) { | |
| 359 | - path_value_str.push_back(std::filesystem::path::preferred_separator); | ||
| 357 | + path_value_str.push_back(kPathSeparator); | ||
| 360 | 358 | } | |
| 361 | 359 | ||
| 362 | 360 | auto package_json = | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,7 +21,6 @@ | |||
| 21 | 21 | #include <cstring> | |
| 22 | 22 | #include <ctime> | |
| 23 | 23 | #include <cwctype> | |
| 24 | - #include <filesystem> | ||
| 25 | 24 | #include <fstream> | |
| 26 | 25 | ||
| 27 | 26 | constexpr int NODE_REPORT_VERSION = 3; | |
@@ -887,9 +886,8 @@ std::string TriggerNodeReport(Isolate* isolate, | |||
| 887 | 886 | report_directory = per_process::cli_options->report_directory; | |
| 888 | 887 | } | |
| 889 | 888 | // Regular file. Append filename to directory path if one was specified | |
| 890 | - if (!report_directory.empty()) { | ||
| 891 | - std::string pathname = | ||
| 892 | - (std::filesystem::path(report_directory) / filename).string(); | ||
| 889 | + if (report_directory.length() > 0) { | ||
| 890 | + std::string pathname = report_directory + kPathSeparator + filename; | ||
| 893 | 891 | outfile.open(pathname, std::ios::out | std::ios::binary); | |
| 894 | 892 | } else { | |
| 895 | 893 | outfile.open(filename, std::ios::out | std::ios::binary); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,11 +7,11 @@ | |||
| 7 | 7 | namespace node { | |
| 8 | 8 | ||
| 9 | 9 | #ifdef _WIN32 | |
| 10 | - constexpr bool IsPathSeparator(char c) noexcept { | ||
| 10 | + constexpr bool IsPathSeparator(const char c) noexcept { | ||
| 11 | 11 | return c == '\\' || c == '/'; | |
| 12 | 12 | } | |
| 13 | 13 | #else // POSIX | |
| 14 | - constexpr bool IsPathSeparator(char c) noexcept { | ||
| 14 | + constexpr bool IsPathSeparator(const char c) noexcept { | ||
| 15 | 15 | return c == '/'; | |
| 16 | 16 | } | |
| 17 | 17 | #endif // _WIN32 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,9 +10,8 @@ | |||
| 10 | 10 | ||
| 11 | 11 | namespace node { | |
| 12 | 12 | ||
| 13 | - class Environment; | ||
| 13 | + constexpr bool IsPathSeparator(const char c) noexcept; | ||
| 14 | 14 | ||
| 15 | - constexpr bool IsPathSeparator(char c) noexcept; | ||
| 16 | 15 | std::string NormalizeString(const std::string_view path, | |
| 17 | 16 | bool allowAboveRoot, | |
| 18 | 17 | const std::string_view separator); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,12 +17,20 @@ | |||
| 17 | 17 | namespace { | |
| 18 | 18 | ||
| 19 | 19 | std::string WildcardIfDir(const std::string& res) noexcept { | |
| 20 | - auto path = std::filesystem::path(res); | ||
| 21 | - auto file_status = std::filesystem::status(path); | ||
| 22 | - if (file_status.type() == std::filesystem::file_type::directory) { | ||
| 23 | - path /= "*"; | ||
| 20 | + uv_fs_t req; | ||
| 21 | + int rc = uv_fs_stat(nullptr, &req, res.c_str(), nullptr); | ||
| 22 | + if (rc == 0) { | ||
| 23 | + const uv_stat_t* const s = static_cast<const uv_stat_t*>(req.ptr); | ||
| 24 | + if ((s->st_mode & S_IFMT) == S_IFDIR) { | ||
| 25 | + // add wildcard when directory | ||
| 26 | + if (res.back() == node::kPathSeparator) { | ||
| 27 | + return res + "*"; | ||
| 28 | + } | ||
| 29 | + return res + node::kPathSeparator + "*"; | ||
| 30 | + } | ||
| 24 | 31 | } | |
| 25 | - return path.string(); | ||
| 32 | + uv_fs_req_cleanup(&req); | ||
| 33 | + return res; | ||
| 26 | 34 | } | |
| 27 | 35 | ||
| 28 | 36 | void FreeRecursivelyNode( | |
| Back | FazBrowse Home | New Git URL |
0 commit comments