Skip to content

Commit d33b5aa

Browse files
authored
Merge pull request #1557 from NativeScript/darind/codecache-livesync
Ensure js timestamp is smaller than corresponding code cache file timstamp
2 parents 05a2a3d + a6906f1 commit d33b5aa

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

test-app/runtime/src/main/cpp/ModuleInternal.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <mutex>
2323
#include <libgen.h>
2424
#include <dlfcn.h>
25+
#include <sys/stat.h>
2526

2627
using namespace v8;
2728
using namespace std;
@@ -460,6 +461,19 @@ ScriptCompiler::CachedData* ModuleInternal::TryLoadScriptCache(const std::string
460461
}
461462

462463
auto cachePath = path + ".cache";
464+
465+
struct stat result;
466+
if (stat(cachePath.c_str(), &result) == 0) {
467+
auto cacheLastModifiedTime = result.st_mtime;
468+
if (stat(path.c_str(), &result) == 0) {
469+
auto jsLastModifiedTime = result.st_mtime;
470+
if (jsLastModifiedTime > 0 && cacheLastModifiedTime > 0 && jsLastModifiedTime > cacheLastModifiedTime) {
471+
// The javascript file is more recent than the cache file => ignore the cache
472+
return nullptr;
473+
}
474+
}
475+
}
476+
463477
int length = 0;
464478
auto data = File::ReadBinary(cachePath, length);
465479
if (!data) {

0 commit comments

Comments
 (0)