Skip to content

Commit e7e88f8

Browse files
author
Mihail Slavchev
committed
add error handling
1 parent a7333c3 commit e7e88f8

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/jni/AssetExtractor.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ void AssetExtractor::ExtractAssets(JNIEnv *env, jobject obj, jstring apk, jstrin
4848

4949
if (shouldOverwrite || forceOverwrite)
5050
{
51-
//DEBUG_WRITE("write asset %s", assetFullname.c_str());
5251
strcpy(pathcopy, name);
5352
auto path = dirname(pathcopy);
5453
std::string dirFullname(baseDir);
@@ -60,19 +59,23 @@ void AssetExtractor::ExtractAssets(JNIEnv *env, jobject obj, jstring apk, jstrin
6059

6160
auto fd = fopen(assetFullname.c_str(), "w");
6261

63-
zip_int64_t sum = 0;
64-
while (sum != sb.size)
62+
if (fd != nullptr)
6563
{
66-
zip_int64_t len = zip_fread(zf, buf, sizeof(buf));
67-
assert(len > 0);
68-
69-
fwrite(buf, 1, len, fd);
70-
sum += len;
64+
zip_int64_t sum = 0;
65+
while (sum != sb.size)
66+
{
67+
zip_int64_t len = zip_fread(zf, buf, sizeof(buf));
68+
assert(len > 0);
69+
70+
fwrite(buf, 1, len, fd);
71+
sum += len;
72+
}
73+
fclose(fd);
74+
utimbuf t;
75+
t.modtime = sb.mtime;
76+
ret = utime(assetFullname.c_str(), &t);
7177
}
72-
fclose(fd);
73-
utimbuf t;
74-
t.modtime = sb.mtime;
75-
ret = utime(assetFullname.c_str(), &t);
78+
7679
zip_fclose(zf);
7780
}
7881
}

0 commit comments

Comments
 (0)