2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2016-01-15 14:57:40 +01:00
|
|
|
|
2011-07-15 16:57:25 +02:00
|
|
|
#include "tarpackagecreationstep.h"
|
|
|
|
|
|
2022-05-27 16:51:04 +02:00
|
|
|
#include "deploymenttimeinfo.h"
|
2020-09-16 12:08:11 +02:00
|
|
|
#include "remotelinux_constants.h"
|
2022-07-15 12:20:23 +02:00
|
|
|
#include "remotelinuxtr.h"
|
2020-09-16 12:08:11 +02:00
|
|
|
|
2016-12-25 12:31:12 -05:00
|
|
|
#include <projectexplorer/buildmanager.h>
|
2012-08-22 16:52:38 +02:00
|
|
|
#include <projectexplorer/deploymentdata.h>
|
2022-07-01 17:29:29 +02:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2011-07-15 16:57:25 +02:00
|
|
|
#include <projectexplorer/project.h>
|
|
|
|
|
#include <projectexplorer/target.h>
|
2019-08-09 13:55:15 +02:00
|
|
|
|
2022-11-08 15:08:21 +01:00
|
|
|
#include <utils/futuresynchronizer.h>
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDateTime>
|
|
|
|
|
#include <QDir>
|
|
|
|
|
#include <QFile>
|
|
|
|
|
#include <QFileInfo>
|
2011-07-15 16:57:25 +02:00
|
|
|
|
2012-09-20 14:25:01 +02:00
|
|
|
#include <cstring>
|
|
|
|
|
|
2011-07-15 16:57:25 +02:00
|
|
|
using namespace ProjectExplorer;
|
2020-09-18 12:11:40 +02:00
|
|
|
using namespace Utils;
|
2011-07-15 16:57:25 +02:00
|
|
|
|
2022-07-01 17:29:29 +02:00
|
|
|
namespace RemoteLinux::Internal {
|
2022-05-27 16:51:04 +02:00
|
|
|
|
2013-09-16 15:52:25 +02:00
|
|
|
const char IgnoreMissingFilesKey[] = "RemoteLinux.TarPackageCreationStep.IgnoreMissingFiles";
|
2016-12-25 12:31:12 -05:00
|
|
|
const char IncrementalDeploymentKey[] = "RemoteLinux.TarPackageCreationStep.IncrementalDeployment";
|
2011-07-15 16:57:25 +02:00
|
|
|
|
|
|
|
|
const int TarBlockSize = 512;
|
2022-07-01 17:29:29 +02:00
|
|
|
|
2011-07-15 16:57:25 +02:00
|
|
|
struct TarFileHeader {
|
|
|
|
|
char fileName[100];
|
|
|
|
|
char fileMode[8];
|
|
|
|
|
char uid[8];
|
|
|
|
|
char gid[8];
|
|
|
|
|
char length[12];
|
|
|
|
|
char mtime[12];
|
|
|
|
|
char chksum[8];
|
|
|
|
|
char typeflag;
|
|
|
|
|
char linkname[100];
|
|
|
|
|
char magic[6];
|
|
|
|
|
char version[2];
|
|
|
|
|
char uname[32];
|
|
|
|
|
char gname[32];
|
|
|
|
|
char devmajor[8];
|
|
|
|
|
char devminor[8];
|
|
|
|
|
char fileNamePrefix[155];
|
|
|
|
|
char padding[12];
|
|
|
|
|
};
|
|
|
|
|
|
2022-07-01 17:29:29 +02:00
|
|
|
class TarPackageCreationStep : public BuildStep
|
2022-05-27 16:51:04 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2022-07-01 17:29:29 +02:00
|
|
|
TarPackageCreationStep(BuildStepList *bsl, Id id);
|
|
|
|
|
|
|
|
|
|
FilePath packageFilePath() const;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
bool init() final;
|
|
|
|
|
void doRun() final;
|
|
|
|
|
bool fromMap(const QVariantMap &map) final;
|
|
|
|
|
QVariantMap toMap() const final;
|
|
|
|
|
QVariant data(Id id) const final;
|
|
|
|
|
|
|
|
|
|
void raiseError(const QString &errorMessage);
|
|
|
|
|
void raiseWarning(const QString &warningMessage);
|
|
|
|
|
bool isPackagingNeeded() const;
|
|
|
|
|
void deployFinished(bool success);
|
|
|
|
|
void addNeededDeploymentFiles(const DeployableFile &deployable, const Kit *kit);
|
|
|
|
|
bool runImpl();
|
|
|
|
|
bool doPackage();
|
|
|
|
|
bool appendFile(QFile &tarFile, const QFileInfo &fileInfo, const QString &remoteFilePath);
|
|
|
|
|
|
2022-05-27 16:51:04 +02:00
|
|
|
FilePath m_cachedPackageFilePath;
|
|
|
|
|
bool m_deploymentDataModified = false;
|
|
|
|
|
DeploymentTimeInfo m_deployTimes;
|
|
|
|
|
BoolAspect *m_incrementalDeploymentAspect = nullptr;
|
|
|
|
|
BoolAspect *m_ignoreMissingFilesAspect = nullptr;
|
|
|
|
|
bool m_packagingNeeded = false;
|
|
|
|
|
QList<DeployableFile> m_files;
|
2022-11-08 15:08:21 +01:00
|
|
|
|
|
|
|
|
FutureSynchronizer m_synchronizer;
|
2022-05-27 16:51:04 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TarPackageCreationStep::TarPackageCreationStep(BuildStepList *bsl, Id id)
|
|
|
|
|
: BuildStep(bsl, id)
|
2011-07-15 16:57:25 +02:00
|
|
|
{
|
2022-05-27 16:51:04 +02:00
|
|
|
connect(target(), &Target::deploymentDataChanged, this, [this] {
|
2022-07-01 17:29:29 +02:00
|
|
|
m_deploymentDataModified = true;
|
2022-05-27 16:51:04 +02:00
|
|
|
});
|
2022-07-01 17:29:29 +02:00
|
|
|
m_deploymentDataModified = true;
|
2022-05-27 16:51:04 +02:00
|
|
|
|
2022-07-01 17:29:29 +02:00
|
|
|
m_ignoreMissingFilesAspect = addAspect<BoolAspect>();
|
|
|
|
|
m_ignoreMissingFilesAspect->setLabel(Tr::tr("Ignore missing files"),
|
2020-08-13 09:16:00 +02:00
|
|
|
BoolAspect::LabelPlacement::AtCheckBox);
|
2022-07-01 17:29:29 +02:00
|
|
|
m_ignoreMissingFilesAspect->setSettingsKey(IgnoreMissingFilesKey);
|
2018-10-17 09:14:51 +02:00
|
|
|
|
2022-07-01 17:29:29 +02:00
|
|
|
m_incrementalDeploymentAspect = addAspect<BoolAspect>();
|
|
|
|
|
m_incrementalDeploymentAspect->setLabel(Tr::tr("Package modified files only"),
|
|
|
|
|
BoolAspect::LabelPlacement::AtCheckBox);
|
|
|
|
|
m_incrementalDeploymentAspect->setSettingsKey(IncrementalDeploymentKey);
|
2019-06-25 16:53:40 +02:00
|
|
|
|
|
|
|
|
setSummaryUpdater([this] {
|
2021-10-27 12:00:41 +02:00
|
|
|
FilePath path = packageFilePath();
|
2019-06-25 16:53:40 +02:00
|
|
|
if (path.isEmpty())
|
2022-07-15 12:20:23 +02:00
|
|
|
return QString("<font color=\"red\">" + Tr::tr("Tarball creation not possible.")
|
2019-06-25 16:53:40 +02:00
|
|
|
+ "</font>");
|
2022-07-15 12:20:23 +02:00
|
|
|
return QString("<b>" + Tr::tr("Create tarball:") + "</b> " + path.toUserOutput());
|
2019-06-25 16:53:40 +02:00
|
|
|
});
|
2011-07-15 16:57:25 +02:00
|
|
|
}
|
|
|
|
|
|
2022-05-27 16:51:04 +02:00
|
|
|
FilePath TarPackageCreationStep::packageFilePath() const
|
|
|
|
|
{
|
|
|
|
|
if (buildDirectory().isEmpty())
|
|
|
|
|
return {};
|
2022-07-01 17:29:29 +02:00
|
|
|
const QString packageFileName = project()->displayName() + ".tar";
|
2022-05-27 16:51:04 +02:00
|
|
|
return buildDirectory().pathAppended(packageFileName);
|
|
|
|
|
}
|
2016-12-25 12:31:12 -05:00
|
|
|
|
2022-05-27 16:51:04 +02:00
|
|
|
bool TarPackageCreationStep::init()
|
|
|
|
|
{
|
2022-07-01 17:29:29 +02:00
|
|
|
m_cachedPackageFilePath = packageFilePath();
|
|
|
|
|
m_packagingNeeded = isPackagingNeeded();
|
2011-10-13 18:53:49 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
ProjectExplorer: Rework the build step run interface
Originally, the build manager used to run all build steps in a dedicated
thread. Communication between the step and the manager happened via a
QFutureInterface that was passed into the step's run() function.
Later, new steps were added that operated asynchronously, so the build
manager had to differentiate between the different kinds of steps for
starting and stopping.
These days, almost all build and deploy steps work asynchronously, which
made the QFuture-based interface look increasingly odd.
With this patch, all build steps are expected to work asynchronously, so
the build manager no longer needs to differentiate. Steps are started
and requested to stop via the run() and cancel() functions,
respectively, and emit the finished() signal when they are done. Build
step implementors no longer have to deal with a QFutureInterface. For
steps whose implementation is inherently synchronous, the BuildStep base
class offers a runInThread() function.
Change-Id: If905c68b234c5a669f6e19f43142eaa57d594803
Reviewed-by: hjk <hjk@qt.io>
2019-01-25 14:26:34 +01:00
|
|
|
void TarPackageCreationStep::doRun()
|
2011-07-15 16:57:25 +02:00
|
|
|
{
|
2022-11-08 15:08:21 +01:00
|
|
|
m_synchronizer.addFuture(runInThread([this] { return runImpl(); }));
|
2011-07-15 16:57:25 +02:00
|
|
|
}
|
|
|
|
|
|
2022-05-27 16:51:04 +02:00
|
|
|
bool TarPackageCreationStep::fromMap(const QVariantMap &map)
|
|
|
|
|
{
|
|
|
|
|
if (!BuildStep::fromMap(map))
|
|
|
|
|
return false;
|
2022-07-01 17:29:29 +02:00
|
|
|
m_deployTimes.importDeployTimes(map);
|
2022-05-27 16:51:04 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariantMap TarPackageCreationStep::toMap() const
|
|
|
|
|
{
|
|
|
|
|
QVariantMap map = BuildStep::toMap();
|
2022-07-01 17:29:29 +02:00
|
|
|
map.insert(m_deployTimes.exportDeployTimes());
|
2022-05-27 16:51:04 +02:00
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-01 17:29:29 +02:00
|
|
|
QVariant TarPackageCreationStep::data(Id id) const
|
|
|
|
|
{
|
|
|
|
|
if (id == Constants::TarPackageFilePathId)
|
|
|
|
|
return packageFilePath().toVariant();
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-27 16:51:04 +02:00
|
|
|
void TarPackageCreationStep::raiseError(const QString &errorMessage)
|
|
|
|
|
{
|
|
|
|
|
emit addTask(DeploymentTask(Task::Error, errorMessage));
|
2022-07-01 17:29:29 +02:00
|
|
|
emit addOutput(errorMessage, OutputFormat::Stderr);
|
2022-05-27 16:51:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TarPackageCreationStep::raiseWarning(const QString &warningMessage)
|
|
|
|
|
{
|
|
|
|
|
emit addTask(DeploymentTask(Task::Warning, warningMessage));
|
|
|
|
|
emit addOutput(warningMessage, OutputFormat::ErrorMessage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TarPackageCreationStep::isPackagingNeeded() const
|
|
|
|
|
{
|
|
|
|
|
const FilePath packagePath = packageFilePath();
|
2022-07-01 17:29:29 +02:00
|
|
|
if (!packagePath.exists() || m_deploymentDataModified)
|
2022-05-27 16:51:04 +02:00
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
const DeploymentData &dd = target()->deploymentData();
|
|
|
|
|
for (int i = 0; i < dd.fileCount(); ++i) {
|
|
|
|
|
if (dd.fileAt(i).localFilePath().isNewerThan(packagePath.lastModified()))
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TarPackageCreationStep::deployFinished(bool success)
|
|
|
|
|
{
|
|
|
|
|
disconnect(BuildManager::instance(), &BuildManager::buildQueueFinished,
|
|
|
|
|
this, &TarPackageCreationStep::deployFinished);
|
|
|
|
|
|
|
|
|
|
if (!success)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const Kit *kit = target()->kit();
|
|
|
|
|
|
|
|
|
|
// Store files that have been tar'd and successfully deployed
|
2022-10-07 14:46:06 +02:00
|
|
|
for (const DeployableFile &file : std::as_const(m_files))
|
2022-07-01 17:29:29 +02:00
|
|
|
m_deployTimes.saveDeploymentTimeStamp(file, kit, QDateTime());
|
2022-05-27 16:51:04 +02:00
|
|
|
}
|
|
|
|
|
|
2016-12-25 12:31:12 -05:00
|
|
|
void TarPackageCreationStep::addNeededDeploymentFiles(
|
2022-07-01 17:29:29 +02:00
|
|
|
const DeployableFile &deployable,
|
|
|
|
|
const Kit *kit)
|
2016-12-25 12:31:12 -05:00
|
|
|
{
|
|
|
|
|
const QFileInfo fileInfo = deployable.localFilePath().toFileInfo();
|
|
|
|
|
if (!fileInfo.isDir()) {
|
2022-07-01 17:29:29 +02:00
|
|
|
if (m_deployTimes.hasLocalFileChanged(deployable, kit))
|
|
|
|
|
m_files << deployable;
|
2016-12-25 12:31:12 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QStringList files = QDir(deployable.localFilePath().toString())
|
|
|
|
|
.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
|
|
|
|
|
|
|
|
|
|
if (files.isEmpty()) {
|
2022-07-01 17:29:29 +02:00
|
|
|
m_files << deployable;
|
2016-12-25 12:31:12 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const QString &fileName : files) {
|
2021-09-13 12:55:01 +02:00
|
|
|
const FilePath localFilePath = deployable.localFilePath().pathAppended(fileName);
|
2016-12-25 12:31:12 -05:00
|
|
|
|
|
|
|
|
const QString remoteDir = deployable.remoteDirectory() + '/' + fileInfo.fileName();
|
|
|
|
|
|
|
|
|
|
// Recurse through the subdirectories
|
|
|
|
|
addNeededDeploymentFiles(DeployableFile(localFilePath, remoteDir), kit);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-27 16:51:04 +02:00
|
|
|
bool TarPackageCreationStep::runImpl()
|
|
|
|
|
{
|
|
|
|
|
const QList<DeployableFile> &files = target()->deploymentData().allFiles();
|
|
|
|
|
|
2022-07-01 17:29:29 +02:00
|
|
|
if (m_incrementalDeploymentAspect->value()) {
|
|
|
|
|
m_files.clear();
|
2022-05-27 16:51:04 +02:00
|
|
|
for (const DeployableFile &file : files)
|
|
|
|
|
addNeededDeploymentFiles(file, kit());
|
|
|
|
|
} else {
|
2022-07-01 17:29:29 +02:00
|
|
|
m_files = files;
|
2022-05-27 16:51:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const bool success = doPackage();
|
|
|
|
|
|
|
|
|
|
if (success) {
|
2022-07-01 17:29:29 +02:00
|
|
|
m_deploymentDataModified = false;
|
2022-07-15 12:20:23 +02:00
|
|
|
emit addOutput(Tr::tr("Packaging finished successfully."), OutputFormat::NormalMessage);
|
2022-05-27 16:51:04 +02:00
|
|
|
} else {
|
2022-07-15 12:20:23 +02:00
|
|
|
emit addOutput(Tr::tr("Packaging failed."), OutputFormat::ErrorMessage);
|
2022-05-27 16:51:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
connect(BuildManager::instance(), &BuildManager::buildQueueFinished,
|
|
|
|
|
this, &TarPackageCreationStep::deployFinished);
|
|
|
|
|
|
|
|
|
|
return success;
|
|
|
|
|
}
|
|
|
|
|
|
ProjectExplorer: Rework the build step run interface
Originally, the build manager used to run all build steps in a dedicated
thread. Communication between the step and the manager happened via a
QFutureInterface that was passed into the step's run() function.
Later, new steps were added that operated asynchronously, so the build
manager had to differentiate between the different kinds of steps for
starting and stopping.
These days, almost all build and deploy steps work asynchronously, which
made the QFuture-based interface look increasingly odd.
With this patch, all build steps are expected to work asynchronously, so
the build manager no longer needs to differentiate. Steps are started
and requested to stop via the run() and cancel() functions,
respectively, and emit the finished() signal when they are done. Build
step implementors no longer have to deal with a QFutureInterface. For
steps whose implementation is inherently synchronous, the BuildStep base
class offers a runInThread() function.
Change-Id: If905c68b234c5a669f6e19f43142eaa57d594803
Reviewed-by: hjk <hjk@qt.io>
2019-01-25 14:26:34 +01:00
|
|
|
bool TarPackageCreationStep::doPackage()
|
2011-07-15 16:57:25 +02:00
|
|
|
{
|
2022-07-15 12:20:23 +02:00
|
|
|
emit addOutput(Tr::tr("Creating tarball..."), OutputFormat::NormalMessage);
|
2022-07-01 17:29:29 +02:00
|
|
|
if (!m_packagingNeeded) {
|
2022-07-15 12:20:23 +02:00
|
|
|
emit addOutput(Tr::tr("Tarball up to date, skipping packaging."), OutputFormat::NormalMessage);
|
2011-07-15 16:57:25 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: Optimization: Only package changed files
|
2022-07-01 17:29:29 +02:00
|
|
|
const FilePath tarFilePath = m_cachedPackageFilePath;
|
2021-10-27 12:00:41 +02:00
|
|
|
QFile tarFile(tarFilePath.toString());
|
2011-07-15 16:57:25 +02:00
|
|
|
|
|
|
|
|
if (!tarFile.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
|
2022-07-15 12:20:23 +02:00
|
|
|
raiseError(Tr::tr("Error: tar file %1 cannot be opened (%2).")
|
2021-10-27 12:00:41 +02:00
|
|
|
.arg(tarFilePath.toUserOutput(), tarFile.errorString()));
|
2011-07-15 16:57:25 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-07 14:46:06 +02:00
|
|
|
for (const DeployableFile &d : std::as_const(m_files)) {
|
2012-08-22 16:52:38 +02:00
|
|
|
if (d.remoteDirectory().isEmpty()) {
|
2022-07-15 12:20:23 +02:00
|
|
|
emit addOutput(Tr::tr("No remote path specified for file \"%1\", skipping.")
|
2017-01-12 10:59:12 +01:00
|
|
|
.arg(d.localFilePath().toUserOutput()), OutputFormat::ErrorMessage);
|
2011-10-24 17:58:53 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
2012-08-22 16:52:38 +02:00
|
|
|
QFileInfo fileInfo = d.localFilePath().toFileInfo();
|
|
|
|
|
if (!appendFile(tarFile, fileInfo, d.remoteDirectory() + QLatin1Char('/')
|
ProjectExplorer: Rework the build step run interface
Originally, the build manager used to run all build steps in a dedicated
thread. Communication between the step and the manager happened via a
QFutureInterface that was passed into the step's run() function.
Later, new steps were added that operated asynchronously, so the build
manager had to differentiate between the different kinds of steps for
starting and stopping.
These days, almost all build and deploy steps work asynchronously, which
made the QFuture-based interface look increasingly odd.
With this patch, all build steps are expected to work asynchronously, so
the build manager no longer needs to differentiate. Steps are started
and requested to stop via the run() and cancel() functions,
respectively, and emit the finished() signal when they are done. Build
step implementors no longer have to deal with a QFutureInterface. For
steps whose implementation is inherently synchronous, the BuildStep base
class offers a runInThread() function.
Change-Id: If905c68b234c5a669f6e19f43142eaa57d594803
Reviewed-by: hjk <hjk@qt.io>
2019-01-25 14:26:34 +01:00
|
|
|
+ fileInfo.fileName())) {
|
2011-07-15 16:57:25 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QByteArray eofIndicator(2*sizeof(TarFileHeader), 0);
|
|
|
|
|
if (tarFile.write(eofIndicator) != eofIndicator.length()) {
|
2022-07-15 12:20:23 +02:00
|
|
|
raiseError(Tr::tr("Error writing tar file \"%1\": %2.")
|
2011-07-15 16:57:25 +02:00
|
|
|
.arg(QDir::toNativeSeparators(tarFile.fileName()), tarFile.errorString()));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-08 14:37:24 +02:00
|
|
|
static bool setFilePath(TarFileHeader &header, const QByteArray &filePath)
|
|
|
|
|
{
|
|
|
|
|
if (filePath.length() <= int(sizeof header.fileName)) {
|
|
|
|
|
std::memcpy(&header.fileName, filePath.data(), filePath.length());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
int sepIndex = filePath.indexOf('/');
|
|
|
|
|
while (sepIndex != -1) {
|
|
|
|
|
const int fileNamePart = filePath.length() - sepIndex;
|
|
|
|
|
if (sepIndex <= int(sizeof header.fileNamePrefix)
|
|
|
|
|
&& fileNamePart <= int(sizeof header.fileName)) {
|
|
|
|
|
std::memcpy(&header.fileNamePrefix, filePath.data(), sepIndex);
|
|
|
|
|
std::memcpy(&header.fileName, filePath.data() + sepIndex + 1, fileNamePart);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
sepIndex = filePath.indexOf('/', sepIndex + 1);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-27 16:51:04 +02:00
|
|
|
static bool writeHeader(QFile &tarFile, const QFileInfo &fileInfo, const QString &remoteFilePath,
|
|
|
|
|
const QString &cachedPackageFilePath, QString *errorMessage)
|
2011-07-15 16:57:25 +02:00
|
|
|
{
|
|
|
|
|
TarFileHeader header;
|
2012-09-20 14:25:01 +02:00
|
|
|
std::memset(&header, '\0', sizeof header);
|
2019-08-08 14:37:24 +02:00
|
|
|
if (!setFilePath(header, remoteFilePath.toUtf8())) {
|
2022-07-15 12:20:23 +02:00
|
|
|
*errorMessage = Tr::tr("Cannot add file \"%1\" to tar-archive: path too long.")
|
|
|
|
|
.arg(remoteFilePath);
|
2011-07-15 16:57:25 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
int permissions = (0400 * fileInfo.permission(QFile::ReadOwner))
|
|
|
|
|
| (0200 * fileInfo.permission(QFile::WriteOwner))
|
|
|
|
|
| (0100 * fileInfo.permission(QFile::ExeOwner))
|
|
|
|
|
| (040 * fileInfo.permission(QFile::ReadGroup))
|
|
|
|
|
| (020 * fileInfo.permission(QFile::WriteGroup))
|
|
|
|
|
| (010 * fileInfo.permission(QFile::ExeGroup))
|
|
|
|
|
| (04 * fileInfo.permission(QFile::ReadOther))
|
|
|
|
|
| (02 * fileInfo.permission(QFile::WriteOther))
|
|
|
|
|
| (01 * fileInfo.permission(QFile::ExeOther));
|
2012-11-26 14:41:39 +02:00
|
|
|
const QByteArray permissionString = QString::fromLatin1("%1").arg(permissions,
|
2012-09-21 13:54:38 +02:00
|
|
|
sizeof header.fileMode - 1, 8, QLatin1Char('0')).toLatin1();
|
2012-09-20 14:25:01 +02:00
|
|
|
std::memcpy(&header.fileMode, permissionString.data(), permissionString.length());
|
2012-11-26 14:41:39 +02:00
|
|
|
const QByteArray uidString = QString::fromLatin1("%1").arg(fileInfo.ownerId(),
|
2012-09-21 13:54:38 +02:00
|
|
|
sizeof header.uid - 1, 8, QLatin1Char('0')).toLatin1();
|
2012-09-20 14:25:01 +02:00
|
|
|
std::memcpy(&header.uid, uidString.data(), uidString.length());
|
2012-11-26 14:41:39 +02:00
|
|
|
const QByteArray gidString = QString::fromLatin1("%1").arg(fileInfo.groupId(),
|
2012-09-21 13:54:38 +02:00
|
|
|
sizeof header.gid - 1, 8, QLatin1Char('0')).toLatin1();
|
2012-09-20 14:25:01 +02:00
|
|
|
std::memcpy(&header.gid, gidString.data(), gidString.length());
|
2012-11-26 14:41:39 +02:00
|
|
|
const QByteArray sizeString = QString::fromLatin1("%1").arg(fileInfo.size(),
|
2012-09-21 13:54:38 +02:00
|
|
|
sizeof header.length - 1, 8, QLatin1Char('0')).toLatin1();
|
2012-09-20 14:25:01 +02:00
|
|
|
std::memcpy(&header.length, sizeString.data(), sizeString.length());
|
2018-09-21 02:09:11 +03:00
|
|
|
const QByteArray mtimeString = QString::fromLatin1("%1").arg(
|
|
|
|
|
fileInfo.lastModified().toSecsSinceEpoch(),
|
|
|
|
|
sizeof header.mtime - 1, 8, QLatin1Char('0')).toLatin1();
|
2012-09-20 14:25:01 +02:00
|
|
|
std::memcpy(&header.mtime, mtimeString.data(), mtimeString.length());
|
2011-07-15 16:57:25 +02:00
|
|
|
if (fileInfo.isDir())
|
|
|
|
|
header.typeflag = '5';
|
2012-09-20 14:25:01 +02:00
|
|
|
std::memcpy(&header.magic, "ustar", sizeof "ustar");
|
|
|
|
|
std::memcpy(&header.version, "00", 2);
|
2011-07-15 16:57:25 +02:00
|
|
|
const QByteArray &owner = fileInfo.owner().toUtf8();
|
2012-09-20 14:25:01 +02:00
|
|
|
std::memcpy(&header.uname, owner.data(), qMin<int>(owner.length(), sizeof header.uname - 1));
|
2011-07-15 16:57:25 +02:00
|
|
|
const QByteArray &group = fileInfo.group().toUtf8();
|
2012-09-20 14:25:01 +02:00
|
|
|
std::memcpy(&header.gname, group.data(), qMin<int>(group.length(), sizeof header.gname - 1));
|
|
|
|
|
std::memset(&header.chksum, ' ', sizeof header.chksum);
|
2011-07-15 16:57:25 +02:00
|
|
|
quint64 checksum = 0;
|
|
|
|
|
for (size_t i = 0; i < sizeof header; ++i)
|
|
|
|
|
checksum += reinterpret_cast<char *>(&header)[i];
|
2012-11-26 14:41:39 +02:00
|
|
|
const QByteArray checksumString = QString::fromLatin1("%1").arg(checksum,
|
2012-09-21 13:54:38 +02:00
|
|
|
sizeof header.chksum - 1, 8, QLatin1Char('0')).toLatin1();
|
2012-09-20 14:25:01 +02:00
|
|
|
std::memcpy(&header.chksum, checksumString.data(), checksumString.length());
|
2011-07-15 16:57:25 +02:00
|
|
|
header.chksum[sizeof header.chksum-1] = 0;
|
|
|
|
|
if (!tarFile.write(reinterpret_cast<char *>(&header), sizeof header)) {
|
2022-07-15 12:20:23 +02:00
|
|
|
*errorMessage = Tr::tr("Error writing tar file \"%1\": %2")
|
|
|
|
|
.arg(cachedPackageFilePath, tarFile.errorString());
|
2011-07-15 16:57:25 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-27 16:51:04 +02:00
|
|
|
bool TarPackageCreationStep::appendFile(QFile &tarFile, const QFileInfo &fileInfo,
|
|
|
|
|
const QString &remoteFilePath)
|
ProjectExplorer: Rework the build step run interface
Originally, the build manager used to run all build steps in a dedicated
thread. Communication between the step and the manager happened via a
QFutureInterface that was passed into the step's run() function.
Later, new steps were added that operated asynchronously, so the build
manager had to differentiate between the different kinds of steps for
starting and stopping.
These days, almost all build and deploy steps work asynchronously, which
made the QFuture-based interface look increasingly odd.
With this patch, all build steps are expected to work asynchronously, so
the build manager no longer needs to differentiate. Steps are started
and requested to stop via the run() and cancel() functions,
respectively, and emit the finished() signal when they are done. Build
step implementors no longer have to deal with a QFutureInterface. For
steps whose implementation is inherently synchronous, the BuildStep base
class offers a runInThread() function.
Change-Id: If905c68b234c5a669f6e19f43142eaa57d594803
Reviewed-by: hjk <hjk@qt.io>
2019-01-25 14:26:34 +01:00
|
|
|
{
|
2022-05-27 16:51:04 +02:00
|
|
|
QString errorMessage;
|
2022-07-01 17:29:29 +02:00
|
|
|
if (!writeHeader(tarFile, fileInfo, remoteFilePath, m_cachedPackageFilePath.toUserOutput(),
|
2022-05-27 16:51:04 +02:00
|
|
|
&errorMessage)) {
|
|
|
|
|
raiseError(errorMessage);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (fileInfo.isDir()) {
|
2022-10-05 13:17:43 +02:00
|
|
|
const QDir dir(fileInfo.absoluteFilePath());
|
|
|
|
|
const QStringList files = dir.entryList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
|
|
|
|
|
for (const QString &fileName : files) {
|
2022-05-27 16:51:04 +02:00
|
|
|
const QString thisLocalFilePath = dir.path() + QLatin1Char('/') + fileName;
|
|
|
|
|
const QString thisRemoteFilePath = remoteFilePath + QLatin1Char('/') + fileName;
|
|
|
|
|
if (!appendFile(tarFile, QFileInfo(thisLocalFilePath), thisRemoteFilePath))
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
ProjectExplorer: Rework the build step run interface
Originally, the build manager used to run all build steps in a dedicated
thread. Communication between the step and the manager happened via a
QFutureInterface that was passed into the step's run() function.
Later, new steps were added that operated asynchronously, so the build
manager had to differentiate between the different kinds of steps for
starting and stopping.
These days, almost all build and deploy steps work asynchronously, which
made the QFuture-based interface look increasingly odd.
With this patch, all build steps are expected to work asynchronously, so
the build manager no longer needs to differentiate. Steps are started
and requested to stop via the run() and cancel() functions,
respectively, and emit the finished() signal when they are done. Build
step implementors no longer have to deal with a QFutureInterface. For
steps whose implementation is inherently synchronous, the BuildStep base
class offers a runInThread() function.
Change-Id: If905c68b234c5a669f6e19f43142eaa57d594803
Reviewed-by: hjk <hjk@qt.io>
2019-01-25 14:26:34 +01:00
|
|
|
|
2022-05-27 16:51:04 +02:00
|
|
|
const QString nativePath = QDir::toNativeSeparators(fileInfo.filePath());
|
|
|
|
|
QFile file(fileInfo.filePath());
|
|
|
|
|
if (!file.open(QIODevice::ReadOnly)) {
|
2022-07-15 12:20:23 +02:00
|
|
|
const QString message = Tr::tr("Error reading file \"%1\": %2.")
|
2022-05-27 16:51:04 +02:00
|
|
|
.arg(nativePath, file.errorString());
|
2022-07-01 17:29:29 +02:00
|
|
|
if (m_ignoreMissingFilesAspect->value()) {
|
2022-05-27 16:51:04 +02:00
|
|
|
raiseWarning(message);
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
raiseError(message);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
ProjectExplorer: Rework the build step run interface
Originally, the build manager used to run all build steps in a dedicated
thread. Communication between the step and the manager happened via a
QFutureInterface that was passed into the step's run() function.
Later, new steps were added that operated asynchronously, so the build
manager had to differentiate between the different kinds of steps for
starting and stopping.
These days, almost all build and deploy steps work asynchronously, which
made the QFuture-based interface look increasingly odd.
With this patch, all build steps are expected to work asynchronously, so
the build manager no longer needs to differentiate. Steps are started
and requested to stop via the run() and cancel() functions,
respectively, and emit the finished() signal when they are done. Build
step implementors no longer have to deal with a QFutureInterface. For
steps whose implementation is inherently synchronous, the BuildStep base
class offers a runInThread() function.
Change-Id: If905c68b234c5a669f6e19f43142eaa57d594803
Reviewed-by: hjk <hjk@qt.io>
2019-01-25 14:26:34 +01:00
|
|
|
}
|
|
|
|
|
|
2022-05-27 16:51:04 +02:00
|
|
|
const int chunkSize = 1024*1024;
|
ProjectExplorer: Rework the build step run interface
Originally, the build manager used to run all build steps in a dedicated
thread. Communication between the step and the manager happened via a
QFutureInterface that was passed into the step's run() function.
Later, new steps were added that operated asynchronously, so the build
manager had to differentiate between the different kinds of steps for
starting and stopping.
These days, almost all build and deploy steps work asynchronously, which
made the QFuture-based interface look increasingly odd.
With this patch, all build steps are expected to work asynchronously, so
the build manager no longer needs to differentiate. Steps are started
and requested to stop via the run() and cancel() functions,
respectively, and emit the finished() signal when they are done. Build
step implementors no longer have to deal with a QFutureInterface. For
steps whose implementation is inherently synchronous, the BuildStep base
class offers a runInThread() function.
Change-Id: If905c68b234c5a669f6e19f43142eaa57d594803
Reviewed-by: hjk <hjk@qt.io>
2019-01-25 14:26:34 +01:00
|
|
|
|
2022-07-15 12:20:23 +02:00
|
|
|
emit addOutput(Tr::tr("Adding file \"%1\" to tarball...").arg(nativePath),
|
2022-05-27 16:51:04 +02:00
|
|
|
OutputFormat::NormalMessage);
|
ProjectExplorer: Rework the build step run interface
Originally, the build manager used to run all build steps in a dedicated
thread. Communication between the step and the manager happened via a
QFutureInterface that was passed into the step's run() function.
Later, new steps were added that operated asynchronously, so the build
manager had to differentiate between the different kinds of steps for
starting and stopping.
These days, almost all build and deploy steps work asynchronously, which
made the QFuture-based interface look increasingly odd.
With this patch, all build steps are expected to work asynchronously, so
the build manager no longer needs to differentiate. Steps are started
and requested to stop via the run() and cancel() functions,
respectively, and emit the finished() signal when they are done. Build
step implementors no longer have to deal with a QFutureInterface. For
steps whose implementation is inherently synchronous, the BuildStep base
class offers a runInThread() function.
Change-Id: If905c68b234c5a669f6e19f43142eaa57d594803
Reviewed-by: hjk <hjk@qt.io>
2019-01-25 14:26:34 +01:00
|
|
|
|
2022-05-27 16:51:04 +02:00
|
|
|
// TODO: Wasteful. Work with fixed-size buffer.
|
|
|
|
|
while (!file.atEnd() && file.error() == QFile::NoError && tarFile.error() == QFile::NoError) {
|
|
|
|
|
const QByteArray data = file.read(chunkSize);
|
|
|
|
|
tarFile.write(data);
|
|
|
|
|
if (isCanceled())
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (file.error() != QFile::NoError) {
|
2022-07-15 12:20:23 +02:00
|
|
|
raiseError(Tr::tr("Error reading file \"%1\": %2.").arg(nativePath, file.errorString()));
|
2022-05-27 16:51:04 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
ProjectExplorer: Rework the build step run interface
Originally, the build manager used to run all build steps in a dedicated
thread. Communication between the step and the manager happened via a
QFutureInterface that was passed into the step's run() function.
Later, new steps were added that operated asynchronously, so the build
manager had to differentiate between the different kinds of steps for
starting and stopping.
These days, almost all build and deploy steps work asynchronously, which
made the QFuture-based interface look increasingly odd.
With this patch, all build steps are expected to work asynchronously, so
the build manager no longer needs to differentiate. Steps are started
and requested to stop via the run() and cancel() functions,
respectively, and emit the finished() signal when they are done. Build
step implementors no longer have to deal with a QFutureInterface. For
steps whose implementation is inherently synchronous, the BuildStep base
class offers a runInThread() function.
Change-Id: If905c68b234c5a669f6e19f43142eaa57d594803
Reviewed-by: hjk <hjk@qt.io>
2019-01-25 14:26:34 +01:00
|
|
|
|
2022-05-27 16:51:04 +02:00
|
|
|
const int blockModulo = file.size() % TarBlockSize;
|
|
|
|
|
if (blockModulo != 0)
|
|
|
|
|
tarFile.write(QByteArray(TarBlockSize - blockModulo, 0));
|
ProjectExplorer: Rework the build step run interface
Originally, the build manager used to run all build steps in a dedicated
thread. Communication between the step and the manager happened via a
QFutureInterface that was passed into the step's run() function.
Later, new steps were added that operated asynchronously, so the build
manager had to differentiate between the different kinds of steps for
starting and stopping.
These days, almost all build and deploy steps work asynchronously, which
made the QFuture-based interface look increasingly odd.
With this patch, all build steps are expected to work asynchronously, so
the build manager no longer needs to differentiate. Steps are started
and requested to stop via the run() and cancel() functions,
respectively, and emit the finished() signal when they are done. Build
step implementors no longer have to deal with a QFutureInterface. For
steps whose implementation is inherently synchronous, the BuildStep base
class offers a runInThread() function.
Change-Id: If905c68b234c5a669f6e19f43142eaa57d594803
Reviewed-by: hjk <hjk@qt.io>
2019-01-25 14:26:34 +01:00
|
|
|
|
2022-05-27 16:51:04 +02:00
|
|
|
if (tarFile.error() != QFile::NoError) {
|
2022-07-15 12:20:23 +02:00
|
|
|
raiseError(Tr::tr("Error writing tar file \"%1\": %2.")
|
2022-05-27 16:51:04 +02:00
|
|
|
.arg(QDir::toNativeSeparators(tarFile.fileName()), tarFile.errorString()));
|
2013-09-16 15:52:25 +02:00
|
|
|
return false;
|
2022-05-27 16:51:04 +02:00
|
|
|
}
|
2013-09-16 15:52:25 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-01 17:29:29 +02:00
|
|
|
TarPackageCreationStepFactory::TarPackageCreationStepFactory()
|
|
|
|
|
{
|
|
|
|
|
registerStep<TarPackageCreationStep>(Constants::TarPackageCreationStepId);
|
|
|
|
|
setDisplayName(Tr::tr("Create tarball"));
|
|
|
|
|
|
|
|
|
|
setSupportedConfiguration(RemoteLinux::Constants::DeployToGenericLinux);
|
|
|
|
|
setSupportedStepList(ProjectExplorer::Constants::BUILDSTEPS_DEPLOY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // RemoteLinux::Internal
|