|
23 | 23 | #include <libgen.h>
|
24 | 24 | #include <dlfcn.h>
|
25 | 25 | #include <sys/stat.h>
|
| 26 | +#include <time.h> |
| 27 | +#include <utime.h> |
26 | 28 |
|
27 | 29 | using namespace v8;
|
28 | 30 | using namespace std;
|
@@ -478,8 +480,9 @@ ScriptCompiler::CachedData* ModuleInternal::TryLoadScriptCache(const std::string
|
478 | 480 | auto cacheLastModifiedTime = result.st_mtime;
|
479 | 481 | if (stat(path.c_str(), &result) == 0) {
|
480 | 482 | auto jsLastModifiedTime = result.st_mtime;
|
481 |
| - if (jsLastModifiedTime > 0 && cacheLastModifiedTime > 0 && jsLastModifiedTime > cacheLastModifiedTime) { |
482 |
| - // The javascript file is more recent than the cache file => ignore the cache |
| 483 | + if (jsLastModifiedTime != cacheLastModifiedTime) { |
| 484 | + // files have different dates, ignore the cache file (this is enforced by the |
| 485 | + // SaveScriptCache function) |
483 | 486 | return nullptr;
|
484 | 487 | }
|
485 | 488 | }
|
@@ -508,6 +511,16 @@ void ModuleInternal::SaveScriptCache(const Local<Script> script, const std::stri
|
508 | 511 | auto cachePath = path + ".cache";
|
509 | 512 | File::WriteBinary(cachePath, cachedData->data, length);
|
510 | 513 | delete cachedData;
|
| 514 | + // make sure cache and js file have the same modification date |
| 515 | + struct stat result; |
| 516 | + struct utimbuf new_times; |
| 517 | + new_times.actime = time(nullptr); |
| 518 | + new_times.modtime = time(nullptr); |
| 519 | + if (stat(path.c_str(), &result) == 0) { |
| 520 | + auto jsLastModifiedTime = result.st_mtime; |
| 521 | + new_times.modtime = jsLastModifiedTime; |
| 522 | + } |
| 523 | + utime(cachePath.c_str(), &new_times); |
511 | 524 | }
|
512 | 525 |
|
513 | 526 | ModuleInternal::ModulePathKind ModuleInternal::GetModulePathKind(const std::string& path) {
|
|
0 commit comments