summaryrefslogtreecommitdiffstats
path: root/src/package-lib/package_p.cpp
diff options
context:
space:
mode:
authorRobert Griebl <robert.griebl@pelagicore.com>2016-09-26 02:35:54 +0200
committerRobert Griebl <robert.griebl@pelagicore.com>2016-10-17 21:43:52 +0000
commit21ae572d2152bd52096aef759534a803b98eb50d (patch)
treee8c7c6c4136f8348f312c0f450c3932e07df9a18 /src/package-lib/package_p.cpp
parentd475d73d9f292cf26e6cd1c6284a0da3efd69d09 (diff)
Reimplemented build-system as a real Qt module
This should help with doc generation and actually running the unit-tests in the CI system. Please note that the binaries are now installed into $$[QT_INSTALL_BINS] Change-Id: I6f27ba39f8e5d923e1aeff550ba11c1fbd8ac5cf Reviewed-by: Robert Griebl <robert.griebl@pelagicore.com>
Diffstat (limited to 'src/package-lib/package_p.cpp')
-rw-r--r--src/package-lib/package_p.cpp88
1 files changed, 88 insertions, 0 deletions
diff --git a/src/package-lib/package_p.cpp b/src/package-lib/package_p.cpp
new file mode 100644
index 00000000..5074222c
--- /dev/null
+++ b/src/package-lib/package_p.cpp
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 Pelagicore AG
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Pelagicore Application Manager.
+**
+** $QT_BEGIN_LICENSE:LGPL-QTAS$
+** Commercial License Usage
+** Licensees holding valid commercial Qt Automotive Suite licenses may use
+** this file in accordance with the commercial license agreement provided
+** with the Software or, alternatively, in accordance with the terms
+** contained in a written agreement between you and The Qt Company. For
+** licensing terms and conditions see https://www.qt.io/terms-conditions.
+** For further information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+** SPDX-License-Identifier: LGPL-3.0
+**
+****************************************************************************/
+
+
+#include <QFileInfo>
+#include <QDataStream>
+
+#include <archive.h>
+
+#include "package_p.h"
+#include "digestfilter.h"
+
+AM_BEGIN_NAMESPACE
+
+ArchiveException::ArchiveException(struct ::archive *ar, const char *errorString)
+ : Exception(Error::Archive, qSL("[libarchive] ") + qL1S(errorString) + qSL(": ") + QString::fromLocal8Bit(::archive_error_string(ar)))
+{ }
+
+
+QVariantMap PackageUtilities::importantHeaderData = QVariantMap {
+};
+
+void PackageUtilities::addFileMetadataToDigest(const QString &entryFilePath, const QFileInfo &fi, DigestFilter *digest)
+{
+ // (using QDataStream would be more readable, but it would make the algorithm Qt dependent)
+ QByteArray addToDigest = ((fi.isDir()) ? "D/" : "F/")
+ + QByteArray::number(fi.isDir() ? 0 : fi.size())
+ + '/' + entryFilePath.toUtf8();
+ digest->processData(addToDigest);
+}
+
+void PackageUtilities::addImportantHeaderDataToDigest(const QVariantMap &header, DigestFilter *digest) throw (Exception)
+{
+ for (auto it = importantHeaderData.constBegin(); it != importantHeaderData.constEnd(); ++it) {
+ if (header.contains(it.key())) {
+ QByteArray ba;
+ QDataStream ds(&ba, QIODevice::WriteOnly);
+
+ QVariant v = header.value(it.key());
+ if (!v.convert(it.value().type()))
+ throw Exception(Error::Package, "metadata field %1 has invalid type for digest calculation (cannot convert %2 to %3)")
+ .arg(it.key()).arg(header.value(it.key()).type()).arg(it.value().type());
+ ds << v;
+
+ digest->processData(ba);
+ }
+ }
+}
+
+AM_END_NAMESPACE