Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions NativeScript/runtime/ModuleInternal.mm
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "ModuleInternal.h"
#include <Foundation/Foundation.h>
#include <sys/stat.h>
#include <time.h>
#include <utime.h>
#include <string>
#include "Caches.h"
#include "Helpers.h"
Expand Down Expand Up @@ -453,9 +455,9 @@ throw NativeScriptException("Unable to locate main entry in " +
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;
}
}
Expand Down Expand Up @@ -485,6 +487,17 @@ throw NativeScriptException("Unable to locate main entry in " +
std::string cachePath = GetCacheFileName(path + ".cache");
tns::WriteBinary(cachePath, cachedData->data, length);
delete cachedData;

// make sure cache and js file have the same modification date
struct stat result;
struct utimbuf new_times;
new_times.actime = time(nullptr);
new_times.modtime = time(nullptr);
if (stat(path.c_str(), &result) == 0) {
auto jsLastModifiedTime = result.st_mtime;
new_times.modtime = jsLastModifiedTime;
}
utime(cachePath.c_str(), &new_times);
}

std::string ModuleInternal::GetCacheFileName(const std::string& path) {
Expand Down
Loading