Make AbstractPackagingStep and derived classes thread safe

Change-Id: I30d412dde2484b756dd2f06ed0a7b5030c14c9eb
Reviewed-by: Christian Kandeler <christian.kandeler@nokia.com>
This commit is contained in:
Daniel Teske
2011-10-13 18:53:49 +02:00
parent 2c2a8a7889
commit 487b56b0b7
6 changed files with 161 additions and 71 deletions

View File

@@ -114,6 +114,22 @@ void TarPackageCreationStep::ctor()
setDefaultDisplayName(displayName());
}
bool TarPackageCreationStep::init()
{
if (!AbstractPackagingStep::init())
return false;
m_packagingNeeded = isPackagingNeeded();
if (!m_packagingNeeded)
return true;
const QSharedPointer<DeploymentInfo> deploymentInfo = deployConfiguration()->deploymentInfo();
for (int i = 0; i < deploymentInfo->deployableCount(); ++i) {
m_files.append(deploymentInfo->deployableAt(i));
}
return true;
}
void TarPackageCreationStep::run(QFutureInterface<bool> &fi)
{
setPackagingStarted();
@@ -129,23 +145,21 @@ void TarPackageCreationStep::run(QFutureInterface<bool> &fi)
bool TarPackageCreationStep::doPackage(QFutureInterface<bool> &fi)
{
emit addOutput(tr("Creating tarball..."), MessageOutput);
if (!isPackagingNeeded()) {
if (!m_packagingNeeded) {
emit addOutput(tr("Tarball up to date, skipping packaging."), MessageOutput);
return true;
}
// TODO: Optimization: Only package changed files
QFile tarFile(packageFilePath());
QFile tarFile(cachedPackageFilePath());
if (!tarFile.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
raiseError(tr("Error: tar file %1 cannot be opened (%2).")
.arg(QDir::toNativeSeparators(packageFilePath()), tarFile.errorString()));
.arg(QDir::toNativeSeparators(cachedPackageFilePath()), tarFile.errorString()));
return false;
}
const QSharedPointer<DeploymentInfo> deploymentInfo = deployConfiguration()->deploymentInfo();
for (int i = 0; i < deploymentInfo->deployableCount(); ++i) {
const DeployableFile &d = deploymentInfo->deployableAt(i);
foreach (const DeployableFile &d, m_files) {
QFileInfo fileInfo(d.localFilePath);
if (!appendFile(tarFile, fileInfo, d.remoteDir + QLatin1Char('/')
+ fileInfo.fileName(), fi)) {
@@ -275,7 +289,7 @@ bool TarPackageCreationStep::writeHeader(QFile &tarFile, const QFileInfo &fileIn
header.chksum[sizeof header.chksum-1] = 0;
if (!tarFile.write(reinterpret_cast<char *>(&header), sizeof header)) {
raiseError(tr("Error writing tar file '%1': %2")
.arg(QDir::toNativeSeparators(packageFilePath()), tarFile.errorString()));
.arg(QDir::toNativeSeparators(cachedPackageFilePath()), tarFile.errorString()));
return false;
}
return true;