Skip to content

Commit 9ae80e1

Browse files
anonrigtargos
authored andcommitted
src: revert filesystem::path changes
PR-URL: #55015 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent 449dad0 commit 9ae80e1

File tree

12 files changed

+55
-55
lines changed

12 files changed

+55
-55
lines changed

src/compile_cache.cc

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "node_internals.h"
77
#include "node_version.h"
88
#include "path.h"
9+
#include "util.h"
910
#include "zlib.h"
1011

1112
#ifdef NODE_IMPLEMENTS_POSIX_CREDENTIALS
@@ -225,14 +226,11 @@ CompileCacheEntry* CompileCacheHandler::GetOrInsert(
225226
compiler_cache_store_.emplace(key, std::make_unique<CompileCacheEntry>());
226227
auto* result = emplaced.first->second.get();
227228

228-
std::u8string cache_filename_u8 =
229-
(compile_cache_dir_ / Uint32ToHex(key)).u8string();
230229
result->code_hash = code_hash;
231230
result->code_size = code_utf8.length();
232231
result->cache_key = key;
233232
result->cache_filename =
234-
std::string(cache_filename_u8.begin(), cache_filename_u8.end()) +
235-
".cache";
233+
compile_cache_dir_ + kPathSeparator + Uint32ToHex(key);
236234
result->source_filename = filename_utf8.ToString();
237235
result->cache = nullptr;
238236
result->type = type;
@@ -452,43 +450,40 @@ CompileCacheEnableResult CompileCacheHandler::Enable(Environment* env,
452450
const std::string& dir) {
453451
std::string cache_tag = GetCacheVersionTag();
454452
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;
460455
CompileCacheEnableResult result;
461456
Debug("[compile cache] resolved path %s + %s -> %s\n",
462457
dir,
463458
cache_tag,
464-
cache_dir_with_tag_str);
459+
cache_dir_with_tag);
465460

466461
if (UNLIKELY(!env->permission()->is_granted(
467462
env,
468463
permission::PermissionScope::kFileSystemWrite,
469-
cache_dir_with_tag_str))) {
464+
cache_dir_with_tag))) {
470465
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";
472467
result.status = CompileCacheEnableStatus::FAILED;
473468
return result;
474469
}
475470

476471
if (UNLIKELY(!env->permission()->is_granted(
477472
env,
478473
permission::PermissionScope::kFileSystemRead,
479-
cache_dir_with_tag_str))) {
474+
cache_dir_with_tag))) {
480475
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";
482477
result.status = CompileCacheEnableStatus::FAILED;
483478
return result;
484479
}
485480

486481
fs::FSReqWrapSync req_wrap;
487482
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);
489484
if (is_debug_) {
490485
Debug("[compile cache] creating cache directory %s...%s\n",
491-
cache_dir_with_tag_str,
486+
cache_dir_with_tag,
492487
err < 0 ? uv_strerror(err) : "success");
493488
}
494489
if (err != 0 && err != UV_EEXIST) {
@@ -498,7 +493,6 @@ CompileCacheEnableResult CompileCacheHandler::Enable(Environment* env,
498493
return result;
499494
}
500495

501-
compile_cache_dir_str_ = absolute_cache_dir_base;
502496
result.cache_directory = absolute_cache_dir_base;
503497
compile_cache_dir_ = cache_dir_with_tag;
504498
result.status = CompileCacheEnableStatus::ENABLED;

src/compile_cache.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
55

66
#include <cinttypes>
7-
#include <filesystem>
87
#include <memory>
98
#include <string>
109
#include <string_view>
@@ -71,7 +70,7 @@ class CompileCacheHandler {
7170
void MaybeSave(CompileCacheEntry* entry,
7271
v8::Local<v8::Module> mod,
7372
bool rejected);
74-
std::string_view cache_dir() { return compile_cache_dir_str_; }
73+
std::string_view cache_dir() { return compile_cache_dir_; }
7574

7675
private:
7776
void ReadCacheFile(CompileCacheEntry* entry);
@@ -94,8 +93,7 @@ class CompileCacheHandler {
9493
v8::Isolate* isolate_ = nullptr;
9594
bool is_debug_ = false;
9695

97-
std::string compile_cache_dir_str_;
98-
std::filesystem::path compile_cache_dir_;
96+
std::string compile_cache_dir_;
9997
std::unordered_map<uint32_t, std::unique_ptr<CompileCacheEntry>>
10098
compiler_cache_store_;
10199
};

src/env.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include <atomic>
2929
#include <cinttypes>
3030
#include <cstdio>
31-
#include <filesystem>
3231
#include <iostream>
3332
#include <limits>
3433
#include <memory>
@@ -741,8 +740,7 @@ std::string Environment::GetCwd(const std::string& exec_path) {
741740

742741
// This can fail if the cwd is deleted. In that case, fall back to
743742
// 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));
746744
}
747745

748746
void Environment::add_refs(int64_t diff) {
@@ -2130,7 +2128,7 @@ size_t Environment::NearHeapLimitCallback(void* data,
21302128
dir = Environment::GetCwd(env->exec_path_);
21312129
}
21322130
DiagnosticFilename name(env, "Heap", "heapsnapshot");
2133-
std::string filename = (std::filesystem::path(dir) / (*name)).string();
2131+
std::string filename = dir + kPathSeparator + (*name);
21342132

21352133
Debug(env, DebugCategory::DIAGNOSTICS, "Start generating %s...\n", *name);
21362134

src/inspector_profiler.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "v8-inspector.h"
1212

1313
#include <cinttypes>
14-
#include <filesystem>
1514
#include <limits>
1615
#include <sstream>
1716
#include "simdutf.h"
@@ -249,7 +248,7 @@ void V8ProfilerConnection::WriteProfile(simdjson::ondemand::object* result) {
249248

250249
std::string filename = GetFilename();
251250
DCHECK(!filename.empty());
252-
std::string path = (std::filesystem::path(directory) / filename).string();
251+
std::string path = directory + kPathSeparator + filename;
253252

254253
WriteResult(env_, path.c_str(), profile);
255254
}
@@ -305,7 +304,7 @@ void V8CoverageConnection::WriteProfile(simdjson::ondemand::object* result) {
305304

306305
std::string filename = GetFilename();
307306
DCHECK(!filename.empty());
308-
std::string path = (std::filesystem::path(directory) / filename).string();
307+
std::string path = directory + kPathSeparator + filename;
309308

310309
// Only insert source map cache when there's source map data at all.
311310
if (!source_map_cache_v->IsUndefined()) {

src/node_file.cc

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ using v8::Value;
8282
# define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
8383
#endif
8484

85+
#ifdef __POSIX__
86+
constexpr char kPathSeparator = '/';
87+
#else
88+
const char* const kPathSeparator = "\\/";
89+
#endif
90+
8591
inline int64_t GetOffset(Local<Value> value) {
8692
return IsSafeJsInt(value) ? value.As<Integer>()->Value() : -1;
8793
}
@@ -1646,9 +1652,9 @@ int MKDirpSync(uv_loop_t* loop,
16461652
return err;
16471653
}
16481654
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) {
16521658
req_wrap->continuation_data()->PushPath(std::move(next_path));
16531659
req_wrap->continuation_data()->PushPath(std::move(dirname));
16541660
} else if (req_wrap->continuation_data()->paths().empty()) {
@@ -1726,9 +1732,9 @@ int MKDirpAsync(uv_loop_t* loop,
17261732
break;
17271733
}
17281734
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) {
17321738
req_wrap->continuation_data()->PushPath(path);
17331739
req_wrap->continuation_data()->PushPath(std::move(dirname));
17341740
} else if (req_wrap->continuation_data()->paths().empty()) {

src/node_modules.cc

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -322,14 +322,13 @@ void BindingData::GetNearestParentPackageJSON(
322322
BufferValue path_value(realm->isolate(), args[0]);
323323
// Check if the path has a trailing slash. If so, add it after
324324
// 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);
327326

328327
ToNamespacedPath(realm->env(), &path_value);
329328

330329
std::string path_value_str = path_value.ToString();
331330
if (slashCheck) {
332-
path_value_str.push_back(std::filesystem::path::preferred_separator);
331+
path_value_str.push_back(kPathSeparator);
333332
}
334333

335334
auto package_json =
@@ -349,14 +348,13 @@ void BindingData::GetNearestParentPackageJSONType(
349348
BufferValue path_value(realm->isolate(), args[0]);
350349
// Check if the path has a trailing slash. If so, add it after
351350
// 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);
354352

355353
ToNamespacedPath(realm->env(), &path_value);
356354

357355
std::string path_value_str = path_value.ToString();
358356
if (slashCheck) {
359-
path_value_str.push_back(std::filesystem::path::preferred_separator);
357+
path_value_str.push_back(kPathSeparator);
360358
}
361359

362360
auto package_json =

src/node_report.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include <cstring>
2222
#include <ctime>
2323
#include <cwctype>
24-
#include <filesystem>
2524
#include <fstream>
2625

2726
constexpr int NODE_REPORT_VERSION = 3;
@@ -887,9 +886,8 @@ std::string TriggerNodeReport(Isolate* isolate,
887886
report_directory = per_process::cli_options->report_directory;
888887
}
889888
// 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;
893891
outfile.open(pathname, std::ios::out | std::ios::binary);
894892
} else {
895893
outfile.open(filename, std::ios::out | std::ios::binary);

src/path.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
namespace node {
88

99
#ifdef _WIN32
10-
constexpr bool IsPathSeparator(char c) noexcept {
10+
constexpr bool IsPathSeparator(const char c) noexcept {
1111
return c == '\\' || c == '/';
1212
}
1313
#else // POSIX
14-
constexpr bool IsPathSeparator(char c) noexcept {
14+
constexpr bool IsPathSeparator(const char c) noexcept {
1515
return c == '/';
1616
}
1717
#endif // _WIN32

src/path.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010

1111
namespace node {
1212

13-
class Environment;
13+
constexpr bool IsPathSeparator(const char c) noexcept;
1414

15-
constexpr bool IsPathSeparator(char c) noexcept;
1615
std::string NormalizeString(const std::string_view path,
1716
bool allowAboveRoot,
1817
const std::string_view separator);

src/permission/fs_permission.cc

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,20 @@
1717
namespace {
1818

1919
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+
}
2431
}
25-
return path.string();
32+
uv_fs_req_cleanup(&req);
33+
return res;
2634
}
2735

2836
void FreeRecursivelyNode(

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy