|
1 | 1 | #include "ModuleInternal.h"
|
2 | 2 | #include <Foundation/Foundation.h>
|
3 | 3 | #include <sys/stat.h>
|
| 4 | +#include <time.h> |
| 5 | +#include <utime.h> |
4 | 6 | #include <string>
|
5 | 7 | #include "Caches.h"
|
6 | 8 | #include "Helpers.h"
|
@@ -453,9 +455,9 @@ throw NativeScriptException("Unable to locate main entry in " +
|
453 | 455 | auto cacheLastModifiedTime = result.st_mtime;
|
454 | 456 | if (stat(path.c_str(), &result) == 0) {
|
455 | 457 | auto jsLastModifiedTime = result.st_mtime;
|
456 |
| - if (jsLastModifiedTime > 0 && cacheLastModifiedTime > 0 && |
457 |
| - jsLastModifiedTime > cacheLastModifiedTime) { |
458 |
| - // The javascript file is more recent than the cache file => ignore the cache |
| 458 | + if (jsLastModifiedTime != cacheLastModifiedTime) { |
| 459 | + // files have different dates, ignore the cache file (this is enforced by the |
| 460 | + // SaveScriptCache function) |
459 | 461 | return nullptr;
|
460 | 462 | }
|
461 | 463 | }
|
@@ -485,6 +487,17 @@ throw NativeScriptException("Unable to locate main entry in " +
|
485 | 487 | std::string cachePath = GetCacheFileName(path + ".cache");
|
486 | 488 | tns::WriteBinary(cachePath, cachedData->data, length);
|
487 | 489 | delete cachedData;
|
| 490 | + |
| 491 | + // make sure cache and js file have the same modification date |
| 492 | + struct stat result; |
| 493 | + struct utimbuf new_times; |
| 494 | + new_times.actime = time(nullptr); |
| 495 | + new_times.modtime = time(nullptr); |
| 496 | + if (stat(path.c_str(), &result) == 0) { |
| 497 | + auto jsLastModifiedTime = result.st_mtime; |
| 498 | + new_times.modtime = jsLastModifiedTime; |
| 499 | + } |
| 500 | + utime(cachePath.c_str(), &new_times); |
488 | 501 | }
|
489 | 502 |
|
490 | 503 | std::string ModuleInternal::GetCacheFileName(const std::string& path) {
|
|
0 commit comments