From 87394de1cf64b811ccac43cde30f9cc0e8ff8b13 Mon Sep 17 00:00:00 2001 From: Jacob Dufault Date: Fri, 22 Sep 2017 00:39:59 -0700 Subject: [PATCH] Handle error condition instead of asserting, since it is occassionaly hit. This needs to be debugged later. --- src/cache.cc | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/cache.cc b/src/cache.cc index daca8bdb..f8bfcba1 100644 --- a/src/cache.cc +++ b/src/cache.cc @@ -4,7 +4,6 @@ #include "language_server_api.h" #include "platform.h" - #include #include @@ -51,15 +50,17 @@ void WriteToCache(Config* config, IndexFile& file) { std::string cache_basename = GetCachedBaseFileName(config->cacheDirectory, file.path); - LOG_IF_S(ERROR, file.file_contents_.empty()) - << "Writing " << file.path << " to cache but it has no contents"; - - assert(!file.file_contents_.empty()); - std::ofstream cache_content; - cache_content.open(cache_basename); - assert(cache_content.good()); - cache_content << file.file_contents_; - cache_content.close(); + if (file.file_contents_.empty()) { + LOG_S(ERROR) << "No cached file contents; performing potentially stale " + << "file-copy for " << file.path; + CopyFileTo(cache_basename, file.path); + } else { + std::ofstream cache_content; + cache_content.open(cache_basename); + assert(cache_content.good()); + cache_content << file.file_contents_; + cache_content.close(); + } std::string indexed_content = Serialize(file); std::ofstream cache;