diff options
author | hjk <[email protected]> | 2021-06-29 09:41:53 +0200 |
---|---|---|
committer | hjk <[email protected]> | 2021-06-29 12:34:43 +0000 |
commit | 1e1c556bc83edbd5a2675e803bfe6df2f2ef9459 (patch) | |
tree | d9c46e2013af54e5c60e54489fc455c94c4fa10e /src/libs/utils/fileutils.cpp | |
parent | b058b6e8417915e6a6922402aa0d2a06e81915a4 (diff) |
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 <[email protected]>
Diffstat (limited to 'src/libs/utils/fileutils.cpp')
-rw-r--r-- | src/libs/utils/fileutils.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/libs/utils/fileutils.cpp b/src/libs/utils/fileutils.cpp index c21a17d86b6..cc51b136971 100644 --- a/src/libs/utils/fileutils.cpp +++ b/src/libs/utils/fileutils.cpp @@ -898,6 +898,20 @@ bool FilePath::ensureWritableDir() const return QDir().mkpath(m_data); } +bool FilePath::ensureExistingFile() const +{ + if (needsDevice()) { + QTC_ASSERT(s_deviceHooks.ensureExistingFile, return false); + return s_deviceHooks.ensureExistingFile(*this); + } + QFile f(m_data); + if (f.exists()) + return true; + f.open(QFile::WriteOnly); + f.close(); + return f.exists(); +} + bool FilePath::isExecutableFile() const { if (needsDevice()) { |