66#include " node_internals.h"
77#include " node_version.h"
88#include " path.h"
9+ #include " util.h"
910#include " zlib.h"
1011
1112namespace 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 (result->cache_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;
0 commit comments