lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi] [PATCH] loaded_files_cache<> error reporting


From: Vaclav Slavik
Subject: [lmi] [PATCH] loaded_files_cache<> error reporting
Date: Wed, 01 Aug 2012 19:32:04 +0200
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:14.0) Gecko/20120713 Thunderbird/14.0

Hi,

my changes added a call to boost::fs::last_write_time() before a file
was loaded and this broke nice reporting of non-existent files. This
patch restores the usual way missing files are reported in LMI.

Vaclav



diff --git a/loaded_files_cache.hpp b/loaded_files_cache.hpp
index d7bde11..3483b8e 100644
--- a/loaded_files_cache.hpp
+++ b/loaded_files_cache.hpp
@@ -26,6 +26,7 @@
 
 #include "config.hpp"
 
+#include "alert.hpp"
 #include "uncopyable_lmi.hpp"
 
 #include <boost/filesystem/operations.hpp>
@@ -56,30 +57,42 @@ class loaded_files_cache
     // if it was modified since the cached copy was read.
     value_ptr_type get(key_type const& filename)
         {
-        std::time_t const write_time = fs::last_write_time(filename);
-
-        typename map_type::iterator i = cache_.lower_bound(filename);
-        if
-            (  i != cache_.end()
-            && i->first == filename
-            && write_time == i->second.write_time
-            )
+        try
             {
-            return i->second.data;
+            std::time_t const write_time = fs::last_write_time(filename);
+
+            typename map_type::iterator i = cache_.lower_bound(filename);
+            if
+                (  i != cache_.end()
+                && i->first == filename
+                && write_time == i->second.write_time
+                )
+                {
+                return i->second.data;
+                }
+
+            // create the value before calling insert() because the call may 
throw
+            value_ptr_type value(new value_type(filename));
+
+            // insert() doesn't update the value if the key is already 
present, so
+            // insert a dummy value and then modify it -- this will work for 
both
+            // existing and new keys.
+            i = cache_.insert(i, typename map_type::value_type(filename, 
record()));
+            record& rec = i->second;
+            rec.write_time = write_time;
+            rec.data = value;
+
+            return value;
+            }
+        catch(fs::filesystem_error const&)
+            {
+            fatal_error()
+                << "File '"
+                << filename
+                << "' is required but could not be found. Try reinstalling."
+                << LMI_FLUSH
+                ;
             }
-
-        // create the value before calling insert() because the call may throw
-        value_ptr_type value(new value_type(filename));
-
-        // insert() doesn't update the value if the key is already present, so
-        // insert a dummy value and then modify it -- this will work for both
-        // existing and new keys.
-        i = cache_.insert(i, typename map_type::value_type(filename, 
record()));
-        record& rec = i->second;
-        rec.write_time = write_time;
-        rec.data = value;
-
-        return value;
         }
 
     // Return singleton instance of the cache.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]