forked from qt-creator/qt-creator
Docker: Remove temporary mounts
Temporary mounts are more problem than solution. We want the user to specifically mount paths himself instead of trying to guess which ones should be mounted. Change-Id: I635ac2555e11979a4eb8cd60c1a22b02a377a5ba Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -341,8 +341,6 @@ public:
|
|||||||
return deviceSettings->clangdExecutable();
|
return deviceSettings->clangdExecutable();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool addTemporaryMount(const FilePath &path, const FilePath &containerPath);
|
|
||||||
|
|
||||||
QStringList createMountArgs() const;
|
QStringList createMountArgs() const;
|
||||||
|
|
||||||
bool isImageAvailable() const;
|
bool isImageAvailable() const;
|
||||||
@@ -350,14 +348,12 @@ public:
|
|||||||
DockerDevice *const q;
|
DockerDevice *const q;
|
||||||
DockerDeviceSettings *deviceSettings;
|
DockerDeviceSettings *deviceSettings;
|
||||||
|
|
||||||
struct TemporaryMountInfo
|
struct MountPair
|
||||||
{
|
{
|
||||||
FilePath path;
|
FilePath path;
|
||||||
FilePath containerPath;
|
FilePath containerPath;
|
||||||
};
|
};
|
||||||
|
|
||||||
QList<TemporaryMountInfo> m_temporaryMounts;
|
|
||||||
|
|
||||||
QMutex m_shellMutex;
|
QMutex m_shellMutex;
|
||||||
std::unique_ptr<ContainerShell> m_shell;
|
std::unique_ptr<ContainerShell> m_shell;
|
||||||
|
|
||||||
@@ -750,7 +746,7 @@ QString escapeMountPath(const FilePath &fp)
|
|||||||
return escapeMountPathUnix(fp);
|
return escapeMountPathUnix(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList toMountArg(const DockerDevicePrivate::TemporaryMountInfo &mi)
|
QStringList toMountArg(const DockerDevicePrivate::MountPair &mi)
|
||||||
{
|
{
|
||||||
QString escapedPath;
|
QString escapedPath;
|
||||||
QString escapedContainerPath;
|
QString escapedContainerPath;
|
||||||
@@ -765,7 +761,7 @@ QStringList toMountArg(const DockerDevicePrivate::TemporaryMountInfo &mi)
|
|||||||
return QStringList{"--mount", mountArg};
|
return QStringList{"--mount", mountArg};
|
||||||
}
|
}
|
||||||
|
|
||||||
expected_str<void> isValidMountInfo(const DockerDevicePrivate::TemporaryMountInfo &mi)
|
expected_str<void> isValidMountInfo(const DockerDevicePrivate::MountPair &mi)
|
||||||
{
|
{
|
||||||
if (mi.path.needsDevice())
|
if (mi.path.needsDevice())
|
||||||
return make_unexpected(QString("The path \"%1\" is not local.").arg(mi.path.toUserOutput()));
|
return make_unexpected(QString("The path \"%1\" is not local.").arg(mi.path.toUserOutput()));
|
||||||
@@ -801,11 +797,11 @@ expected_str<void> isValidMountInfo(const DockerDevicePrivate::TemporaryMountInf
|
|||||||
QStringList DockerDevicePrivate::createMountArgs() const
|
QStringList DockerDevicePrivate::createMountArgs() const
|
||||||
{
|
{
|
||||||
QStringList cmds;
|
QStringList cmds;
|
||||||
QList<TemporaryMountInfo> mounts = m_temporaryMounts;
|
QList<MountPair> mounts;
|
||||||
for (const FilePath &m : deviceSettings->mounts())
|
for (const FilePath &m : deviceSettings->mounts())
|
||||||
mounts.append({m, m});
|
mounts.append({m, m});
|
||||||
|
|
||||||
for (const TemporaryMountInfo &mi : mounts) {
|
for (const MountPair &mi : mounts) {
|
||||||
if (isValidMountInfo(mi))
|
if (isValidMountInfo(mi))
|
||||||
cmds += toMountArg(mi);
|
cmds += toMountArg(mi);
|
||||||
}
|
}
|
||||||
@@ -1307,33 +1303,6 @@ void DockerDeviceFactory::shutdownExistingDevices()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DockerDevicePrivate::addTemporaryMount(const FilePath &path, const FilePath &containerPath)
|
|
||||||
{
|
|
||||||
const bool alreadyAdded = anyOf(m_temporaryMounts,
|
|
||||||
[containerPath](const TemporaryMountInfo &info) {
|
|
||||||
return info.containerPath == containerPath;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (alreadyAdded)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
const bool alreadyManuallyAdded = anyOf(deviceSettings->mounts(),
|
|
||||||
[path](const FilePath &mount) { return mount == path; });
|
|
||||||
|
|
||||||
if (alreadyManuallyAdded)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
const TemporaryMountInfo newMount{path, containerPath};
|
|
||||||
|
|
||||||
const expected_str<void> result = isValidMountInfo(newMount);
|
|
||||||
QTC_ASSERT_EXPECTED(result, return false);
|
|
||||||
|
|
||||||
qCDebug(dockerDeviceLog) << "Adding temporary mount:" << path;
|
|
||||||
m_temporaryMounts.append(newMount);
|
|
||||||
stopCurrentContainer(); // Force re-start with new mounts.
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
expected_str<Environment> DockerDevicePrivate::environment()
|
expected_str<Environment> DockerDevicePrivate::environment()
|
||||||
{
|
{
|
||||||
if (!m_cachedEnviroment) {
|
if (!m_cachedEnviroment) {
|
||||||
@@ -1364,13 +1333,6 @@ void DockerDevicePrivate::changeMounts(QStringList newMounts)
|
|||||||
expected_str<FilePath> DockerDevicePrivate::localSource(const FilePath &other) const
|
expected_str<FilePath> DockerDevicePrivate::localSource(const FilePath &other) const
|
||||||
{
|
{
|
||||||
const auto devicePath = FilePath::fromString(other.path());
|
const auto devicePath = FilePath::fromString(other.path());
|
||||||
for (const TemporaryMountInfo &info : m_temporaryMounts) {
|
|
||||||
if (devicePath.isChildOf(info.containerPath)) {
|
|
||||||
const FilePath relativePath = devicePath.relativeChildPath(info.containerPath);
|
|
||||||
return info.path.pathAppended(relativePath.path());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const FilePath &mount : deviceSettings->mounts()) {
|
for (const FilePath &mount : deviceSettings->mounts()) {
|
||||||
const FilePath mountPoint = mount;
|
const FilePath mountPoint = mount;
|
||||||
if (devicePath.isChildOf(mountPoint)) {
|
if (devicePath.isChildOf(mountPoint)) {
|
||||||
@@ -1395,22 +1357,10 @@ bool DockerDevicePrivate::ensureReachable(const FilePath &other)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto &[path, containerPath] : m_temporaryMounts) {
|
|
||||||
if (path.path() != containerPath.path())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (path == other)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
if (other.isChildOf(path))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (q->filePath(other.path()).exists())
|
if (q->filePath(other.path()).exists())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
addTemporaryMount(other, other);
|
return false;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DockerDevice::prepareForBuild(const Target *target)
|
bool DockerDevice::prepareForBuild(const Target *target)
|
||||||
|
Reference in New Issue
Block a user