diff options
author | Aron Budea <aron.budea@collabora.com> | 2022-09-01 05:41:02 +0200 |
---|---|---|
committer | Gökay ŞATIR <gokaysatir@gmail.com> | 2022-09-13 12:19:14 +0300 |
commit | 2e081ad06b16b8869148954a6b844bfdfb1a763c (patch) | |
tree | a543f32df2d49521f41ccc029d03d903e55bccc1 | |
parent | wsd: test: enable IsModifiedByUser assertion (diff) | |
download | online-2e081ad06b16b8869148954a6b844bfdfb1a763c.tar.gz online-2e081ad06b16b8869148954a6b844bfdfb1a763c.zip |
wsd: Cache result of disk space check, too
...when it's requested.
Previously always an empty string was returned on subsequent
calls, and the error message was only shown once.
Signed-off-by: Aron Budea <aron.budea@collabora.com>
Change-Id: I7645c7770e3e1712c8ef1b3ad145daec14530fb0
(cherry picked from commit 64b0355f648f72652b739ba27310a7d703419f4c)
-rw-r--r-- | common/FileUtil.cpp | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/common/FileUtil.cpp b/common/FileUtil.cpp index 1651168aa1..3e1c056284 100644 --- a/common/FileUtil.cpp +++ b/common/FileUtil.cpp @@ -466,25 +466,32 @@ namespace FileUtil std::string checkDiskSpaceOnRegisteredFileSystems(const bool cacheLastCheck) { static std::chrono::steady_clock::time_point lastCheck; + static std::string lastResult; std::chrono::steady_clock::time_point now(std::chrono::steady_clock::now()); std::lock_guard<std::mutex> lock(fsmutex); - // Don't check more often than once a minute - if (std::chrono::duration_cast<std::chrono::seconds>(now - lastCheck).count() < 60) - return std::string(); - if (cacheLastCheck) + { + // Don't check more often than once a minute + if (std::chrono::duration_cast<std::chrono::seconds>(now - lastCheck).count() < 60) + return lastResult; + lastCheck = now; + } for (const auto& i: filesystems) { if (!checkDiskSpace(i.getPath())) { + if (cacheLastCheck) + lastResult = i.getPath(); return i.getPath(); } } + if (cacheLastCheck) + lastResult = std::string(); return std::string(); } #endif |