diff --git a/src/plugins/remotelinux/abstractremotelinuxdeployservice.h b/src/plugins/remotelinux/abstractremotelinuxdeployservice.h index c59a77fd4c4..3d63136fa74 100644 --- a/src/plugins/remotelinux/abstractremotelinuxdeployservice.h +++ b/src/plugins/remotelinux/abstractremotelinuxdeployservice.h @@ -106,6 +106,8 @@ protected: virtual void doDeviceSetup() { handleDeviceSetupDone(true); } virtual void stopDeviceSetup() { handleDeviceSetupDone(false); } + void setFinished(); + private: void handleConnected(); void handleConnectionFailure(); @@ -115,7 +117,6 @@ private: virtual void doDeploy() = 0; virtual void stopDeployment() = 0; - void setFinished(); Internal::AbstractRemoteLinuxDeployServicePrivate * const d; }; diff --git a/src/plugins/remotelinux/linuxdevice.cpp b/src/plugins/remotelinux/linuxdevice.cpp index 74d9e4586f0..874ae4386ff 100644 --- a/src/plugins/remotelinux/linuxdevice.cpp +++ b/src/plugins/remotelinux/linuxdevice.cpp @@ -403,6 +403,20 @@ QString LinuxDevice::userAtHost() const return sshParameters().userName() + '@' + sshParameters().host(); } +FilePath LinuxDevice::mapToGlobalPath(const FilePath &pathOnDevice) const +{ + if (pathOnDevice.needsDevice()) { + // Already correct form, only sanity check it's ours... + QTC_CHECK(handlesFile(pathOnDevice)); + return pathOnDevice; + } + FilePath result; + result.setScheme("ssh"); + result.setHost(userAtHost()); + result.setPath(pathOnDevice.path()); + return result; +} + bool LinuxDevice::handlesFile(const FilePath &filePath) const { return filePath.scheme() == "ssh" && filePath.host() == userAtHost(); diff --git a/src/plugins/remotelinux/linuxdevice.h b/src/plugins/remotelinux/linuxdevice.h index 00498dcc2a0..4f728fdfbb9 100644 --- a/src/plugins/remotelinux/linuxdevice.h +++ b/src/plugins/remotelinux/linuxdevice.h @@ -58,6 +58,8 @@ public: ProjectExplorer::DeviceEnvironmentFetcher::Ptr environmentFetcher() const override; QString userAtHost() const; + Utils::FilePath mapToGlobalPath(const Utils::FilePath &pathOnDevice) const override; + bool handlesFile(const Utils::FilePath &filePath) const override; bool isExecutableFile(const Utils::FilePath &filePath) const override; bool isReadableFile(const Utils::FilePath &filePath) const override; diff --git a/src/plugins/remotelinux/remotelinuxcheckforfreediskspaceservice.cpp b/src/plugins/remotelinux/remotelinuxcheckforfreediskspaceservice.cpp index 4f75d409557..9cb6340d868 100644 --- a/src/plugins/remotelinux/remotelinuxcheckforfreediskspaceservice.cpp +++ b/src/plugins/remotelinux/remotelinuxcheckforfreediskspaceservice.cpp @@ -28,14 +28,15 @@ #include #include +#include + namespace RemoteLinux { namespace Internal { class RemoteLinuxCheckForFreeDiskSpaceServicePrivate { public: QString pathToCheck; - quint64 requiredSpaceInBytes; - QSsh::SshRemoteProcessRunner *processRunner; + quint64 requiredSpaceInBytes = 0; }; } // namespace Internal @@ -43,13 +44,10 @@ RemoteLinuxCheckForFreeDiskSpaceService::RemoteLinuxCheckForFreeDiskSpaceService : AbstractRemoteLinuxDeployService(parent), d(new Internal::RemoteLinuxCheckForFreeDiskSpaceServicePrivate) { - d->processRunner = nullptr; - d->requiredSpaceInBytes = 0; } RemoteLinuxCheckForFreeDiskSpaceService::~RemoteLinuxCheckForFreeDiskSpaceService() { - cleanup(); delete d; } @@ -63,44 +61,31 @@ void RemoteLinuxCheckForFreeDiskSpaceService::setRequiredSpaceInBytes(quint64 si d->requiredSpaceInBytes = sizeInBytes; } -void RemoteLinuxCheckForFreeDiskSpaceService::handleStdErr() +void RemoteLinuxCheckForFreeDiskSpaceService::deployAndFinish() { - emit stdErrData(QString::fromUtf8(d->processRunner->readAllStandardError())); -} - -void RemoteLinuxCheckForFreeDiskSpaceService::handleProcessFinished() -{ - if (!d->processRunner->processErrorString().isEmpty()) { - emit errorMessage(tr("Remote process failed: %1") - .arg(d->processRunner->processErrorString())); - stopDeployment(); - return; - - } - - bool isNumber; - QByteArray processOutput = d->processRunner->readAllStandardOutput(); - processOutput.chop(1); // newline - quint64 freeSpace = processOutput.toULongLong(&isNumber); - quint64 requiredSpaceInMegaBytes = d->requiredSpaceInBytes / (1024 * 1024); - if (!isNumber) { - emit errorMessage(tr("Unexpected output from remote process: \"%1\"") - .arg(QString::fromUtf8(processOutput))); - stopDeployment(); + auto cleanup = qScopeGuard([this] { setFinished(); }); + const Utils::FilePath path + = deviceConfiguration()->mapToGlobalPath(Utils::FilePath::fromString(d->pathToCheck)); + const quint64 freeSpace = path.bytesAvailable(); + if (freeSpace < 0) { + emit errorMessage(tr("Can't get the info about the free disk space for \"%1\"") + .arg(path.toUserOutput())); return; } - freeSpace /= 1024; // convert kilobyte to megabyte - if (freeSpace < requiredSpaceInMegaBytes) { + const quint64 mb = 1024 * 1024; + const quint64 freeSpaceMB = freeSpace / mb; + const quint64 requiredSpaceMB = d->requiredSpaceInBytes / mb; + + if (freeSpaceMB < requiredSpaceMB) { emit errorMessage(tr("The remote file system has only %n megabytes of free space, " - "but %1 megabytes are required.", nullptr, freeSpace).arg(requiredSpaceInMegaBytes)); - stopDeployment(); + "but %1 megabytes are required.", nullptr, freeSpaceMB) + .arg(requiredSpaceMB)); return; } emit progressMessage(tr("The remote file system has %n megabytes of free space, going ahead.", - nullptr, freeSpace)); - stopDeployment(); + nullptr, freeSpaceMB)); } CheckResult RemoteLinuxCheckForFreeDiskSpaceService::isDeploymentPossible() const @@ -114,32 +99,4 @@ CheckResult RemoteLinuxCheckForFreeDiskSpaceService::isDeploymentPossible() cons return AbstractRemoteLinuxDeployService::isDeploymentPossible(); } -void RemoteLinuxCheckForFreeDiskSpaceService::doDeploy() -{ - d->processRunner = new QSsh::SshRemoteProcessRunner; - connect(d->processRunner, &QSsh::SshRemoteProcessRunner::processClosed, - this, &RemoteLinuxCheckForFreeDiskSpaceService::handleProcessFinished); - connect(d->processRunner, &QSsh::SshRemoteProcessRunner::readyReadStandardError, - this, &RemoteLinuxCheckForFreeDiskSpaceService::handleStdErr); - const QString command = QString::fromLatin1("df -k %1 |tail -n 1 |sed 's/ */ /g' " - "|cut -d ' ' -f 4").arg(d->pathToCheck); - d->processRunner->run(command, deviceConfiguration()->sshParameters()); -} - -void RemoteLinuxCheckForFreeDiskSpaceService::stopDeployment() -{ - cleanup(); - handleDeploymentDone(); -} - -void RemoteLinuxCheckForFreeDiskSpaceService::cleanup() -{ - if (d->processRunner) { - disconnect(d->processRunner, nullptr, this, nullptr); - d->processRunner->cancel(); - delete d->processRunner; - d->processRunner = nullptr; - } -} - } // namespace RemoteLinux diff --git a/src/plugins/remotelinux/remotelinuxcheckforfreediskspaceservice.h b/src/plugins/remotelinux/remotelinuxcheckforfreediskspaceservice.h index 6e81520df60..3d565d37d7b 100644 --- a/src/plugins/remotelinux/remotelinuxcheckforfreediskspaceservice.h +++ b/src/plugins/remotelinux/remotelinuxcheckforfreediskspaceservice.h @@ -42,16 +42,15 @@ public: void setRequiredSpaceInBytes(quint64 sizeInBytes); private: - void handleStdErr(); - void handleProcessFinished(); - + void deployAndFinish(); bool isDeploymentNecessary() const override { return true; } CheckResult isDeploymentPossible() const override; - void doDeploy() override; - void stopDeployment() override; + void doDeviceSetup() final { deployAndFinish(); } + void stopDeviceSetup() final { } - void cleanup(); + void doDeploy() final {}; + void stopDeployment() final {}; Internal::RemoteLinuxCheckForFreeDiskSpaceServicePrivate * const d; };