aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhjk <hjk@qt.io>2022-02-09 12:29:40 +0100
committerhjk <hjk@qt.io>2022-02-10 10:02:33 +0000
commit3bdab2f05eae5133b9fcd1f1df71d8999efa1eb2 (patch)
treecbbbb051b7ee0d635ad726ffcd35f15f32e75280
parent7e00d5f662e9ccfb2b3b8e8a5e9d781db537891d (diff)
Docker: Simplify and fix "Open Shell in Container"
Change-Id: Icce72712a006f524b8a8328904d89f2b0e2b8a3d Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Christian Stenger <christian.stenger@qt.io>
-rw-r--r--src/plugins/docker/dockerdevice.cpp33
1 files changed, 15 insertions, 18 deletions
diff --git a/src/plugins/docker/dockerdevice.cpp b/src/plugins/docker/dockerdevice.cpp
index 22428aea25..7652ef935f 100644
--- a/src/plugins/docker/dockerdevice.cpp
+++ b/src/plugins/docker/dockerdevice.cpp
@@ -530,32 +530,29 @@ DockerDevice::DockerDevice(const DockerDeviceData &data)
setAllowEmptyCommand(true);
setOpenTerminal([this](const Environment &env, const FilePath &workingDir) {
- DeviceProcess * const proc = createProcess(nullptr);
- QObject::connect(proc, &DeviceProcess::finished, [proc] {
- if (!proc->errorString().isEmpty()) {
- MessageManager::writeDisrupting(
- tr("Error running remote shell: %1").arg(proc->errorString()));
- }
- proc->deleteLater();
- });
+ Q_UNUSED(env); // TODO: That's the runnable's environment in general. Use it via -e below.
+ updateContainerAccess();
+ if (d->m_container.isEmpty()) {
+ MessageManager::writeDisrupting(tr("Error starting remote shell. No container"));
+ return;
+ }
+
+ QtcProcess *proc = new QtcProcess(QtcProcess::TerminalOn);
+ QObject::connect(proc, &QtcProcess::finished, proc, &QObject::deleteLater);
+
QObject::connect(proc, &DeviceProcess::errorOccurred, [proc] {
MessageManager::writeDisrupting(tr("Error starting remote shell."));
proc->deleteLater();
});
- Runnable runnable;
- runnable.command = {"/bin/sh", {}};
- runnable.device = sharedFromThis();
- runnable.environment = env;
- runnable.workingDirectory = workingDir;
- runnable.extraData[Constants::DOCKER_RUN_FLAGS] = QStringList({"--interactive", "--tty"});
-
- proc->setRunInTerminal(true);
- proc->start(runnable);
+ const QString wd = workingDir.isEmpty() ? "/" : workingDir.path();
+ proc->setCommand({"docker", {"exec", "-it", "-w", wd, d->m_container, "/bin/sh"}});
+ proc->setEnvironment(Environment::systemEnvironment()); // The host system env. Intentional.
+ proc->start();
});
if (HostOsInfo::isAnyUnixHost()) {
- addDeviceAction({tr("Open Shell in Container"), [](const IDevice::Ptr &device, QWidget *) {
+ addDeviceAction({tr("Open Shell in Container"), [this](const IDevice::Ptr &device, QWidget *) {
device->openTerminal(Environment(), FilePath());
}});
}