diff options
author | hjk <hjk@qt.io> | 2023-04-06 14:28:12 +0200 |
---|---|---|
committer | hjk <hjk@qt.io> | 2023-04-06 17:09:08 +0000 |
commit | 25f7dfac25e8dd3f73ed5d189e2975843e808439 (patch) | |
tree | 09884799d4af62ed5ee505688ca69685fe454595 /src | |
parent | 3eb60d80e5bffb5d852a751584bd7a337d609386 (diff) | |
download | qt-creator-25f7dfac25e8dd3f73ed5d189e2975843e808439.tar.gz |
ProjectExplorer: Remove FileTransferDirection
Only 'Upload' is in active use, and the direction determination
gets fiddly when more than one remote device is involved.
If there'd ever be a real need for a 'Download', I add / reimplement
that as a separate case in FileTransferMethod.
Change-Id: I51580a180aae6f0ed5904ff1b828c9ffd6da658c
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/projectexplorer/devicesupport/filetransfer.cpp | 39 | ||||
-rw-r--r-- | src/plugins/projectexplorer/devicesupport/filetransferinterface.h | 8 | ||||
-rw-r--r-- | src/plugins/remotelinux/linuxdevice.cpp | 75 |
3 files changed, 28 insertions, 94 deletions
diff --git a/src/plugins/projectexplorer/devicesupport/filetransfer.cpp b/src/plugins/projectexplorer/devicesupport/filetransfer.cpp index bd386db0d1..523db6b32c 100644 --- a/src/plugins/projectexplorer/devicesupport/filetransfer.cpp +++ b/src/plugins/projectexplorer/devicesupport/filetransfer.cpp @@ -16,43 +16,18 @@ using namespace Utils; namespace ProjectExplorer { -FileTransferDirection FileToTransfer::direction() const -{ - if (m_source.needsDevice() == m_target.needsDevice()) - return FileTransferDirection::Invalid; - return m_source.needsDevice() ? FileTransferDirection::Download : FileTransferDirection::Upload; -} - QString FileTransferSetupData::defaultRsyncFlags() { return "-av"; } -static FileTransferDirection transferDirection(const FilesToTransfer &files) -{ - if (files.isEmpty()) - return FileTransferDirection::Invalid; - - const FileTransferDirection direction = files.first().direction(); - for (const FileToTransfer &file : files) { - if (file.direction() != direction) - return FileTransferDirection::Invalid; - } - return direction; -} - -static const FilePath &remoteFile(FileTransferDirection direction, const FileToTransfer &file) -{ - return direction == FileTransferDirection::Upload ? file.m_target : file.m_source; -} - -static IDeviceConstPtr matchedDevice(FileTransferDirection direction, const FilesToTransfer &files) +static IDeviceConstPtr matchedDevice(const FilesToTransfer &files) { if (files.isEmpty()) return {}; - const FilePath &filePath = remoteFile(direction, files.first()); + const FilePath filePath = files.first().m_target; for (const FileToTransfer &file : files) { - if (!filePath.isSameDevice(remoteFile(direction, file))) + if (!filePath.isSameDevice(file.m_target)) return {}; } return DeviceManager::deviceForPath(filePath); @@ -102,15 +77,11 @@ void FileTransferPrivate::start() if (m_setup.m_files.isEmpty()) return startFailed(Tr::tr("No files to transfer.")); - const FileTransferDirection direction = transferDirection(m_setup.m_files); - - IDeviceConstPtr device; - if (direction != FileTransferDirection::Invalid) - device = matchedDevice(direction, m_setup.m_files); + IDeviceConstPtr device = matchedDevice(m_setup.m_files); if (!device) { // Fall back to generic copy. - const FilePath &filePath = m_setup.m_files.first().m_target; + const FilePath filePath = m_setup.m_files.first().m_target; device = DeviceManager::deviceForPath(filePath); m_setup.m_method = FileTransferMethod::GenericCopy; } diff --git a/src/plugins/projectexplorer/devicesupport/filetransferinterface.h b/src/plugins/projectexplorer/devicesupport/filetransferinterface.h index 2907f9c257..ce4e662db4 100644 --- a/src/plugins/projectexplorer/devicesupport/filetransferinterface.h +++ b/src/plugins/projectexplorer/devicesupport/filetransferinterface.h @@ -11,12 +11,6 @@ namespace Utils { class ProcessResultData; } namespace ProjectExplorer { -enum class FileTransferDirection { - Invalid, - Upload, - Download -}; - enum class FileTransferMethod { Sftp, Rsync, @@ -29,8 +23,6 @@ class PROJECTEXPLORER_EXPORT FileToTransfer public: Utils::FilePath m_source; Utils::FilePath m_target; - - FileTransferDirection direction() const; }; using FilesToTransfer = QList<FileToTransfer>; diff --git a/src/plugins/remotelinux/linuxdevice.cpp b/src/plugins/remotelinux/linuxdevice.cpp index 0822c9e9e3..b17ed8fcf7 100644 --- a/src/plugins/remotelinux/linuxdevice.cpp +++ b/src/plugins/remotelinux/linuxdevice.cpp @@ -1152,13 +1152,9 @@ static FilePaths dirsToCreate(const FilesToTransfer &files) return sorted(std::move(dirs)); } -static QByteArray transferCommand(const FileTransferDirection direction, bool link) +static QByteArray transferCommand(bool link) { - if (direction == FileTransferDirection::Upload) - return link ? "ln -s" : "put"; - if (direction == FileTransferDirection::Download) - return "get"; - return {}; + return link ? "ln -s" : "put"; } class SshTransferInterface : public FileTransferInterface @@ -1171,8 +1167,6 @@ protected: , m_device(device) , m_process(this) { - m_direction = m_setup.m_files.isEmpty() ? FileTransferDirection::Invalid - : m_setup.m_files.first().direction(); SshParameters::setupSshEnvironment(&m_process); connect(&m_process, &QtcProcess::readyReadStandardOutput, this, [this] { emit progress(QString::fromLocal8Bit(m_process.readAllRawStandardOutput())); @@ -1216,7 +1210,6 @@ protected: QString userAtHost() const { return m_sshParameters.userAtHost(); } QtcProcess &process() { return m_process; } - FileTransferDirection direction() const { return m_direction; } private: virtual void startImpl() = 0; @@ -1269,7 +1262,6 @@ private: IDevice::ConstPtr m_device; SshParameters m_sshParameters; - FileTransferDirection m_direction = FileTransferDirection::Invalid; // helper // ssh shared connection related std::unique_ptr<SshConnectionHandle> m_connectionHandle; @@ -1299,35 +1291,26 @@ private: QByteArray batchData; const FilePaths dirs = dirsToCreate(m_setup.m_files); - for (const FilePath &dir : dirs) { - if (direction() == FileTransferDirection::Upload) { - batchData += "-mkdir " + ProcessArgs::quoteArgUnix(dir.path()).toLocal8Bit() + '\n'; - } else if (direction() == FileTransferDirection::Download) { - if (!QDir::root().mkpath(dir.path())) { - startFailed(Tr::tr("Failed to create local directory \"%1\".") - .arg(QDir::toNativeSeparators(dir.path()))); - return; - } - } - } + for (const FilePath &dir : dirs) + batchData += "-mkdir " + ProcessArgs::quoteArgUnix(dir.path()).toLocal8Bit() + '\n'; for (const FileToTransfer &file : m_setup.m_files) { FilePath sourceFileOrLinkTarget = file.m_source; bool link = false; - if (direction() == FileTransferDirection::Upload) { - const QFileInfo fi(file.m_source.toFileInfo()); - if (fi.isSymLink()) { - link = true; - batchData += "-rm " + ProcessArgs::quoteArgUnix( - file.m_target.path()).toLocal8Bit() + '\n'; - // see QTBUG-5817. - sourceFileOrLinkTarget = - sourceFileOrLinkTarget.withNewPath(fi.dir().relativeFilePath(fi.symLinkTarget())); - } - } - batchData += transferCommand(direction(), link) + ' ' - + ProcessArgs::quoteArgUnix(sourceFileOrLinkTarget.path()).toLocal8Bit() + ' ' - + ProcessArgs::quoteArgUnix(file.m_target.path()).toLocal8Bit() + '\n'; + + const QFileInfo fi(file.m_source.toFileInfo()); + if (fi.isSymLink()) { + link = true; + batchData += "-rm " + ProcessArgs::quoteArgUnix( + file.m_target.path()).toLocal8Bit() + '\n'; + // see QTBUG-5817. + sourceFileOrLinkTarget = + sourceFileOrLinkTarget.withNewPath(fi.dir().relativeFilePath(fi.symLinkTarget())); + } + + batchData += transferCommand(link) + ' ' + + ProcessArgs::quoteArgUnix(sourceFileOrLinkTarget.path()).toLocal8Bit() + ' ' + + ProcessArgs::quoteArgUnix(file.m_target.path()).toLocal8Bit() + '\n'; } process().setCommand({sftpBinary, fullConnectionOptions() << "-b" << "-" << host()}); process().setWriteData(batchData); @@ -1392,8 +1375,7 @@ private: if (!HostOsInfo::isWindowsHost()) return file; - QString localFilePath = direction() == FileTransferDirection::Upload - ? file.m_source.path() : file.m_target.path(); + QString localFilePath = file.m_source.path(); localFilePath = '/' + localFilePath.at(0) + localFilePath.mid(2); if (anyOf(options, [](const QString &opt) { return opt.contains("cygwin", Qt::CaseInsensitive); })) { @@ -1401,30 +1383,19 @@ private: } FileToTransfer fixedFile = file; - if (direction() == FileTransferDirection::Upload) - fixedFile.m_source = fixedFile.m_source.withNewPath(localFilePath); - else - fixedFile.m_target = fixedFile.m_target.withNewPath(localFilePath); + fixedFile.m_source = fixedFile.m_source.withNewPath(localFilePath); return fixedFile; } QPair<QString, QString> fixPaths(const FileToTransfer &file, const QString &remoteHost) const { - FilePath localPath; - FilePath remotePath; - if (direction() == FileTransferDirection::Upload) { - localPath = file.m_source; - remotePath = file.m_target; - } else { - remotePath = file.m_source; - localPath = file.m_target; - } + FilePath localPath = file.m_source; + FilePath remotePath = file.m_target; const QString local = (localPath.isDir() && localPath.path().back() != '/') ? localPath.path() + '/' : localPath.path(); const QString remote = remoteHost + ':' + remotePath.path(); - return direction() == FileTransferDirection::Upload ? qMakePair(local, remote) - : qMakePair(remote, local); + return qMakePair(local, remote); } int m_currentIndex = 0; |