Skip to content
This repository was archived by the owner on Feb 2, 2019. It is now read-only.

Commit dbdb991

Browse files
committed
Backups - fix restoring
1 parent e043635 commit dbdb991

File tree

2 files changed

+42
-8
lines changed

2 files changed

+42
-8
lines changed

src/ornbackup.cpp

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,23 +121,49 @@ void OrnBackup::pSearchPackages()
121121
// Delete future watcher and prepare variables
122122
this->sender()->deleteLater();
123123
mPackagesToInstall.clear();
124+
mSearchIndex = 0;
124125

125-
auto t = mZypp->transaction();
126+
auto t = new PackageKit::Transaction();
127+
connect(t, &PackageKit::Transaction::errorCode, mZypp, &OrnZypp::pkError);
126128
connect(t, &PackageKit::Transaction::package, this, &OrnBackup::pAddPackage);
127-
connect(t, &PackageKit::Transaction::finished, this, &OrnBackup::pInstallPackages);
128-
t->searchNames(mNamesToSearch, PackageKit::Transaction::FilterNotInstalled);
129+
// It seems that the PackageKit::Transaction::searchNames(QStringList, ...)
130+
// does searches only for the first name so we use this hack
131+
connect(t, &PackageKit::Transaction::finished, [this, t]()
132+
{
133+
++mSearchIndex;
134+
if (mSearchIndex < mNamesToSearch.size())
135+
{
136+
t->reset();
137+
t->searchNames(mNamesToSearch[mSearchIndex]);
138+
}
139+
else
140+
{
141+
t->deleteLater();
142+
this->pInstallPackages();
143+
}
144+
});
145+
t->searchNames(mNamesToSearch[mSearchIndex]);
129146
}
130147

131148
void OrnBackup::pAddPackage(int info, const QString &packageId, const QString &summary)
132149
{
133150
Q_UNUSED(info)
134151
Q_UNUSED(summary)
135152
auto idParts = packageId.split(QChar(';'));
136-
// Process only packages from OpenRepos
137-
if (idParts.last().startsWith(OrnZypp::repoNamePrefix))
153+
auto name = idParts.first();
154+
if (mNamesToSearch.contains(name))
138155
{
139-
// We will filter the newest versions later
140-
mPackagesToInstall.insertMulti(idParts.first(), packageId);
156+
auto repo = idParts.last();
157+
// Process only packages from OpenRepos
158+
if (repo.startsWith(OrnZypp::repoNamePrefix))
159+
{
160+
// We will filter the newest versions later
161+
mPackagesToInstall.insert(name, packageId);
162+
}
163+
else if (repo == QStringLiteral("installed"))
164+
{
165+
mInstalled.insert(name, idParts[1]);
166+
}
141167
}
142168
}
143169

@@ -161,7 +187,11 @@ void OrnBackup::pInstallPackages()
161187
newestId = pid;
162188
}
163189
}
164-
ids << newestId;
190+
// Skip packages that are already installed
191+
if (!mInstalled.contains(pname) || OrnVersion(mInstalled[pname]) < newestVersion)
192+
{
193+
ids << newestId;
194+
}
165195
}
166196

167197
if (ids.isEmpty())
@@ -279,6 +309,7 @@ void OrnBackup::pRefreshRepos()
279309
this->setStatus(RefreshingRepos);
280310
auto t = new PackageKit::Transaction();
281311
connect(t, &PackageKit::Transaction::finished, t, &PackageKit::Transaction::deleteLater);
312+
connect(t, &PackageKit::Transaction::errorCode, mZypp, &OrnZypp::pkError);
282313
connect(t, &PackageKit::Transaction::finished, this, &OrnBackup::pSearchPackages);
283314
t->refreshCache(false);
284315
}

src/ornbackup.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,11 @@ private slots:
6565
private:
6666
OrnZypp *mZypp;
6767
Status mStatus;
68+
QStringList::size_type mSearchIndex;
6869
QString mFilePath;
6970
QStringList mNamesToSearch;
71+
// Name, version
72+
QHash<QString, QString> mInstalled;
7073
QMultiHash<QString, QString> mPackagesToInstall;
7174
};
7275

0 commit comments

Comments
 (0)