Skip to content

Commit 2f4d1c2

Browse files
committed
fix HarmonyOS Next file size error. ((port from cocos/cocos-engine#19100)
1 parent b7ba9f7 commit 2f4d1c2

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

native/cocos/platform/openharmony/FileUtils-OpenHarmony.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ long FileUtilsOpenHarmony::getFileSize(const std::string &filepath) {
178178
if (fullPath.empty()) {
179179
return 0;
180180
}
181+
182+
if(fullPath[0] == '/') {
183+
return FileUtils::getFileSize(fullPath);
184+
}
185+
181186
if (nullptr == _nativeResourceManager) {
182187
CC_LOG_ERROR("nativeResourceManager is nullptr");
183188
return 0;
@@ -201,11 +206,11 @@ bool FileUtilsOpenHarmony::isFileExistInternal(const std::string &strFilePath) c
201206
return false;
202207
}
203208

204-
if (strFilePath[0] != '/') {
209+
if (strFilePath[0] != '/') {
205210
const char *s = strFilePath.c_str();
206211
// Found "@assets/" at the beginning of the path and we don't want it
207212
if (strFilePath.find(ASSETS_FOLDER_NAME) == 0) s += strlen(ASSETS_FOLDER_NAME);
208-
213+
209214
if (nullptr == _nativeResourceManager) {
210215
CC_LOG_ERROR("nativeResourceManager is nullptr");
211216
return false;
@@ -217,7 +222,7 @@ bool FileUtilsOpenHarmony::isFileExistInternal(const std::string &strFilePath) c
217222
return true;
218223
}
219224
return false;
220-
}
225+
}
221226
FILE *fp = fopen(strFilePath.c_str(), "r");
222227
if (fp) {
223228
fclose(fp);

0 commit comments

Comments
 (0)