Utils: Add a FilePath::ensureExistingFile

Essentially a kind of 'touch', to be used in the CMake file API.

Change-Id: Iaae62b441c0006b39d4bef5f06420e798c28c2a5
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2021-06-29 09:41:53 +02:00
parent b058b6e841
commit 1e1c556bc8
7 changed files with 47 additions and 0 deletions

View File

@@ -877,6 +877,22 @@ bool DockerDevice::exists(const FilePath &filePath) const
return exitCode == 0;
}
bool DockerDevice::ensureExistingFile(const FilePath &filePath) const
{
QTC_ASSERT(handlesFile(filePath), return false);
tryCreateLocalFileAccess();
if (hasLocalFileAccess()) {
const FilePath localAccess = mapToLocalAccess(filePath);
const bool res = localAccess.ensureExistingFile();
LOG("Ensure existing file? " << filePath.toUserOutput() << localAccess.toUserOutput() << res);
return res;
}
const QString path = filePath.path();
const CommandLine cmd("touch", {path});
const int exitCode = d->runSynchronously(cmd);
return exitCode == 0;
}
bool DockerDevice::removeFile(const FilePath &filePath) const
{
QTC_ASSERT(handlesFile(filePath), return false);