RemoteLinux: Speed up rsync transfer

Group files with the same target directory into a single rsync
invocation.

Fixes: QTCREATORBUG-29988
Change-Id: I3fc7883e55c9c3105d403d19d0b59cc70d158d6d
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Christian Kandeler
2024-02-14 14:48:13 +01:00
parent 0b2f7dd6fe
commit 065debd163

View File

@@ -1485,23 +1485,24 @@ public:
private: private:
void startImpl() final void startImpl() final
{ {
m_currentIndex = 0; // Note: This assumes that files do not get renamed when transferring.
startNextFile(); for (auto it = m_setup.m_files.cbegin(); it != m_setup.m_files.cend(); ++it)
m_batches[it->m_target.parentDir()] << *it;
startNextBatch();
} }
void doneImpl() final void doneImpl() final
{ {
if (m_setup.m_files.size() == 0 || m_currentIndex == m_setup.m_files.size() - 1) if (m_batches.isEmpty())
return handleDone(); return handleDone();
if (handleError()) if (handleError())
return; return;
++m_currentIndex; startNextBatch();
startNextFile();
} }
void startNextFile() void startNextBatch()
{ {
process().close(); process().close();
@@ -1510,12 +1511,14 @@ private:
<< fullConnectionOptions(), OsTypeLinux); << fullConnectionOptions(), OsTypeLinux);
QStringList options{"-e", sshCmdLine, m_setup.m_rsyncFlags}; QStringList options{"-e", sshCmdLine, m_setup.m_rsyncFlags};
if (!m_setup.m_files.isEmpty()) { // NormalRun if (!m_batches.isEmpty()) { // NormalRun
const FileToTransfer file = m_setup.m_files.at(m_currentIndex); const auto batchIt = m_batches.begin();
const FileToTransfer fixedFile = fixLocalFileOnWindows(file, options); for (auto filesIt = batchIt->cbegin(); filesIt != batchIt->cend(); ++filesIt) {
const auto fixedPaths = fixPaths(fixedFile, userAtHost()); const FileToTransfer fixedFile = fixLocalFileOnWindows(*filesIt, options);
options << fixedLocalPath(fixedFile.m_source);
options << fixedPaths.first << fixedPaths.second; }
options << fixedRemotePath(batchIt.key(), userAtHost());
m_batches.erase(batchIt);
} else { // TestRun } else { // TestRun
options << "-n" << "--exclude=*" << (userAtHost() + ":/tmp"); options << "-n" << "--exclude=*" << (userAtHost() + ":/tmp");
} }
@@ -1542,18 +1545,17 @@ private:
return fixedFile; return fixedFile;
} }
QPair<QString, QString> fixPaths(const FileToTransfer &file, const QString &remoteHost) const QString fixedLocalPath(const FilePath &file) const
{ {
FilePath localPath = file.m_source; return file.isDir() && file.path().back() != '/' ? file.path() + '/' : file.path();
FilePath remotePath = file.m_target;
const QString local = (localPath.isDir() && localPath.path().back() != '/')
? localPath.path() + '/' : localPath.path();
const QString remote = remoteHost + ':' + remotePath.path();
return qMakePair(local, remote);
} }
int m_currentIndex = 0; QString fixedRemotePath(const FilePath &file, const QString &remoteHost) const
{
return remoteHost + ':' + file.path();
}
QHash<FilePath, FilesToTransfer> m_batches;
}; };
class GenericTransferImpl : public FileTransferInterface class GenericTransferImpl : public FileTransferInterface