From a6b25443c1a02174e149f4ac4a271d23918ac7ae Mon Sep 17 00:00:00 2001 From: Eduardo Speroni Date: Fri, 6 Sep 2024 11:20:17 -0300 Subject: [PATCH] fix: ensure same mtime for js and code cache to prevent loading old code caches --- .../runtime/src/main/cpp/ModuleInternal.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/test-app/runtime/src/main/cpp/ModuleInternal.cpp b/test-app/runtime/src/main/cpp/ModuleInternal.cpp index 07f2588cd..a7779cc50 100644 --- a/test-app/runtime/src/main/cpp/ModuleInternal.cpp +++ b/test-app/runtime/src/main/cpp/ModuleInternal.cpp @@ -23,6 +23,8 @@ #include #include #include +#include +#include using namespace v8; using namespace std; @@ -478,8 +480,9 @@ ScriptCompiler::CachedData* ModuleInternal::TryLoadScriptCache(const std::string auto cacheLastModifiedTime = result.st_mtime; if (stat(path.c_str(), &result) == 0) { auto jsLastModifiedTime = result.st_mtime; - if (jsLastModifiedTime > 0 && cacheLastModifiedTime > 0 && jsLastModifiedTime > cacheLastModifiedTime) { - // The javascript file is more recent than the cache file => ignore the cache + if (jsLastModifiedTime != cacheLastModifiedTime) { + // files have different dates, ignore the cache file (this is enforced by the + // SaveScriptCache function) return nullptr; } } @@ -508,6 +511,16 @@ void ModuleInternal::SaveScriptCache(const Local