Maemo: Add option to create directory on device in deployment API.

This commit is contained in:
ck
2010-01-07 15:23:33 +01:00
parent 6b1a98cdb3
commit af64744706
5 changed files with 50 additions and 26 deletions

View File

@@ -43,8 +43,9 @@
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/progressmanager/progressmanager.h> #include <coreplugin/progressmanager/progressmanager.h>
#include <extensionsystem/pluginmanager.h>
#include <debugger/debuggermanager.h> #include <debugger/debuggermanager.h>
#include <extensionsystem/pluginmanager.h>
#include <projectexplorer/toolchain.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <QtCore/QDir> #include <QtCore/QDir>
@@ -55,7 +56,9 @@
namespace Qt4ProjectManager { namespace Qt4ProjectManager {
namespace Internal { namespace Internal {
#ifndef USE_SSH_LIB
using ProjectExplorer::Environment; using ProjectExplorer::Environment;
#endif // USE_SSH_LIB
using ProjectExplorer::RunConfiguration; using ProjectExplorer::RunConfiguration;
using ProjectExplorer::ToolChain; using ProjectExplorer::ToolChain;
@@ -115,14 +118,16 @@ void AbstractMaemoRunControl::deploy()
{ {
#ifdef USE_SSH_LIB #ifdef USE_SSH_LIB
if (!deployables.isEmpty()) { if (!deployables.isEmpty()) {
QList<SshDeploySpec> deploySpecs;
QStringList files; QStringList files;
QStringList targetDirs;
foreach (const Deployable &deployable, deployables) { foreach (const Deployable &deployable, deployables) {
files << deployable.dir + QDir::separator() + deployable.fileName; const QString srcFilePath
targetDirs << remoteDir(); = deployable.dir % QDir::separator() % deployable.fileName;
files << srcFilePath;
deploySpecs << SshDeploySpec(srcFilePath, remoteDir());
} }
emit addToOutputWindow(this, tr("Files to deploy: %1.").arg(files.join(" "))); emit addToOutputWindow(this, tr("Files to deploy: %1.").arg(files.join(" ")));
sshDeployer.reset(new MaemoSshDeployer(devConfig, files, targetDirs)); sshDeployer.reset(new MaemoSshDeployer(devConfig, deploySpecs));
connect(sshDeployer.data(), SIGNAL(finished()), connect(sshDeployer.data(), SIGNAL(finished()),
this, SLOT(deployProcessFinished())); this, SLOT(deployProcessFinished()));
connect(sshDeployer.data(), SIGNAL(fileCopied(QString)), connect(sshDeployer.data(), SIGNAL(fileCopied(QString)),

View File

@@ -49,7 +49,6 @@
#include <QtCore/QFileInfo> #include <QtCore/QFileInfo>
#include <QtCore/QStringBuilder> #include <QtCore/QStringBuilder>
#include <QtCore/QStringList>
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
@@ -60,6 +59,8 @@ namespace {
ne7ssh ssh; ne7ssh ssh;
} }
// TODO: Which encoding to use for file names? Unicode? Latin1? ASCII?
MaemoSshConnection::MaemoSshConnection(const MaemoDeviceConfig &devConf, MaemoSshConnection::MaemoSshConnection(const MaemoDeviceConfig &devConf,
bool shell) bool shell)
: m_channel(-1), m_stopRequested(false) : m_channel(-1), m_stopRequested(false)
@@ -155,17 +156,22 @@ MaemoSftpConnection::~MaemoSftpConnection()
} }
void MaemoSftpConnection::transferFiles(const QStringList &filePaths, void MaemoSftpConnection::transferFiles(const QList<SshDeploySpec> &deploySpecs)
const QStringList &targetDirs)
{ {
Q_ASSERT(filePaths.count() == targetDirs.count()); for (int i = 0; i < deploySpecs.count(); ++i) {
for (int i = 0; i < filePaths.count(); ++i) { const SshDeploySpec &deploySpec = deploySpecs.at(i);
const QString &curFile = filePaths.at(i); const QString &curFile = deploySpec.srcFilePath();
QSharedPointer<FILE> filePtr(fopen(curFile.toLatin1().data(), "rb"), QSharedPointer<FILE> filePtr(fopen(curFile.toLatin1().data(), "rb"),
&std::fclose); &std::fclose);
if (filePtr.isNull()) if (filePtr.isNull())
throw MaemoSshException(tr("Could not open file '%1'").arg(curFile)); throw MaemoSshException(tr("Could not open file '%1'").arg(curFile));
const QString &targetFile = targetDirs.at(i) % QLatin1String("/")
// TODO: Is the mkdir() method recursive? If not, we have to
// introduce a recursive version ourselves.
if (deploySpec.mkdir())
sftp->mkdir(deploySpec.targetDir().toLatin1().data());
const QString &targetFile = deploySpec.targetDir() % QLatin1String("/")
% QFileInfo(curFile).fileName(); % QFileInfo(curFile).fileName();
if (!sftp->put(filePtr.data(), targetFile.toLatin1().data())) { if (!sftp->put(filePtr.data(), targetFile.toLatin1().data())) {
const QString &error = tr("Could not copy local file '%1' " const QString &error = tr("Could not copy local file '%1' "

View File

@@ -49,11 +49,6 @@
#include <QtCore/QSharedPointer> #include <QtCore/QSharedPointer>
#include <QtCore/QString> #include <QtCore/QString>
QT_BEGIN_NAMESPACE
class QStringList;
QT_END_NAMESPACE
class ne7ssh;
class Ne7SftpSubsystem; class Ne7SftpSubsystem;
namespace Qt4ProjectManager { namespace Qt4ProjectManager {
@@ -110,6 +105,26 @@ private:
const char *m_prompt; const char *m_prompt;
}; };
class SshDeploySpec
{
public:
SshDeploySpec(const QString &srcFilePath, const QString &targetDir,
bool mkdir = false)
: m_srcFilePath(srcFilePath), m_targetDir(targetDir), m_mkdir(mkdir)
{
}
QString srcFilePath() const { return m_srcFilePath; }
QString targetDir() const { return m_targetDir; }
bool mkdir() const { return m_mkdir; }
private:
QString m_srcFilePath;
QString m_targetDir;
bool m_mkdir;
};
class MaemoSftpConnection : public MaemoSshConnection class MaemoSftpConnection : public MaemoSshConnection
{ {
Q_OBJECT Q_OBJECT
@@ -118,8 +133,7 @@ public:
typedef QSharedPointer<MaemoSftpConnection> Ptr; typedef QSharedPointer<MaemoSftpConnection> Ptr;
static Ptr create(const MaemoDeviceConfig &devConf); static Ptr create(const MaemoDeviceConfig &devConf);
void transferFiles(const QStringList &filePaths, void transferFiles(const QList<SshDeploySpec> &deploySpecs);
const QStringList &targetDirs);
virtual ~MaemoSftpConnection(); virtual ~MaemoSftpConnection();
signals: signals:

View File

@@ -104,8 +104,8 @@ void MaemoSshRunner::runInternal()
} }
MaemoSshDeployer::MaemoSshDeployer(const MaemoDeviceConfig &devConf, MaemoSshDeployer::MaemoSshDeployer(const MaemoDeviceConfig &devConf,
const QStringList &filePaths, const QStringList &targetDirs) const QList<SshDeploySpec> &deploySpecs)
: MaemoSshThread(devConf), m_filePaths(filePaths), m_targetDirs(targetDirs) : MaemoSshThread(devConf), m_deploySpecs(deploySpecs)
{ {
} }
@@ -117,7 +117,7 @@ void MaemoSshDeployer::runInternal()
return; return;
connect(connection.data(), SIGNAL(fileCopied(QString)), connect(connection.data(), SIGNAL(fileCopied(QString)),
this, SIGNAL(fileCopied(QString))); this, SIGNAL(fileCopied(QString)));
connection->transferFiles(m_filePaths, m_targetDirs); connection->transferFiles(m_deploySpecs);
} }
} // namespace Internal } // namespace Internal

View File

@@ -45,8 +45,8 @@
#include "maemodeviceconfigurations.h" #include "maemodeviceconfigurations.h"
#include "maemosshconnection.h" #include "maemosshconnection.h"
#include <QtCore/QList>
#include <QtCore/QMutex> #include <QtCore/QMutex>
#include <QtCore/QStringList>
#include <QtCore/QThread> #include <QtCore/QThread>
#ifdef USE_SSH_LIB #ifdef USE_SSH_LIB
@@ -104,7 +104,7 @@ class MaemoSshDeployer : public MaemoSshThread
Q_DISABLE_COPY(MaemoSshDeployer) Q_DISABLE_COPY(MaemoSshDeployer)
public: public:
MaemoSshDeployer(const MaemoDeviceConfig &devConf, MaemoSshDeployer(const MaemoDeviceConfig &devConf,
const QStringList &filePaths, const QStringList &targetDirs); const QList<SshDeploySpec> &deploySpecs);
signals: signals:
void fileCopied(const QString &filePath); void fileCopied(const QString &filePath);
@@ -112,8 +112,7 @@ signals:
private: private:
virtual void runInternal(); virtual void runInternal();
const QStringList m_filePaths; const QList<SshDeploySpec> m_deploySpecs;
const QStringList m_targetDirs;
}; };
} // namespace Internal } // namespace Internal