9
9
AptCache::AptCache ()
10
10
{
11
11
loadCacheFiles ();
12
+ parseContent ();
12
13
}
13
14
14
15
void AptCache::loadCacheFiles ()
15
16
{
16
17
// 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
18
20
+ " _Packages)|"
19
21
" (.*binary-.*_Packages(?!.*debian_.*-backports_.*_Packages)"
20
22
" (?!.*mx_testrepo.*_test_.*_Packages)"
21
23
" (?!.*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 ();
24
27
if (packagesFilter.match (fileName).hasMatch () && !readFile (fileName)) {
25
28
qWarning () << " Error reading cache file:" << fileName;
26
29
}
27
30
}
28
- parseContent ();
29
31
}
30
32
31
33
QMap<QString, PackageInfo> AptCache::getCandidates () const
@@ -36,7 +38,8 @@ QMap<QString, PackageInfo> AptCache::getCandidates() const
36
38
// Return DEB_BUILD_ARCH format which differs from what 'arch' or currentCpuArchitecture return
37
39
QString AptCache::getArch ()
38
40
{
39
- return arch_names.value (QSysInfo::currentCpuArchitecture ());
41
+ static const QString arch = arch_names.value (QSysInfo::currentCpuArchitecture ());
42
+ return arch;
40
43
}
41
44
42
45
void AptCache::parseContent ()
@@ -49,7 +52,8 @@ void AptCache::parseContent()
49
52
QString description;
50
53
QString architecture;
51
54
52
- const QRegularExpression re_arch (" .*(" + getArch () + " |all).*" );
55
+ const QString arch = getArch ();
56
+ const QRegularExpression re_arch (" .*(" + arch + " |all).*" );
53
57
bool match_arch = false ;
54
58
55
59
// Code assumes Description: is the last matched line
@@ -64,9 +68,9 @@ void AptCache::parseContent()
64
68
} else if (line.startsWith (QLatin1String (" Description:" ))) {
65
69
description = line.mid (13 ).trimmed ();
66
70
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};
70
74
}
71
75
}
72
76
}
@@ -81,7 +85,7 @@ bool AptCache::readFile(const QString &file_name)
81
85
qWarning () << " Could not open file: " << file.fileName ();
82
86
return false ;
83
87
}
84
- files_content += file.readAll ();
88
+ files_content += QLatin1String ( " \n " ) + file.readAll ();
85
89
file.close ();
86
90
return true ;
87
91
}
0 commit comments