From 1d45e99fd197ca52c631af594a3b34196b2ae123 Mon Sep 17 00:00:00 2001 From: Geoffrey Goh Date: Thu, 18 Feb 2016 23:51:20 -0800 Subject: [PATCH] package->update android --- .../codepush/react/CodePushPackage.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/android/app/src/main/java/com/microsoft/codepush/react/CodePushPackage.java b/android/app/src/main/java/com/microsoft/codepush/react/CodePushPackage.java index 9179813..6623caf 100644 --- a/android/app/src/main/java/com/microsoft/codepush/react/CodePushPackage.java +++ b/android/app/src/main/java/com/microsoft/codepush/react/CodePushPackage.java @@ -153,13 +153,13 @@ public class CodePushPackage { public void downloadPackage(Context applicationContext, ReadableMap updatePackage, DownloadProgressCallback progressCallback) throws IOException { - String newPackageHash = CodePushUtils.tryGetString(updatePackage, PACKAGE_HASH_KEY); - String newPackageFolderPath = getPackageFolderPath(newPackageHash); - String newPackageMetadataPath = CodePushUtils.appendPathComponent(newPackageFolderPath, PACKAGE_FILE_NAME); - if (FileUtils.fileAtPathExists(newPackageFolderPath)) { + String newUpdateHash = CodePushUtils.tryGetString(updatePackage, PACKAGE_HASH_KEY); + String newUpdateFolderPath = getPackageFolderPath(newUpdateHash); + String newUpdateMetadataPath = CodePushUtils.appendPathComponent(newUpdateFolderPath, PACKAGE_FILE_NAME); + if (FileUtils.fileAtPathExists(newUpdateFolderPath)) { // 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); + FileUtils.deleteDirectoryAtPath(newUpdateFolderPath); } String downloadUrlString = CodePushUtils.tryGetString(updatePackage, DOWNLOAD_URL_KEY); @@ -232,27 +232,27 @@ public class CodePushPackage { DIFF_MANIFEST_FILE_NAME); if (FileUtils.fileAtPathExists(diffManifestFilePath)) { String currentPackageFolderPath = getCurrentPackageFolderPath(); - CodePushUpdateUtils.copyNecessaryFilesFromCurrentPackage(diffManifestFilePath, currentPackageFolderPath, newPackageFolderPath); + CodePushUpdateUtils.copyNecessaryFilesFromCurrentPackage(diffManifestFilePath, currentPackageFolderPath, newUpdateFolderPath); File diffManifestFile = new File(diffManifestFilePath); diffManifestFile.delete(); } - FileUtils.copyDirectoryContents(unzippedFolderPath, newPackageFolderPath); + FileUtils.copyDirectoryContents(unzippedFolderPath, newUpdateFolderPath); FileUtils.deleteFileAtPathSilently(unzippedFolderPath); // For zip updates, we need to find the relative path to the jsBundle and save it in the // metadata so that we can find and run it easily the next time. - String relativeBundlePath = CodePushUpdateUtils.findJSBundleInUpdateContents(newPackageFolderPath); + String relativeBundlePath = CodePushUpdateUtils.findJSBundleInUpdateContents(newUpdateFolderPath); if (relativeBundlePath == null) { throw new CodePushInvalidUpdateException("Update is invalid - no files with extension .bundle, .js or .jsbundle were found in the update package."); } else { - if (FileUtils.fileAtPathExists(newPackageMetadataPath)) { - File metadataFileFromOldUpdate = new File(newPackageMetadataPath); + if (FileUtils.fileAtPathExists(newUpdateMetadataPath)) { + File metadataFileFromOldUpdate = new File(newUpdateMetadataPath); metadataFileFromOldUpdate.delete(); } - CodePushUpdateUtils.verifyHashForZipUpdate(newPackageFolderPath, newPackageHash); + CodePushUpdateUtils.verifyHashForZipUpdate(newUpdateFolderPath, newUpdateHash); JSONObject updatePackageJSON = CodePushUtils.convertReadableToJsonObject(updatePackage); try { @@ -267,11 +267,11 @@ public class CodePushPackage { } } else { // File is a jsbundle, move it to a folder with the packageHash as its name - FileUtils.moveFile(downloadFile, newPackageFolderPath, UPDATE_BUNDLE_FILE_NAME); + FileUtils.moveFile(downloadFile, newUpdateFolderPath, UPDATE_BUNDLE_FILE_NAME); } // Save metadata to the folder. - CodePushUtils.writeReadableMapToFile(updatePackage, newPackageMetadataPath); + CodePushUtils.writeReadableMapToFile(updatePackage, newUpdateMetadataPath); } public void installPackage(ReadableMap updatePackage, boolean removePendingUpdate) throws IOException {