Skip to content
This repository has been archived by the owner on Oct 1, 2018. It is now read-only.

Commit

Permalink
Cleanup file system from old releases after installing the new one.
Browse files Browse the repository at this point in the history
  • Loading branch information
nikDemyankov committed May 26, 2016
1 parent 5766238 commit 66c1ae0
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions src/android/src/com/nordnetab/chcp/main/HotCodePushPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,7 @@ public void initialize(final CordovaInterface cordova, final CordovaWebView webV
Log.d("CHCP", "Currently running release version " + pluginInternalPrefs.getCurrentReleaseVersionName());

// clean up file system
if (!TextUtils.isEmpty(pluginInternalPrefs.getCurrentReleaseVersionName())) {
CleanUpHelper.removeReleaseFolders(cordova.getActivity(),
new String[]{pluginInternalPrefs.getCurrentReleaseVersionName(),
pluginInternalPrefs.getPreviousReleaseVersionName(),
pluginInternalPrefs.getReadyForInstallationReleaseVersionName()
}
);
}
cleanupFileSystemFromOldReleases();

handler = new Handler();
fileStructure = new PluginFilesStructure(cordova.getActivity(), pluginInternalPrefs.getCurrentReleaseVersionName());
Expand All @@ -115,12 +108,12 @@ public void initialize(final CordovaInterface cordova, final CordovaWebView webV
@Override
public void onStart() {
super.onStart();

final EventBus eventBus = EventBus.getDefault();
if (!eventBus.isRegistered(this)) {
eventBus.register(this);
}

// ensure that www folder installed on external storage;
// if not - install it
isPluginReadyForWork = isPluginReadyForWork();
Expand Down Expand Up @@ -246,7 +239,7 @@ public boolean execute(String action, CordovaArgs args, CallbackContext callback
* Send message to default plugin callback.
* Default callback - is a callback that we receive on initialization (device ready).
* Through it we are broadcasting different events.
*
* <p/>
* If callback is not set yet - message will be stored until it is initialized.
*
* @param message message to send to web side
Expand All @@ -266,7 +259,7 @@ private boolean sendMessageToDefaultCallback(final PluginResult message) {

/**
* Dispatch stored events for the default callback.
* */
*/
private void dispatchDefaultCallbackStoredResults() {
if (defaultCallbackStoredResults.size() == 0 || jsDefaultCallback == null) {
return;
Expand Down Expand Up @@ -404,7 +397,7 @@ private void jsRequestAppUpdate(final CordovaArgs arguments, final CallbackConte
* Check if new version was loaded and can be installed.
*
* @param callback callback where to send the result
* */
*/
private void jsIsUpdateAvailableForInstallation(final CallbackContext callback) {
Map<String, Object> data = null;
ChcpError error = null;
Expand Down Expand Up @@ -789,6 +782,8 @@ public void run() {
HotCodePushPlugin.this.redirectToLocalStorageIndexPage();
}
});

cleanupFileSystemFromOldReleases();
}

/**
Expand Down Expand Up @@ -843,6 +838,23 @@ public void onEvent(NothingToInstallEvent event) {

// endregion

// region Cleanup process

private void cleanupFileSystemFromOldReleases() {
if (TextUtils.isEmpty(pluginInternalPrefs.getCurrentReleaseVersionName())) {
return;
}

CleanUpHelper.removeReleaseFolders(cordova.getActivity(),
new String[]{pluginInternalPrefs.getCurrentReleaseVersionName(),
pluginInternalPrefs.getPreviousReleaseVersionName(),
pluginInternalPrefs.getReadyForInstallationReleaseVersionName()
}
);
}

//endregion

// region Rollback process

/**
Expand Down

0 comments on commit 66c1ae0

Please sign in to comment.