]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
refactor: Improve util::read_file usage
authorJoel Rosdahl <joel@rosdahl.net>
Mon, 24 Jul 2023 11:51:42 +0000 (13:51 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 25 Jul 2023 13:58:24 +0000 (15:58 +0200)
src/storage/remote/FileStorage.cpp

index ca18dd9f63ad2806defdb356bfd97c221748257d..da68921b56a836f78636ce4d19495888df4e6961 100644 (file)
@@ -128,12 +128,11 @@ FileStorageBackend::get(const Hash::Digest& key)
     util::set_timestamps(path);
   }
 
-  auto value = util::read_file<util::Bytes>(path);
-  if (!value) {
-    LOG("Failed to read {}: {}", path, value.error());
-    return tl::unexpected(Failure::error);
-  }
-  return std::move(*value);
+  return util::read_file<util::Bytes>(path).transform_error(
+    [&](const auto& error) {
+      LOG("Failed to read {}: {}", path, error);
+      return Failure::error;
+    });
 }
 
 tl::expected<bool, RemoteStorage::Backend::Failure>