Skip to content

Commit 353d750

Browse files
committed
Minor improvements to AptCache
1 parent 6755db1 commit 353d750

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

aptcache.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,25 @@
99
AptCache::AptCache()
1010
{
1111
loadCacheFiles();
12+
parseContent();
1213
}
1314

1415
void AptCache::loadCacheFiles()
1516
{
1617
// Exclude Debian backports and MX testrepo and temp repos
17-
const QRegularExpression packagesFilter("(.*binary-" + getArch()
18+
const QString arch = getArch();
19+
const QRegularExpression packagesFilter("(.*binary-" + arch
1820
+ "_Packages)|"
1921
"(.*binary-.*_Packages(?!.*debian_.*-backports_.*_Packages)"
2022
"(?!.*mx_testrepo.*_test_.*_Packages)"
2123
"(?!.*mx_repo.*_temp_.*_Packages))");
22-
const QStringList files = QDir(dir).entryList(QDir::Files);
23-
for (const QString &fileName : files) {
24+
QDirIterator it(dir.path(), QDir::Files);
25+
while (it.hasNext()) {
26+
const QString fileName = it.next();
2427
if (packagesFilter.match(fileName).hasMatch() && !readFile(fileName)) {
2528
qWarning() << "Error reading cache file:" << fileName;
2629
}
2730
}
28-
parseContent();
2931
}
3032

3133
QMap<QString, PackageInfo> AptCache::getCandidates() const
@@ -36,7 +38,8 @@ QMap<QString, PackageInfo> AptCache::getCandidates() const
3638
// Return DEB_BUILD_ARCH format which differs from what 'arch' or currentCpuArchitecture return
3739
QString AptCache::getArch()
3840
{
39-
return arch_names.value(QSysInfo::currentCpuArchitecture());
41+
static const QString arch = arch_names.value(QSysInfo::currentCpuArchitecture());
42+
return arch;
4043
}
4144

4245
void AptCache::parseContent()
@@ -49,7 +52,8 @@ void AptCache::parseContent()
4952
QString description;
5053
QString architecture;
5154

52-
const QRegularExpression re_arch(".*(" + getArch() + "|all).*");
55+
const QString arch = getArch();
56+
const QRegularExpression re_arch(".*(" + arch + "|all).*");
5357
bool match_arch = false;
5458

5559
// Code assumes Description: is the last matched line
@@ -64,9 +68,9 @@ void AptCache::parseContent()
6468
} else if (line.startsWith(QLatin1String("Description:"))) {
6569
description = line.mid(13).trimmed();
6670
if (match_arch) {
67-
auto it = candidates.constFind(package);
68-
if (it == candidates.constEnd() || VersionNumber(it.value().version) < VersionNumber(version)) {
69-
candidates.insert(package, {version, description});
71+
auto it = candidates.find(package);
72+
if (it == candidates.end() || VersionNumber(it->version) < VersionNumber(version)) {
73+
candidates[package] = {version, description};
7074
}
7175
}
7276
}
@@ -81,7 +85,7 @@ bool AptCache::readFile(const QString &file_name)
8185
qWarning() << "Could not open file: " << file.fileName();
8286
return false;
8387
}
84-
files_content += file.readAll();
88+
files_content += QLatin1String("\n") + file.readAll();
8589
file.close();
8690
return true;
8791
}

0 commit comments

Comments
 (0)