summaryrefslogtreecommitdiffstats
path: root/installerbuilder
diff options
context:
space:
mode:
authorkh1 <karsten.heimrich@nokia.com>2012-02-28 17:50:35 +0100
committerKarsten Heimrich <karsten.heimrich@nokia.com>2012-03-01 11:57:57 +0100
commit1c1c5a08575ffe9117094edbf6db80c828809b01 (patch)
tree0ee8424ebec3964542e78afec7d8b7216c443a5f /installerbuilder
parent4e5d95928551d8a8a9f80964ea2077a31dd4b00b (diff)
Rewrite copy component data.
Since at some point file and directory use the same code, merge both foreach into one. Extend package info to store the copied archives (for use in binary creator). Change-Id: I57544530a139911d81ad72f1e871e57138fb6019 Reviewed-by: Tim Jenssen <tim.jenssen@nokia.com> Reviewed-by: Niels Weber <niels.2.weber@nokia.com>
Diffstat (limited to 'installerbuilder')
-rw-r--r--installerbuilder/common/repositorygen.cpp94
-rw-r--r--installerbuilder/common/repositorygen.h3
-rw-r--r--installerbuilder/repogen/repogen.cpp6
3 files changed, 43 insertions, 60 deletions
diff --git a/installerbuilder/common/repositorygen.cpp b/installerbuilder/common/repositorygen.cpp
index d7e90a1cc..fa3d4a044 100644
--- a/installerbuilder/common/repositorygen.cpp
+++ b/installerbuilder/common/repositorygen.cpp
@@ -711,78 +711,62 @@ void QInstaller::compressMetaDirectories(const QString &repoDir, const QString &
existingUpdatesXml.close();
}
-void QInstaller::copyComponentData(const QString &packageDir, const QString &repoDir,
- const PackageInfoVector &infos)
+void QInstaller::copyComponentData(const QString &packageDir, const QString &repoDir, PackageInfoVector &infos)
{
- foreach (const PackageInfo &info, infos) {
- const QString i = info.name;
- qDebug() << "Copying component data for" << i;
- const QString dataDirPath = QString::fromLatin1("%1/%2/data").arg(packageDir, i);
+ for (int i = 0; i < infos.count(); ++i) {
+ const PackageInfo info = infos.at(i);
+ const QString name = info.name;
+ qDebug() << "Copying component data for" << name;
+ const QString dataDirPath = QString::fromLatin1("%1/%2/data").arg(packageDir, name);
const QDir dataDir(dataDirPath);
- if (!QDir().mkpath(QString::fromLatin1("%1/%2").arg(repoDir, i))) {
- throw QInstaller::Error(QObject::tr("Could not create repository folder for "
- "component %1").arg(i));
+ if (!QDir().mkpath(QString::fromLatin1("%1/%2").arg(repoDir, name))) {
+ throw QInstaller::Error(QObject::tr("Could not create repository folder for component %1")
+ .arg(name));
}
- const QStringList files = dataDir.entryList(QDir::Files);
- foreach (const QString &file, files) {
- QFile tmp(dataDir.absoluteFilePath(file));
- openForRead(&tmp, tmp.fileName());
-
- const QString target = QString::fromLatin1("%1/%2/%4%3").arg(repoDir, i, file,
- info.version);
- qDebug() << QString::fromLatin1("Copying archive from %1 to %2").arg(tmp.fileName(), target);
- if (!tmp.copy(target)) {
- throw QInstaller::Error(QObject::tr("Could not copy %1 to %2: %3")
- .arg(tmp.fileName(), target, tmp.errorString()));
+ const QStringList entries = dataDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::Files);
+ foreach (const QString &entry, entries) {
+ QString target;
+ QFileInfo fileInfo(dataDir.absoluteFilePath(entry));
+ if (fileInfo.isFile()) {
+ target = QString::fromLatin1("%1/%2/%4%3").arg(repoDir, name, entry, info.version);
+ QFile tmp(dataDir.absoluteFilePath(entry));
+ qDebug() << QString::fromLatin1("Copying archive from %1 to %2").arg(tmp.fileName(), target);
+ openForRead(&tmp, tmp.fileName());
+ if (!tmp.copy(target)) {
+ throw QInstaller::Error(QObject::tr("Could not copy %1 to %2: %3").arg(tmp.fileName(),
+ target, tmp.errorString()));
+ }
+ } else if (fileInfo.isDir()) {
+ qDebug() << "Compressing data directory" << entry;
+ target = QString::fromLatin1("%1/%2/%4%3.7z").arg(repoDir, name, entry, info.version);
+ QInstaller::compressDirectory(QStringList() << dataDir.absoluteFilePath(entry), target);
+ } else {
+ continue;
}
+ infos[i].copiedArchives.append(target);
+
QFile archiveFile(target);
- QString archiveHashFileName = archiveFile.fileName();
- archiveHashFileName += QLatin1String(".sha1");
- qDebug() << "Hash is stored in" << archiveHashFileName;
- QFile archiveHashFile(archiveHashFileName);
- try {
- openForRead(&archiveFile, archiveFile.fileName());
- openForWrite(&archiveHashFile, archiveHashFile.fileName());
- const QByteArray archiveData = archiveFile.readAll();
- archiveFile.close();
- const QByteArray hashOfArchiveData = QCryptographicHash::hash(archiveData,
- QCryptographicHash::Sha1).toHex();
- archiveHashFile.write(hashOfArchiveData);
- archiveHashFile.close();
+ QFile archiveHashFile(archiveFile.fileName() + QLatin1String(".sha1"));
- } catch (const Error &/*e*/) {
- archiveHashFile.close();
- archiveFile.close();
- throw;
- }
- }
+ qDebug() << "Hash is stored in" << archiveHashFile.fileName();
+ qDebug() << "Creating hash of archive" << archiveFile.fileName();
- const QStringList dirs = dataDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
- foreach (const QString &dir, dirs) {
- qDebug() << "Compressing data directory" << dir;
- const QString archiveName = QString::fromLatin1("%1/%2/%4%3.7z").arg(repoDir, i, dir,
- info.version);
- compressDirectory(QStringList() << dataDir.absoluteFilePath(dir), archiveName);
- qDebug() << "Creating hash of archive"<< archiveName;
- QFile archiveFile(archiveName);
- QString archiveHashFileName = archiveFile.fileName();
- archiveHashFileName += QLatin1String(".sha1");
- qDebug() << "Hash is stored in"<< archiveHashFileName;
- QFile archiveHashFile(archiveHashFileName);
try {
openForRead(&archiveFile, archiveFile.fileName());
- openForWrite(&archiveHashFile, archiveHashFile.fileName());
const QByteArray archiveData = archiveFile.readAll();
archiveFile.close();
+
+ openForWrite(&archiveHashFile, archiveHashFile.fileName());
const QByteArray hashOfArchiveData = QCryptographicHash::hash(archiveData,
QCryptographicHash::Sha1).toHex();
archiveHashFile.write(hashOfArchiveData);
+ qDebug() << "Generated sha1 hash:" << hashOfArchiveData;
+ infos[i].copiedArchives.append(archiveHashFile.fileName());
archiveHashFile.close();
- } catch(const Error &/*e*/) {
- //std::cerr << e.message() << std::endl;
- archiveHashFile.close();
+ } catch (const Error &/*e*/) {
archiveFile.close();
+ archiveHashFile.close();
throw;
}
}
diff --git a/installerbuilder/common/repositorygen.h b/installerbuilder/common/repositorygen.h
index 6b8ebcb68..8cb517dae 100644
--- a/installerbuilder/common/repositorygen.h
+++ b/installerbuilder/common/repositorygen.h
@@ -45,6 +45,7 @@ struct PackageInfo
QString version;
QString directory;
QStringList dependencies;
+ QStringList copiedArchives;
};
typedef QVector<PackageInfo> PackageInfoVector;
@@ -55,7 +56,7 @@ void compressDirectory(const QStringList &paths, const QString &archivePath);
void compressMetaDirectories(const QString &repoDir, const QString &baseDir,
const QMap<QString, QString> &versionMapping);
-void copyComponentData(const QString &packageDir, const QString &repoDir, const PackageInfoVector &infos);
+void copyComponentData(const QString &packageDir, const QString &repoDir, PackageInfoVector &infos);
void generateMetaDataDirectory(const QString &outDir, const QString &dataDir,
const PackageInfoVector &packages, const QString &appName,
diff --git a/installerbuilder/repogen/repogen.cpp b/installerbuilder/repogen/repogen.cpp
index 4105b5f51..1c33a1d16 100644
--- a/installerbuilder/repogen/repogen.cpp
+++ b/installerbuilder/repogen/repogen.cpp
@@ -193,10 +193,8 @@ int main(int argc, char** argv)
.arg(repositoryDir));
}
- const PackageInfoVector packagesList = createListOfPackages(components, packagesDir,
- !replaceSingleComponent);
- const PackageInfoVector packages = filterBlacklisted(packagesList, excludedPackages);
-
+ PackageInfoVector packages = filterBlacklisted(createListOfPackages(components, packagesDir,
+ !replaceSingleComponent), excludedPackages);
QMap<QString, QString> pathToVersionMapping = buildPathToVersionMap(packages);
for (PackageInfoVector::const_iterator it = packages.begin(); it != packages.end(); ++it) {