From 0b90c6c6f635a05c20e5d1cd5efca548262125dd Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Wed, 14 Sep 2022 10:01:41 +0200 Subject: [PATCH] SftpFileTransfer: Don't use temporary file for batch file Use a "-" for a batch file option "-b" what makes sftp read batch from standard input. Fixes: QTCREATORBUG-28167 Change-Id: I449c5ba97ea11fca090b748f0a5ee8099140a548 Reviewed-by: Reviewed-by: Christian Kandeler --- src/plugins/remotelinux/linuxdevice.cpp | 27 +++++++++---------------- 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/src/plugins/remotelinux/linuxdevice.cpp b/src/plugins/remotelinux/linuxdevice.cpp index e11d6cd7db7..813934e9200 100644 --- a/src/plugins/remotelinux/linuxdevice.cpp +++ b/src/plugins/remotelinux/linuxdevice.cpp @@ -1495,18 +1495,12 @@ private: return; } - m_batchFile.reset(new QTemporaryFile(this)); - if (!m_batchFile->isOpen() && !m_batchFile->open()) { - startFailed(SshTransferInterface::tr("Could not create temporary file: %1") - .arg(m_batchFile->errorString())); - return; - } + QByteArray batchData; const FilePaths dirs = dirsToCreate(m_setup.m_files); for (const FilePath &dir : dirs) { if (direction() == FileTransferDirection::Upload) { - m_batchFile->write("-mkdir " + ProcessArgs::quoteArgUnix(dir.path()).toLocal8Bit() - + '\n'); + batchData += "-mkdir " + ProcessArgs::quoteArgUnix(dir.path()).toLocal8Bit() + '\n'; } else if (direction() == FileTransferDirection::Download) { if (!QDir::root().mkpath(dir.path())) { startFailed(SshTransferInterface::tr("Failed to create local directory \"%1\".") @@ -1523,25 +1517,22 @@ private: const QFileInfo fi(file.m_source.toFileInfo()); if (fi.isSymLink()) { link = true; - m_batchFile->write("-rm " + ProcessArgs::quoteArgUnix( - file.m_target.path()).toLocal8Bit() + '\n'); + batchData += "-rm " + ProcessArgs::quoteArgUnix( + file.m_target.path()).toLocal8Bit() + '\n'; // see QTBUG-5817. sourceFileOrLinkTarget.setPath(fi.dir().relativeFilePath(fi.symLinkTarget())); } } - m_batchFile->write(transferCommand(direction(), link) + ' ' - + ProcessArgs::quoteArgUnix(sourceFileOrLinkTarget.path()).toLocal8Bit() + ' ' - + ProcessArgs::quoteArgUnix(file.m_target.path()).toLocal8Bit() + '\n'); + batchData += transferCommand(direction(), link) + ' ' + + ProcessArgs::quoteArgUnix(sourceFileOrLinkTarget.path()).toLocal8Bit() + ' ' + + ProcessArgs::quoteArgUnix(file.m_target.path()).toLocal8Bit() + '\n'; } - m_batchFile->close(); - process().setCommand(CommandLine(sftpBinary, fullConnectionOptions() - << "-b" << m_batchFile->fileName() << host())); + process().setCommand({sftpBinary, fullConnectionOptions() << "-b" << "-" << host()}); + process().setWriteData(batchData); process().start(); } void doneImpl() final { handleDone(); } - - std::unique_ptr m_batchFile; }; class RsyncTransferImpl : public SshTransferInterface