Skip to content

Commit

Permalink
adding a permanent fix for clearing old stuff!
Browse files Browse the repository at this point in the history
  • Loading branch information
antony-jr committed Jan 13, 2018
1 parent e854b47 commit 9638ccf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
48 changes: 25 additions & 23 deletions AIUpdaterBridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ void AIUpdaterBridge::setAppImageUpdateInformation(const QString& appImage)
if(!mutex.tryLock()) {
return;
}

clear();

connect(&AppImageInformer, SIGNAL(updateInformation(const QString&, const QJsonObject&)),
this, SLOT(handleAppImageUpdateInformation(const QString&, const QJsonObject&)));
connect(&AppImageInformer, SIGNAL(error(const QString&, short)),
Expand All @@ -101,6 +104,9 @@ void AIUpdaterBridge::setAppImageUpdateInformation(const QJsonObject& config)
if(!mutex.tryLock()) {
return;
}

clear();

if(!config["appImagePath"].isString() || config["appImagePath"].isNull()) {
if(debug) {
qDebug() << "AIUpdaterBridge:: 'appImagePath' entry missing in the given json ::" << config;
Expand Down Expand Up @@ -260,6 +266,21 @@ void AIUpdaterBridge::stopUpdating(void)
return;
}

void AIUpdaterBridge::clear(void)
{
appImage.clear();
zsyncHeader.clear();
zsyncFileName.clear();
zsyncHeaderJson = QJsonObject(); // clean zsync header
zsyncURL.clear();
fileURL.clear();

if(zsyncFile != NULL) {
zsyncFile = NULL;
}
github = stopUpdate = false;
return;
}

/* ------------------------------- */

Expand Down Expand Up @@ -826,10 +847,10 @@ void AIUpdaterBridge::doUpdate(void)
zsyncHeaderJson = QJsonObject(); // clean zsync header
zsyncURL.clear();
fileURL.clear();
if(zsyncFile != NULL){
free(zsyncFile);
zsyncFile = NULL;

if(zsyncFile != NULL) {
free(zsyncFile);
zsyncFile = NULL;
}
github = stopUpdate = false;
mutex.unlock();
Expand Down Expand Up @@ -896,26 +917,7 @@ void AIUpdaterBridge::doUpdate(void)
emit error(LocalFile, POST_INSTALLATION_FAILED);
return;
}

/*
* Clear everything -> This is really important!
*/
zsyncHeader.clear();
zsyncFileName.clear();
zsyncHeaderJson = QJsonObject(); // clean zsync header
zsyncURL.clear();
fileURL.clear();

if(zsyncFile != NULL){
/*
* Do not free here!
*/
zsyncFile = NULL;
}
github = stopUpdate = false;

emit updateFinished(appImage, RemoteSHA1); // Yeaa , Finally Finished Gracefully!
appImage.clear();
}
mutex.unlock();
return;
Expand Down
1 change: 1 addition & 0 deletions AIUpdaterBridge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public slots:
bool isRunning(void);
void startUpdating(void);
void stopUpdating(void);
void clear(void);

private slots:
void doUpdate(void);
Expand Down

0 comments on commit 9638ccf

Please sign in to comment.