summaryrefslogtreecommitdiffstats
path: root/src/libs/installer/fileutils.cpp
diff options
context:
space:
mode:
authorArttu Tarkiainen <arttu.tarkiainen@qt.io>2022-08-24 12:19:11 +0300
committerArttu Tarkiainen <arttu.tarkiainen@qt.io>2022-10-14 15:15:51 +0300
commit59ce8c088fca01cfbabe9918302bdb0ee2eaf037 (patch)
tree0da452a18decd3f286fc2fda63307a7305891c39 /src/libs/installer/fileutils.cpp
parent30de0fe3f01ac3d6a0ee0a288d51dc920e4432ca (diff)
Add persistent metadata file cache
Introduce GenericDataCache and Metadata classes for storing the fetched metadata files (Updates.xml and uncompressed files from the meta.7z archives) on local filesystem. The cache uses a checksum based dictionary to keep track of the cached metadata items, with the SHA1 sums of downloaded Updates.xml files being the keys to refer single metadata item. We still need to download all the Updates.xml files on each fetch to check if the cached metadata items are applicable for the current repositories. Update the Updates.xml files in auto-test data to have unique contents, otherwise there could be conflicts with identical test repositories, as the tests will also utilize the cache now. Also omit registering Repository type to the meta-object system in the class contructors, this is expensive as we construct objects from the class frequently, in the worst case hundreds of thousands times. PackageManagerCore already does the registering. Task-number: QTIFW-2621 Change-Id: Iee10ead68befd722ffe7f18ca48483d5a3666658 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Katja Marttila <katja.marttila@qt.io>
Diffstat (limited to 'src/libs/installer/fileutils.cpp')
-rw-r--r--src/libs/installer/fileutils.cpp28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/libs/installer/fileutils.cpp b/src/libs/installer/fileutils.cpp
index 5a89073fc..6bd79d4dd 100644
--- a/src/libs/installer/fileutils.cpp
+++ b/src/libs/installer/fileutils.cpp
@@ -66,54 +66,62 @@ using namespace QInstaller;
/*!
\inmodule QtInstallerFramework
- \class QInstaller::TempDirDeleter
+ \class QInstaller::TempPathDeleter
\internal
*/
// -- TempDirDeleter
-TempDirDeleter::TempDirDeleter(const QString &path)
+TempPathDeleter::TempPathDeleter(const QString &path)
{
m_paths.insert(path);
}
-TempDirDeleter::TempDirDeleter(const QStringList &paths)
+TempPathDeleter::TempPathDeleter(const QStringList &paths)
: m_paths(QSet<QString>(paths.begin(), paths.end()))
{
}
-TempDirDeleter::~TempDirDeleter()
+TempPathDeleter::~TempPathDeleter()
{
releaseAndDeleteAll();
}
-QStringList TempDirDeleter::paths() const
+QStringList TempPathDeleter::paths() const
{
return m_paths.toList();
}
-void TempDirDeleter::add(const QString &path)
+void TempPathDeleter::add(const QString &path)
{
m_paths.insert(path);
}
-void TempDirDeleter::add(const QStringList &paths)
+void TempPathDeleter::add(const QStringList &paths)
{
m_paths += QSet<QString>(paths.begin(), paths.end());
}
-void TempDirDeleter::releaseAndDeleteAll()
+void TempPathDeleter::releaseAndDeleteAll()
{
foreach (const QString &path, m_paths)
releaseAndDelete(path);
}
-void TempDirDeleter::releaseAndDelete(const QString &path)
+void TempPathDeleter::releaseAndDelete(const QString &path)
{
if (m_paths.contains(path)) {
try {
m_paths.remove(path);
- removeDirectory(path);
+ if (QFileInfo(path).isDir()) {
+ removeDirectory(path);
+ return;
+ }
+ QFile file(path);
+ if (file.exists() && !file.remove()) {
+ throw Error(QCoreApplication::translate("QInstaller",
+ "Cannot remove file \"%1\": %3").arg(file.fileName(), file.errorString()));
+ }
} catch (const Error &e) {
qCritical() << Q_FUNC_INFO << "Exception caught:" << e.message();
} catch (...) {