Skip to content

Commit 380f83f

Browse files
committed
fix(core): fix GetFileModifyTime for v8 code cache
1 parent 0b1b603 commit 380f83f

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

modules/vfs/native/include/vfs/file.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class HippyFile {
5151
static int CreateDir(const string_view& dir_path, mode_t mode);
5252
static int CheckDir(const string_view& dir_path, int mode);
5353
static uint64_t GetFileModifyTime(const string_view& file_path);
54+
static const char* RemoveFilePrefix(const char* str);
5455

5556
template <typename CharType>
5657
static bool ReadFile(const string_view& file_path,

modules/vfs/native/src/file.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ uint64_t HippyFile::GetFileModifyTime(const string_view& file_path) {
124124
auto path_str = StringViewUtils::ConvertEncoding(file_path,
125125
string_view::Encoding::Utf8).utf8_value();
126126
auto path = reinterpret_cast<const char*>(path_str.c_str());
127+
path = RemoveFilePrefix(path);
127128
struct stat statInfo{};
128129
FILE* fp = fopen(path, "r");
129130
if (fp == nullptr) {
@@ -139,5 +140,16 @@ uint64_t HippyFile::GetFileModifyTime(const string_view& file_path) {
139140
return modify_time;
140141
}
141142

143+
const char* HippyFile::RemoveFilePrefix(const char* str) {
144+
const char* prefix = "file:";
145+
size_t prefix_len = strlen(prefix);
146+
147+
if (strncmp(str, prefix, prefix_len) == 0) {
148+
return str + prefix_len;
149+
}
150+
151+
return str;
152+
}
153+
142154
} // namespace vfs
143155
} // namespace hippy

0 commit comments

Comments
 (0)