From 2dafeadd0c6fffb0c2aec9cde066ba44f347126c Mon Sep 17 00:00:00 2001 From: hjk Date: Fri, 16 Jul 2021 07:42:59 +0200 Subject: [PATCH] Docker: Enable DockerDevice::removeRecursively() With some half-baked sanity checks. Change-Id: Ic3b9977f2bb8218105c5b7dba26df5cb933840c6 Reviewed-by: Christian Stenger --- src/plugins/docker/dockerdevice.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/plugins/docker/dockerdevice.cpp b/src/plugins/docker/dockerdevice.cpp index 65180deecd2..35df348c33a 100644 --- a/src/plugins/docker/dockerdevice.cpp +++ b/src/plugins/docker/dockerdevice.cpp @@ -1195,9 +1195,15 @@ bool DockerDevice::removeRecursively(const FilePath &filePath) const LOG("Remove recursively? " << filePath.toUserOutput() << localAccess.toUserOutput() << res); return res; } -// Open this up only when really needed. -// return d->runInContainer({"rm", "-rf", {filePath.path()}}); - return false; + + const QString path = filePath.cleanPath().path(); + // We are expecting this only to be called in a context of build directories or similar. + // Chicken out in some cases that _might_ be user code errors. + QTC_ASSERT(path.startsWith('/'), return false); + const int levelsNeeded = path.startsWith("/home/" ? 4 : 3); + QTC_ASSERT(path.count('/') >= levelsNeeded, return false); + + return d->runInContainer({"rm", {"-rf", "--", path}}); } bool DockerDevice::copyFile(const FilePath &filePath, const FilePath &target) const