| 80 | } |
| 81 | |
| 82 | void DockerRuntime::setEnabled(bool enable) |
| 83 | { |
| 84 | if (enable) { |
| 85 | m_userMergedDir = KDevelop::Path(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + QLatin1String("/docker-") + QString(m_tag).replace(QLatin1Char('/'), QLatin1Char('_'))); |
| 86 | QDir().mkpath(m_userMergedDir.toLocalFile()); |
| 87 | |
| 88 | QProcess pCreateContainer; |
| 89 | pCreateContainer.start(QStringLiteral("docker"), {QStringLiteral("run"), QStringLiteral("-d"), m_tag, QStringLiteral("tail"), QStringLiteral("-f"), QStringLiteral("/dev/null")}); |
| 90 | pCreateContainer.waitForFinished(); |
| 91 | if (pCreateContainer.exitCode()) { |
| 92 | qCWarning(DOCKER) << "could not create the container" << pCreateContainer.readAll(); |
| 93 | } |
| 94 | m_container = QString::fromUtf8(pCreateContainer.readAll().trimmed()); |
| 95 | |
| 96 | inspectContainer(); |
| 97 | |
| 98 | const QStringList cmd = {QStringLiteral("pkexec"), QStringLiteral("bindfs"), QLatin1String("--map=root/")+KUser().loginName(), m_mergedDir.toLocalFile(), m_userMergedDir.toLocalFile() }; |
| 99 | QProcess p; |
| 100 | p.start(cmd.first(), cmd.mid(1)); |
| 101 | p.waitForFinished(); |
| 102 | if (p.exitCode()) { |
| 103 | qCDebug(DOCKER) << "bindfs returned" << cmd << p.exitCode() << p.readAll(); |
| 104 | } |
| 105 | } else { |
| 106 | int codeContainer = QProcess::execute(QStringLiteral("docker"), {QStringLiteral("kill"), m_container}); |
| 107 | qCDebug(DOCKER) << "docker kill returned" << codeContainer; |
| 108 | |
| 109 | int code = QProcess::execute(QStringLiteral("pkexec"), {QStringLiteral("umount"), m_userMergedDir.toLocalFile()}); |
| 110 | qCDebug(DOCKER) << "umount returned" << code; |
| 111 | |
| 112 | m_container.clear(); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | static QString ensureEndsSlash(const QString &string) |
| 117 | { |
no test coverage detected