Skip to content

Commit 67ddaa9

Browse files
committed
src: revert filesystem::path changes
1 parent 291d90a commit 67ddaa9

File tree

12 files changed

+54
-54
lines changed

12 files changed

+54
-54
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
namespace node {
@@ -219,14 +220,11 @@ CompileCacheEntry* CompileCacheHandler::GetOrInsert(
219220
compiler_cache_store_.emplace(key, std::make_unique<CompileCacheEntry>());
220221
auto* result = emplaced.first->second.get();
221222

222-
std::u8string cache_filename_u8 =
223-
(compile_cache_dir_ / Uint32ToHex(key)).u8string();
224223
result->code_hash = code_hash;
225224
result->code_size = code_utf8.length();
226225
result->cache_key = key;
227226
result->cache_filename =
228-
std::string(cache_filename_u8.begin(), cache_filename_u8.end()) +
229-
".cache";
227+
compile_cache_dir_ + kPathSeparator + Uint32ToHex(key);
230228
result->source_filename = filename_utf8.ToString();
231229
result->cache = nullptr;
232230
result->type = type;
@@ -364,43 +362,40 @@ CompileCacheEnableResult CompileCacheHandler::Enable(Environment* env,
364362
const std::string& dir) {
365363
std::string cache_tag = GetCacheVersionTag();
366364
std::string absolute_cache_dir_base = PathResolve(env, {dir});
367-
std::filesystem::path cache_dir_with_tag =
368-
std::filesystem::path(absolute_cache_dir_base) / cache_tag;
369-
std::u8string cache_dir_with_tag_u8 = cache_dir_with_tag.u8string();
370-
std::string cache_dir_with_tag_str(cache_dir_with_tag_u8.begin(),
371-
cache_dir_with_tag_u8.end());
365+
std::string cache_dir_with_tag =
366+
absolute_cache_dir_base + kPathSeparator + cache_tag;
372367
CompileCacheEnableResult result;
373368
Debug("[compile cache] resolved path %s + %s -> %s\n",
374369
dir,
375370
cache_tag,
376-
cache_dir_with_tag_str);
371+
cache_dir_with_tag);
377372

378373
if (UNLIKELY(!env->permission()->is_granted(
379374
env,
380375
permission::PermissionScope::kFileSystemWrite,
381-
cache_dir_with_tag_str))) {
376+
cache_dir_with_tag))) {
382377
result.message = "Skipping compile cache because write permission for " +
383-
cache_dir_with_tag_str + " is not granted";
378+
cache_dir_with_tag + " is not granted";
384379
result.status = CompileCacheEnableStatus::FAILED;
385380
return result;
386381
}
387382

388383
if (UNLIKELY(!env->permission()->is_granted(
389384
env,
390385
permission::PermissionScope::kFileSystemRead,
391-
cache_dir_with_tag_str))) {
386+
cache_dir_with_tag))) {
392387
result.message = "Skipping compile cache because read permission for " +
393-
cache_dir_with_tag_str + " is not granted";
388+
cache_dir_with_tag + " is not granted";
394389
result.status = CompileCacheEnableStatus::FAILED;
395390
return result;
396391
}
397392

398393
fs::FSReqWrapSync req_wrap;
399394
int err = fs::MKDirpSync(
400-
nullptr, &(req_wrap.req), cache_dir_with_tag_str, 0777, nullptr);
395+
nullptr, &(req_wrap.req), cache_dir_with_tag, 0777, nullptr);
401396
if (is_debug_) {
402397
Debug("[compile cache] creating cache directory %s...%s\n",
403-
cache_dir_with_tag_str,
398+
cache_dir_with_tag,
404399
err < 0 ? uv_strerror(err) : "success");
405400
}
406401
if (err != 0 && err != UV_EEXIST) {
@@ -410,7 +405,6 @@ CompileCacheEnableResult CompileCacheHandler::Enable(Environment* env,
410405
return result;
411406
}
412407

413-
compile_cache_dir_str_ = absolute_cache_dir_base;
414408
result.cache_directory = absolute_cache_dir_base;
415409
compile_cache_dir_ = cache_dir_with_tag;
416410
result.status = CompileCacheEnableStatus::ENABLED;

src/compile_cache.h

Lines changed: 1 addition & 3 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>
@@ -92,8 +91,7 @@ class CompileCacheHandler {
9291
v8::Isolate* isolate_ = nullptr;
9392
bool is_debug_ = false;
9493

95-
std::string compile_cache_dir_str_;
96-
std::filesystem::path compile_cache_dir_;
94+
std::string compile_cache_dir_;
9795
std::unordered_map<uint32_t, std::unique_ptr<CompileCacheEntry>>
9896
compiler_cache_store_;
9997
};

src/env.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#include <atomic>
3030
#include <cinttypes>
3131
#include <cstdio>
32-
#include <filesystem>
3332
#include <iostream>
3433
#include <limits>
3534
#include <memory>
@@ -730,8 +729,7 @@ std::string Environment::GetCwd(const std::string& exec_path) {
730729

731730
// This can fail if the cwd is deleted. In that case, fall back to
732731
// exec_path.
733-
return exec_path.substr(
734-
0, exec_path.find_last_of(std::filesystem::path::preferred_separator));
732+
return exec_path.substr(0, exec_path.find_last_of(kPathSeparator));
735733
}
736734

737735
void Environment::add_refs(int64_t diff) {
@@ -2122,7 +2120,7 @@ size_t Environment::NearHeapLimitCallback(void* data,
21222120
dir = Environment::GetCwd(env->exec_path_);
21232121
}
21242122
DiagnosticFilename name(env, "Heap", "heapsnapshot");
2125-
std::string filename = (std::filesystem::path(dir) / (*name)).string();
2123+
std::string filename = dir + kPathSeparator + (*name);
21262124

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

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
@@ -88,6 +88,12 @@ using v8::Value;
8888
# define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
8989
#endif
9090

91+
#ifdef __POSIX__
92+
constexpr char kPathSeparator = '/';
93+
#else
94+
const char* const kPathSeparator = "\\/";
95+
#endif
96+
9197
inline int64_t GetOffset(Local<Value> value) {
9298
return IsSafeJsInt(value) ? value.As<Integer>()->Value() : -1;
9399
}
@@ -1741,9 +1747,9 @@ int MKDirpSync(uv_loop_t* loop,
17411747
return err;
17421748
}
17431749
case UV_ENOENT: {
1744-
auto filesystem_path = std::filesystem::path(next_path);
1745-
if (filesystem_path.has_parent_path()) {
1746-
std::string dirname = filesystem_path.parent_path().string();
1750+
std::string dirname =
1751+
next_path.substr(0, next_path.find_last_of(kPathSeparator));
1752+
if (dirname != next_path) {
17471753
req_wrap->continuation_data()->PushPath(std::move(next_path));
17481754
req_wrap->continuation_data()->PushPath(std::move(dirname));
17491755
} else if (req_wrap->continuation_data()->paths().empty()) {
@@ -1821,9 +1827,9 @@ int MKDirpAsync(uv_loop_t* loop,
18211827
break;
18221828
}
18231829
case UV_ENOENT: {
1824-
auto filesystem_path = std::filesystem::path(path);
1825-
if (filesystem_path.has_parent_path()) {
1826-
std::string dirname = filesystem_path.parent_path().string();
1830+
std::string dirname =
1831+
path.substr(0, path.find_last_of(kPathSeparator));
1832+
if (dirname != path) {
18271833
req_wrap->continuation_data()->PushPath(path);
18281834
req_wrap->continuation_data()->PushPath(std::move(dirname));
18291835
} 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(

src/permission/fs_permission.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
#include "v8.h"
77

8-
#include <filesystem>
98
#include <unordered_map>
109
#include "permission/permission_base.h"
1110
#include "util.h"
@@ -107,7 +106,7 @@ class FSPermission final : public PermissionBase {
107106
// path = /home/subdirectory
108107
// child = subdirectory/*
109108
if (idx >= path.length() &&
110-
child->prefix[i] == std::filesystem::path::preferred_separator) {
109+
child->prefix[i] == node::kPathSeparator) {
111110
continue;
112111
}
113112

src/util.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
#include <array>
4040
#include <bit>
41+
#include <filesystem>
4142
#include <limits>
4243
#include <memory>
4344
#include <optional>
@@ -57,6 +58,8 @@
5758

5859
namespace node {
5960

61+
constexpr char kPathSeparator = std::filesystem::path::preferred_separator;
62+
6063
#ifdef _WIN32
6164
/* MAX_PATH is in characters, not bytes. Make sure we have enough headroom. */
6265
#define PATH_MAX_BYTES (MAX_PATH * 4)

0 commit comments

Comments
 (0)