2010-08-10 15:05:21 +02:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
|
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
|
|
|
**
|
|
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** No Commercial Usage
|
2010-08-10 15:05:21 +02:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** This file contains pre-release code and may not be distributed.
|
|
|
|
|
** You may use this file in accordance with the terms and conditions
|
|
|
|
|
** contained in the Technology Preview License Agreement accompanying
|
|
|
|
|
** this package.
|
2010-08-10 15:05:21 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
** If you have questions regarding the use of this file, please contact
|
|
|
|
|
** Nokia at qt-info@nokia.com.
|
2010-08-10 15:05:21 +02:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "maemoremotemounter.h"
|
2010-08-10 15:42:12 +02:00
|
|
|
|
|
|
|
|
#include "maemoglobal.h"
|
2010-11-02 10:24:50 +01:00
|
|
|
#include "maemousedportsgatherer.h"
|
2010-08-10 15:05:21 +02:00
|
|
|
|
|
|
|
|
#include <coreplugin/ssh/sftpchannel.h>
|
|
|
|
|
#include <coreplugin/ssh/sshconnection.h>
|
|
|
|
|
#include <coreplugin/ssh/sshremoteprocess.h>
|
2011-01-04 14:14:12 +01:00
|
|
|
#include <qt4projectmanager/qt4buildconfiguration.h>
|
2010-10-01 11:49:55 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2010-08-10 15:05:21 +02:00
|
|
|
|
2010-08-17 14:49:51 +02:00
|
|
|
#include <QtCore/QTimer>
|
2010-08-10 15:05:21 +02:00
|
|
|
|
2010-10-29 12:17:56 +02:00
|
|
|
#define ASSERT_STATE(state) ASSERT_STATE_GENERIC(State, state, m_state)
|
2010-10-01 11:49:55 +02:00
|
|
|
|
2010-08-10 15:05:21 +02:00
|
|
|
using namespace Core;
|
|
|
|
|
|
|
|
|
|
namespace Qt4ProjectManager {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2010-08-23 15:54:35 +02:00
|
|
|
MaemoRemoteMounter::MaemoRemoteMounter(QObject *parent)
|
2010-11-11 12:08:13 +01:00
|
|
|
: QObject(parent), m_utfsServerTimer(new QTimer(this)),
|
2010-10-01 11:49:55 +02:00
|
|
|
m_uploadJobId(SftpInvalidJob), m_state(Inactive)
|
2010-08-10 15:05:21 +02:00
|
|
|
{
|
2010-08-17 14:49:51 +02:00
|
|
|
connect(m_utfsServerTimer, SIGNAL(timeout()), this,
|
|
|
|
|
SLOT(handleUtfsServerTimeout()));
|
2010-08-10 15:05:21 +02:00
|
|
|
}
|
|
|
|
|
|
2010-08-17 14:49:51 +02:00
|
|
|
MaemoRemoteMounter::~MaemoRemoteMounter()
|
|
|
|
|
{
|
|
|
|
|
killAllUtfsServers();
|
|
|
|
|
}
|
2010-08-10 15:05:21 +02:00
|
|
|
|
2010-11-11 12:08:13 +01:00
|
|
|
void MaemoRemoteMounter::setConnection(const SshConnection::Ptr &connection)
|
2010-08-10 15:05:21 +02:00
|
|
|
{
|
2010-10-01 11:49:55 +02:00
|
|
|
ASSERT_STATE(Inactive);
|
2010-08-10 15:05:21 +02:00
|
|
|
m_connection = connection;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-04 14:14:12 +01:00
|
|
|
void MaemoRemoteMounter::setBuildConfiguration(const Qt4BuildConfiguration *bc)
|
2010-11-11 12:08:13 +01:00
|
|
|
{
|
|
|
|
|
ASSERT_STATE(Inactive);
|
2011-01-04 14:14:12 +01:00
|
|
|
const QtVersion * const qtVersion = bc->qtVersion();
|
|
|
|
|
m_remoteMountsAllowed = MaemoGlobal::allowsRemoteMounts(qtVersion);
|
|
|
|
|
m_maddeRoot = MaemoGlobal::maddeRoot(qtVersion);
|
2010-11-11 12:08:13 +01:00
|
|
|
}
|
|
|
|
|
|
2010-11-02 14:18:12 +01:00
|
|
|
void MaemoRemoteMounter::addMountSpecification(const MaemoMountSpecification &mountSpec,
|
2010-08-11 16:31:59 +02:00
|
|
|
bool mountAsRoot)
|
2010-08-10 15:05:21 +02:00
|
|
|
{
|
2010-10-01 11:49:55 +02:00
|
|
|
ASSERT_STATE(Inactive);
|
|
|
|
|
|
2010-11-11 12:08:13 +01:00
|
|
|
if (m_remoteMountsAllowed && mountSpec.isValid())
|
2010-11-02 10:24:50 +01:00
|
|
|
m_mountSpecs << MountInfo(mountSpec, mountAsRoot);
|
2010-08-10 15:05:21 +02:00
|
|
|
}
|
|
|
|
|
|
2010-10-06 15:32:39 +02:00
|
|
|
bool MaemoRemoteMounter::hasValidMountSpecifications() const
|
|
|
|
|
{
|
|
|
|
|
return !m_mountSpecs.isEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-02 10:24:50 +01:00
|
|
|
void MaemoRemoteMounter::mount(MaemoPortList *freePorts,
|
|
|
|
|
const MaemoUsedPortsGatherer *portsGatherer)
|
2010-08-10 15:05:21 +02:00
|
|
|
{
|
2010-10-01 11:49:55 +02:00
|
|
|
ASSERT_STATE(Inactive);
|
2010-08-19 17:03:36 +02:00
|
|
|
Q_ASSERT(m_utfsServers.isEmpty());
|
2010-10-01 11:49:55 +02:00
|
|
|
Q_ASSERT(m_connection);
|
2010-08-10 15:05:21 +02:00
|
|
|
|
2010-10-01 11:49:55 +02:00
|
|
|
if (m_mountSpecs.isEmpty()) {
|
2010-10-01 15:49:09 +02:00
|
|
|
setState(Inactive);
|
2010-10-01 11:49:55 +02:00
|
|
|
emit reportProgress(tr("No directories to mount"));
|
2010-08-10 15:05:21 +02:00
|
|
|
emit mounted();
|
2010-10-01 11:49:55 +02:00
|
|
|
} else {
|
2010-11-02 10:24:50 +01:00
|
|
|
m_freePorts = freePorts;
|
|
|
|
|
m_portsGatherer = portsGatherer;
|
2010-08-10 15:05:21 +02:00
|
|
|
deployUtfsClient();
|
2010-10-01 11:49:55 +02:00
|
|
|
}
|
2010-08-10 15:05:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaemoRemoteMounter::unmount()
|
|
|
|
|
{
|
2010-10-01 11:49:55 +02:00
|
|
|
ASSERT_STATE(Inactive);
|
|
|
|
|
|
2010-08-10 15:05:21 +02:00
|
|
|
if (m_mountSpecs.isEmpty()) {
|
2010-10-01 11:49:55 +02:00
|
|
|
emit reportProgress(tr("No directories to unmount"));
|
2010-08-10 15:05:21 +02:00
|
|
|
emit unmounted();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString remoteCall;
|
|
|
|
|
for (int i = 0; i < m_mountSpecs.count(); ++i) {
|
2010-10-29 11:41:39 +02:00
|
|
|
remoteCall += QString::fromLocal8Bit("%1 umount %2 && %1 rmdir %2;")
|
2010-08-10 15:05:21 +02:00
|
|
|
.arg(MaemoGlobal::remoteSudo(),
|
2010-08-11 16:31:59 +02:00
|
|
|
m_mountSpecs.at(i).mountSpec.remoteMountPoint);
|
2010-08-10 15:05:21 +02:00
|
|
|
}
|
|
|
|
|
|
2010-08-10 15:42:12 +02:00
|
|
|
m_umountStderr.clear();
|
2010-08-10 15:05:21 +02:00
|
|
|
m_unmountProcess = m_connection->createRemoteProcess(remoteCall.toUtf8());
|
|
|
|
|
connect(m_unmountProcess.data(), SIGNAL(closed(int)), this,
|
|
|
|
|
SLOT(handleUnmountProcessFinished(int)));
|
|
|
|
|
connect(m_unmountProcess.data(), SIGNAL(errorOutputAvailable(QByteArray)),
|
2010-08-10 15:42:12 +02:00
|
|
|
this, SLOT(handleUmountStderr(QByteArray)));
|
2010-10-01 15:49:09 +02:00
|
|
|
setState(Unmounting);
|
2010-08-10 15:05:21 +02:00
|
|
|
m_unmountProcess->start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaemoRemoteMounter::handleUnmountProcessFinished(int exitStatus)
|
|
|
|
|
{
|
2010-10-01 11:49:55 +02:00
|
|
|
ASSERT_STATE(QList<State>() << Unmounting << Inactive);
|
|
|
|
|
|
|
|
|
|
if (m_state == Inactive)
|
2010-08-10 15:05:21 +02:00
|
|
|
return;
|
2010-10-01 15:49:09 +02:00
|
|
|
setState(Inactive);
|
2010-08-10 15:05:21 +02:00
|
|
|
|
|
|
|
|
QString errorMsg;
|
|
|
|
|
switch (exitStatus) {
|
|
|
|
|
case SshRemoteProcess::FailedToStart:
|
|
|
|
|
errorMsg = tr("Could not execute unmount request.");
|
|
|
|
|
break;
|
|
|
|
|
case SshRemoteProcess::KilledBySignal:
|
|
|
|
|
errorMsg = tr("Failure unmounting: %1")
|
|
|
|
|
.arg(m_unmountProcess->errorString());
|
|
|
|
|
break;
|
|
|
|
|
case SshRemoteProcess::ExitedNormally:
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
Q_ASSERT_X(false, Q_FUNC_INFO,
|
|
|
|
|
"Impossible SshRemoteProcess exit status.");
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-17 14:49:51 +02:00
|
|
|
killAllUtfsServers();
|
2010-08-10 15:05:21 +02:00
|
|
|
|
2010-08-10 15:42:12 +02:00
|
|
|
if (errorMsg.isEmpty()) {
|
2010-08-10 16:26:41 +02:00
|
|
|
emit reportProgress(tr("Finished unmounting."));
|
2010-08-10 15:05:21 +02:00
|
|
|
emit unmounted();
|
2010-08-10 15:42:12 +02:00
|
|
|
} else {
|
|
|
|
|
if (!m_umountStderr.isEmpty()) {
|
|
|
|
|
errorMsg += tr("\nstderr was: '%1'")
|
|
|
|
|
.arg(QString::fromUtf8(m_umountStderr));
|
|
|
|
|
}
|
2010-08-10 15:05:21 +02:00
|
|
|
emit error(errorMsg);
|
2010-08-10 15:42:12 +02:00
|
|
|
}
|
2010-08-10 15:05:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaemoRemoteMounter::stop()
|
|
|
|
|
{
|
2010-10-01 15:49:09 +02:00
|
|
|
setState(Inactive);
|
2010-08-10 15:05:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaemoRemoteMounter::deployUtfsClient()
|
|
|
|
|
{
|
2010-08-10 15:59:37 +02:00
|
|
|
emit reportProgress(tr("Setting up SFTP connection..."));
|
2010-08-10 15:05:21 +02:00
|
|
|
m_utfsClientUploader = m_connection->createSftpChannel();
|
|
|
|
|
connect(m_utfsClientUploader.data(), SIGNAL(initialized()), this,
|
|
|
|
|
SLOT(handleUploaderInitialized()));
|
|
|
|
|
connect(m_utfsClientUploader.data(), SIGNAL(initializationFailed(QString)),
|
|
|
|
|
this, SLOT(handleUploaderInitializationFailed(QString)));
|
|
|
|
|
m_utfsClientUploader->initialize();
|
2010-10-01 11:49:55 +02:00
|
|
|
|
2010-10-01 15:49:09 +02:00
|
|
|
setState(UploaderInitializing);
|
2010-08-10 15:05:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaemoRemoteMounter::handleUploaderInitializationFailed(const QString &reason)
|
|
|
|
|
{
|
2010-10-01 11:49:55 +02:00
|
|
|
ASSERT_STATE(QList<State>() << UploaderInitializing << Inactive);
|
2010-08-10 15:05:21 +02:00
|
|
|
|
2010-10-01 11:49:55 +02:00
|
|
|
if (m_state == UploaderInitializing) {
|
|
|
|
|
emit error(tr("Failed to establish SFTP connection: %1").arg(reason));
|
2010-10-01 15:49:09 +02:00
|
|
|
setState(Inactive);
|
2010-10-01 11:49:55 +02:00
|
|
|
}
|
2010-08-10 15:05:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaemoRemoteMounter::handleUploaderInitialized()
|
|
|
|
|
{
|
2010-10-01 11:49:55 +02:00
|
|
|
ASSERT_STATE(QList<State>() << UploaderInitializing << Inactive);
|
|
|
|
|
if (m_state == Inactive)
|
2010-08-10 15:05:21 +02:00
|
|
|
return;
|
|
|
|
|
|
2010-08-10 15:59:37 +02:00
|
|
|
emit reportProgress(tr("Uploading UTFS client..."));
|
2010-08-10 15:05:21 +02:00
|
|
|
connect(m_utfsClientUploader.data(),
|
|
|
|
|
SIGNAL(finished(Core::SftpJobId, QString)), this,
|
|
|
|
|
SLOT(handleUploadFinished(Core::SftpJobId, QString)));
|
|
|
|
|
const QString localFile
|
2010-11-11 12:08:13 +01:00
|
|
|
= m_maddeRoot + QLatin1String("/madlib/armel/utfs-client");
|
2010-08-10 15:59:37 +02:00
|
|
|
m_uploadJobId = m_utfsClientUploader->uploadFile(localFile,
|
|
|
|
|
utfsClientOnDevice(), SftpOverwriteExisting);
|
2010-10-01 11:49:55 +02:00
|
|
|
if (m_uploadJobId == SftpInvalidJob) {
|
2010-10-01 15:49:09 +02:00
|
|
|
setState(Inactive);
|
2010-08-10 15:05:21 +02:00
|
|
|
emit error(tr("Could not upload UTFS client (%1).").arg(localFile));
|
2010-10-01 15:49:09 +02:00
|
|
|
} else {
|
|
|
|
|
setState(UploadRunning);
|
2010-10-01 11:49:55 +02:00
|
|
|
}
|
2010-08-10 15:05:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaemoRemoteMounter::handleUploadFinished(Core::SftpJobId jobId,
|
|
|
|
|
const QString &errorMsg)
|
|
|
|
|
{
|
2010-10-01 11:49:55 +02:00
|
|
|
ASSERT_STATE(QList<State>() << UploadRunning << Inactive);
|
|
|
|
|
|
|
|
|
|
if (m_state == Inactive)
|
2010-08-10 15:05:21 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (jobId != m_uploadJobId) {
|
|
|
|
|
qWarning("Warning: unknown upload job %d finished.", jobId);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_uploadJobId = SftpInvalidJob;
|
|
|
|
|
if (!errorMsg.isEmpty()) {
|
2010-10-06 14:55:38 +02:00
|
|
|
emit reportProgress(tr("Could not upload UTFS client (%1), continuing anyway.")
|
|
|
|
|
.arg(errorMsg));
|
2010-08-10 15:05:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
startUtfsClients();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaemoRemoteMounter::startUtfsClients()
|
|
|
|
|
{
|
|
|
|
|
const QString chmodFuse
|
|
|
|
|
= MaemoGlobal::remoteSudo() + QLatin1String(" chmod a+r+w /dev/fuse");
|
|
|
|
|
const QString chmodUtfsClient
|
|
|
|
|
= QLatin1String("chmod a+x ") + utfsClientOnDevice();
|
|
|
|
|
const QLatin1String andOp(" && ");
|
|
|
|
|
QString remoteCall = chmodFuse + andOp + chmodUtfsClient;
|
|
|
|
|
for (int i = 0; i < m_mountSpecs.count(); ++i) {
|
2010-11-02 10:24:50 +01:00
|
|
|
MountInfo &mountInfo = m_mountSpecs[i];
|
|
|
|
|
mountInfo.remotePort
|
|
|
|
|
= m_portsGatherer->getNextFreePort(m_freePorts);
|
|
|
|
|
if (mountInfo.remotePort == -1) {
|
|
|
|
|
setState(Inactive);
|
|
|
|
|
emit error(tr("Error: Not enough free ports on device to fulfill all mount requests."));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-13 15:25:22 +02:00
|
|
|
const MaemoMountSpecification &mountSpec = mountInfo.mountSpec;
|
2010-08-10 15:05:21 +02:00
|
|
|
const QString mkdir = QString::fromLocal8Bit("%1 mkdir -p %2")
|
|
|
|
|
.arg(MaemoGlobal::remoteSudo(), mountSpec.remoteMountPoint);
|
|
|
|
|
const QString chmod = QString::fromLocal8Bit("%1 chmod a+r+w+x %2")
|
|
|
|
|
.arg(MaemoGlobal::remoteSudo(), mountSpec.remoteMountPoint);
|
2010-08-11 16:31:59 +02:00
|
|
|
QString utfsClient
|
2010-08-20 12:50:10 +02:00
|
|
|
= QString::fromLocal8Bit("%1 -l %2 -r %2 -b %2 %4 -o nonempty")
|
2010-08-13 15:25:22 +02:00
|
|
|
.arg(utfsClientOnDevice()).arg(mountInfo.remotePort)
|
2010-08-10 15:05:21 +02:00
|
|
|
.arg(mountSpec.remoteMountPoint);
|
2010-08-13 15:25:22 +02:00
|
|
|
if (mountInfo.mountAsRoot)
|
2010-08-11 16:31:59 +02:00
|
|
|
utfsClient.prepend(MaemoGlobal::remoteSudo() + QLatin1Char(' '));
|
2010-09-13 16:50:30 +02:00
|
|
|
QLatin1String seqOp("; ");
|
|
|
|
|
remoteCall += seqOp + MaemoGlobal::remoteSourceProfilesCommand()
|
|
|
|
|
+ seqOp + mkdir + andOp + chmod + andOp + utfsClient;
|
2010-08-10 15:05:21 +02:00
|
|
|
}
|
|
|
|
|
|
2010-08-10 15:59:37 +02:00
|
|
|
emit reportProgress(tr("Starting remote UTFS clients..."));
|
2010-08-10 15:42:12 +02:00
|
|
|
m_utfsClientStderr.clear();
|
2010-08-10 15:05:21 +02:00
|
|
|
m_mountProcess = m_connection->createRemoteProcess(remoteCall.toUtf8());
|
2010-08-19 17:03:36 +02:00
|
|
|
connect(m_mountProcess.data(), SIGNAL(started()), this,
|
|
|
|
|
SLOT(handleUtfsClientsStarted()));
|
2010-08-10 15:05:21 +02:00
|
|
|
connect(m_mountProcess.data(), SIGNAL(closed(int)), this,
|
|
|
|
|
SLOT(handleUtfsClientsFinished(int)));
|
|
|
|
|
connect(m_mountProcess.data(), SIGNAL(errorOutputAvailable(QByteArray)),
|
2010-08-10 15:42:12 +02:00
|
|
|
this, SLOT(handleUtfsClientStderr(QByteArray)));
|
2010-08-10 15:05:21 +02:00
|
|
|
m_mountProcess->start();
|
2010-10-01 11:49:55 +02:00
|
|
|
|
2010-10-01 15:49:09 +02:00
|
|
|
setState(UtfsClientsStarting);
|
2010-08-10 15:05:21 +02:00
|
|
|
}
|
|
|
|
|
|
2010-08-19 17:03:36 +02:00
|
|
|
void MaemoRemoteMounter::handleUtfsClientsStarted()
|
|
|
|
|
{
|
2010-10-01 11:49:55 +02:00
|
|
|
ASSERT_STATE(QList<State>() << UtfsClientsStarting << Inactive);
|
|
|
|
|
if (m_state == UtfsClientsStarting) {
|
2010-10-01 15:49:09 +02:00
|
|
|
setState(UtfsClientsStarted);
|
2010-08-26 11:21:41 +02:00
|
|
|
QTimer::singleShot(250, this, SLOT(startUtfsServers()));
|
2010-10-01 11:49:55 +02:00
|
|
|
}
|
2010-08-19 17:03:36 +02:00
|
|
|
}
|
|
|
|
|
|
2010-08-10 15:05:21 +02:00
|
|
|
void MaemoRemoteMounter::handleUtfsClientsFinished(int exitStatus)
|
|
|
|
|
{
|
2010-10-01 11:49:55 +02:00
|
|
|
ASSERT_STATE(QList<State>() << UtfsClientsStarting << UtfsClientsStarted
|
|
|
|
|
<< UtfsServersStarted << Inactive);
|
|
|
|
|
|
|
|
|
|
if (m_state == Inactive)
|
2010-08-10 15:05:21 +02:00
|
|
|
return;
|
|
|
|
|
|
2010-10-01 15:49:09 +02:00
|
|
|
setState(Inactive);
|
2010-08-12 12:24:11 +02:00
|
|
|
if (exitStatus == SshRemoteProcess::ExitedNormally
|
|
|
|
|
&& m_mountProcess->exitCode() == 0) {
|
2010-10-01 11:49:55 +02:00
|
|
|
emit reportProgress(tr("Mount operation succeeded."));
|
2010-08-19 17:03:36 +02:00
|
|
|
emit mounted();
|
2010-08-12 12:24:11 +02:00
|
|
|
} else {
|
|
|
|
|
QString errMsg = tr("Failure running UTFS client: %1")
|
2010-08-10 15:42:12 +02:00
|
|
|
.arg(m_mountProcess->errorString());
|
|
|
|
|
if (!m_utfsClientStderr.isEmpty())
|
|
|
|
|
errMsg += tr("\nstderr was: '%1'")
|
|
|
|
|
.arg(QString::fromUtf8(m_utfsClientStderr));
|
|
|
|
|
emit error(errMsg);
|
|
|
|
|
}
|
2010-08-10 15:05:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaemoRemoteMounter::startUtfsServers()
|
|
|
|
|
{
|
2010-10-01 11:49:55 +02:00
|
|
|
ASSERT_STATE(QList<State>() << UtfsClientsStarted << Inactive);
|
|
|
|
|
|
|
|
|
|
if (m_state == Inactive)
|
2010-08-26 11:21:41 +02:00
|
|
|
return;
|
|
|
|
|
|
2010-08-10 15:59:37 +02:00
|
|
|
emit reportProgress(tr("Starting UTFS servers..."));
|
2010-08-17 14:49:51 +02:00
|
|
|
m_utfsServerTimer->start(30000);
|
2010-08-10 15:05:21 +02:00
|
|
|
for (int i = 0; i < m_mountSpecs.count(); ++i) {
|
2010-08-13 15:25:22 +02:00
|
|
|
const MountInfo &mountInfo = m_mountSpecs.at(i);
|
|
|
|
|
const MaemoMountSpecification &mountSpec = mountInfo.mountSpec;
|
2010-08-10 15:05:21 +02:00
|
|
|
const ProcPtr utfsServerProc(new QProcess);
|
2010-08-13 15:25:22 +02:00
|
|
|
const QString port = QString::number(mountInfo.remotePort);
|
2010-08-10 15:05:21 +02:00
|
|
|
const QString localSecretOpt = QLatin1String("-l");
|
|
|
|
|
const QString remoteSecretOpt = QLatin1String("-r");
|
2010-08-17 14:49:51 +02:00
|
|
|
const QStringList utfsServerArgs = QStringList() << localSecretOpt
|
|
|
|
|
<< port << remoteSecretOpt << port << QLatin1String("-c")
|
2010-08-11 16:31:59 +02:00
|
|
|
<< (m_connection->connectionParameters().host + QLatin1Char(':') + port)
|
2010-08-10 15:05:21 +02:00
|
|
|
<< mountSpec.localDir;
|
2010-08-17 14:49:51 +02:00
|
|
|
connect(utfsServerProc.data(),
|
|
|
|
|
SIGNAL(finished(int,QProcess::ExitStatus)), this,
|
|
|
|
|
SLOT(handleUtfsServerFinished(int,QProcess::ExitStatus)));
|
|
|
|
|
connect(utfsServerProc.data(), SIGNAL(error(QProcess::ProcessError)),
|
|
|
|
|
this, SLOT(handleUtfsServerError(QProcess::ProcessError)));
|
2010-08-26 11:17:40 +02:00
|
|
|
connect(utfsServerProc.data(), SIGNAL(readyReadStandardError()), this,
|
|
|
|
|
SLOT(handleUtfsServerStderr()));
|
2010-08-19 17:03:36 +02:00
|
|
|
m_utfsServers << utfsServerProc;
|
2010-08-10 15:05:21 +02:00
|
|
|
utfsServerProc->start(utfsServer(), utfsServerArgs);
|
2010-08-17 14:49:51 +02:00
|
|
|
}
|
2010-10-01 11:49:55 +02:00
|
|
|
|
2010-10-01 15:49:09 +02:00
|
|
|
setState(UtfsServersStarted);
|
2010-08-17 14:49:51 +02:00
|
|
|
}
|
|
|
|
|
|
2010-08-26 11:17:40 +02:00
|
|
|
void MaemoRemoteMounter::handleUtfsServerStderr()
|
|
|
|
|
{
|
2010-10-01 11:49:55 +02:00
|
|
|
if (m_state != Inactive) {
|
2010-08-26 11:17:40 +02:00
|
|
|
QProcess * const proc = static_cast<QProcess *>(sender());
|
|
|
|
|
const QByteArray &output = proc->readAllStandardError();
|
|
|
|
|
emit debugOutput(QString::fromLocal8Bit(output));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-19 17:03:36 +02:00
|
|
|
void MaemoRemoteMounter::handleUtfsServerError(QProcess::ProcessError)
|
2010-08-17 14:49:51 +02:00
|
|
|
{
|
2010-10-01 11:49:55 +02:00
|
|
|
if (m_state == Inactive || m_utfsServers.isEmpty())
|
2010-08-17 14:49:51 +02:00
|
|
|
return;
|
|
|
|
|
|
2010-08-19 17:03:36 +02:00
|
|
|
QProcess * const proc = static_cast<QProcess *>(sender());
|
|
|
|
|
QString errorString = proc->errorString();
|
|
|
|
|
const QByteArray &errorOutput = proc->readAllStandardError();
|
|
|
|
|
if (!errorOutput.isEmpty()) {
|
|
|
|
|
errorString += tr("\nstderr was: %1")
|
|
|
|
|
.arg(QString::fromLocal8Bit(errorOutput));
|
2010-08-10 15:05:21 +02:00
|
|
|
}
|
2010-08-19 17:03:36 +02:00
|
|
|
killAllUtfsServers();
|
|
|
|
|
emit error(tr("Error running UTFS server: %1").arg(errorString));
|
2010-10-01 11:49:55 +02:00
|
|
|
|
2010-10-01 15:49:09 +02:00
|
|
|
setState(Inactive);
|
2010-08-17 14:49:51 +02:00
|
|
|
}
|
|
|
|
|
|
2010-08-19 17:03:36 +02:00
|
|
|
void MaemoRemoteMounter::handleUtfsServerFinished(int /* exitCode */,
|
2010-08-17 14:49:51 +02:00
|
|
|
QProcess::ExitStatus exitStatus)
|
|
|
|
|
{
|
2010-10-01 11:49:55 +02:00
|
|
|
if (m_state != Inactive && exitStatus != QProcess::NormalExit)
|
2010-08-19 17:03:36 +02:00
|
|
|
handleUtfsServerError(static_cast<QProcess *>(sender())->error());
|
2010-08-10 15:05:21 +02:00
|
|
|
}
|
|
|
|
|
|
2010-08-10 15:42:12 +02:00
|
|
|
void MaemoRemoteMounter::handleUtfsClientStderr(const QByteArray &output)
|
|
|
|
|
{
|
2010-10-01 11:49:55 +02:00
|
|
|
if (m_state != Inactive)
|
|
|
|
|
m_utfsClientStderr += output;
|
2010-08-10 15:42:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaemoRemoteMounter::handleUmountStderr(const QByteArray &output)
|
2010-08-10 15:05:21 +02:00
|
|
|
{
|
2010-10-01 11:49:55 +02:00
|
|
|
if (m_state != Inactive)
|
|
|
|
|
m_umountStderr += output;
|
2010-08-10 15:05:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString MaemoRemoteMounter::utfsClientOnDevice() const
|
|
|
|
|
{
|
2010-09-23 10:20:29 +02:00
|
|
|
return MaemoGlobal::homeDirOnDevice(m_connection->connectionParameters().uname)
|
2010-08-10 15:05:21 +02:00
|
|
|
+ QLatin1String("/utfs-client");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString MaemoRemoteMounter::utfsServer() const
|
|
|
|
|
{
|
2010-11-11 12:08:13 +01:00
|
|
|
return m_maddeRoot + QLatin1String("/madlib/utfs-server");
|
2010-08-10 15:05:21 +02:00
|
|
|
}
|
|
|
|
|
|
2010-08-17 14:49:51 +02:00
|
|
|
void MaemoRemoteMounter::killAllUtfsServers()
|
|
|
|
|
{
|
2010-08-19 17:03:36 +02:00
|
|
|
foreach (const ProcPtr &proc, m_utfsServers)
|
|
|
|
|
killUtfsServer(proc.data());
|
|
|
|
|
m_utfsServers.clear();
|
2010-08-17 14:49:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaemoRemoteMounter::killUtfsServer(QProcess *proc)
|
|
|
|
|
{
|
|
|
|
|
disconnect(proc, 0, this, 0);
|
|
|
|
|
proc->terminate();
|
|
|
|
|
proc->waitForFinished(1000);
|
|
|
|
|
proc->kill();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaemoRemoteMounter::handleUtfsServerTimeout()
|
|
|
|
|
{
|
2010-10-01 11:49:55 +02:00
|
|
|
ASSERT_STATE(QList<State>() << UtfsServersStarted << Inactive);
|
|
|
|
|
if (m_state == Inactive)
|
2010-08-17 14:49:51 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
killAllUtfsServers();
|
|
|
|
|
emit error(tr("Timeout waiting for UTFS servers to connect."));
|
2010-10-01 11:49:55 +02:00
|
|
|
|
2010-10-01 15:49:09 +02:00
|
|
|
setState(Inactive);
|
2010-10-01 11:49:55 +02:00
|
|
|
}
|
|
|
|
|
|
2010-10-01 15:49:09 +02:00
|
|
|
void MaemoRemoteMounter::setState(State newState)
|
|
|
|
|
{
|
2010-11-08 18:14:09 +01:00
|
|
|
if (newState == Inactive) {
|
2010-10-01 15:49:09 +02:00
|
|
|
m_utfsServerTimer->stop();
|
2010-11-08 18:14:09 +01:00
|
|
|
if (m_utfsClientUploader) {
|
|
|
|
|
disconnect(m_utfsClientUploader.data(), 0, this, 0);
|
|
|
|
|
m_utfsClientUploader->closeChannel();
|
|
|
|
|
}
|
|
|
|
|
if (m_mountProcess) {
|
|
|
|
|
disconnect(m_mountProcess.data(), 0, this, 0);
|
|
|
|
|
m_mountProcess->closeChannel();
|
|
|
|
|
}
|
|
|
|
|
if (m_unmountProcess) {
|
|
|
|
|
disconnect(m_unmountProcess.data(), 0, this, 0);
|
|
|
|
|
m_unmountProcess->closeChannel();
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-10-01 15:49:09 +02:00
|
|
|
m_state = newState;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-10 15:05:21 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Qt4ProjectManager
|