fix getCurrentPackage

This commit is contained in:
Geoffrey Goh
2016-02-11 21:18:00 -08:00
parent 009ae205f8
commit 7bb4e1099e
5 changed files with 34 additions and 14 deletions

View File

@@ -411,6 +411,10 @@ public class CodePush {
@Override
protected Void doInBackground(Object... params) {
WritableMap currentPackage = codePushPackage.getCurrentPackage();
if (currentPackage == null) {
promise.resolve("");
return null;
}
Boolean isPendingUpdate = false;

View File

@@ -129,14 +129,14 @@ public class CodePushPackage {
public WritableMap getCurrentPackage() {
String folderPath = getCurrentPackageFolderPath();
if (folderPath == null) {
return new WritableNativeMap();
return null;
}
String packagePath = CodePushUtils.appendPathComponent(folderPath, PACKAGE_FILE_NAME);
try {
return CodePushUtils.getWritableMapFromFile(packagePath);
} catch (IOException e) {
// There is no current package.
// Should not happen unless the update metadata was somehow deleted.
return null;
}
}
@@ -155,6 +155,12 @@ public class CodePushPackage {
DownloadProgressCallback progressCallback) throws IOException {
String newPackageFolderPath = getPackageFolderPath(CodePushUtils.tryGetString(updatePackage, PACKAGE_HASH_KEY));
if (FileUtils.fileAtPathExists(newPackageFolderPath)) {
// This removes any stale data in newPackageFolderPath that could have been left
// uncleared due to a crash or error during the download or install process.
FileUtils.deleteDirectoryAtPath(newPackageFolderPath);
}
String downloadUrlString = CodePushUtils.tryGetString(updatePackage, DOWNLOAD_URL_KEY);
URL downloadUrl = null;
HttpURLConnection connection = null;