Support file:// URI-style file specifiers in asset map.
authorCarl Hetherington <cth@carlh.net>
Sat, 3 May 2014 11:35:41 +0000 (12:35 +0100)
committerCarl Hetherington <cth@carlh.net>
Sat, 3 May 2014 11:35:41 +0000 (12:35 +0100)
Allow DCP reads to continue in the face of some errors (currently
just missing assets).

src/dcp.cc
src/dcp.h

index d383eeac013e4167bff0da1109be503e721cb60b..c0d148c5a8596b3a5b92c78298327291357df233 100644 (file)
@@ -55,8 +55,10 @@ using std::ostream;
 using std::make_pair;
 using std::map;
 using std::cout;
+using std::exception;
 using boost::shared_ptr;
 using boost::lexical_cast;
+using boost::algorithm::starts_with;
 using namespace dcp;
 
 DCP::DCP (boost::filesystem::path directory)
@@ -66,8 +68,18 @@ DCP::DCP (boost::filesystem::path directory)
        _directory = boost::filesystem::canonical (_directory);
 }
 
+template<class T> void
+survivable_error (bool keep_going, list<string>* errors, T const & e)
+{
+       if (keep_going && errors) {
+               errors->push_back (e.what ());
+       } else {
+               throw e;
+       }
+}
+
 void
-DCP::read ()
+DCP::read (bool keep_going, list<string>* errors)
 {
        /* Read the ASSETMAP */
        
@@ -88,15 +100,22 @@ DCP::read ()
                if ((*i)->node_child("ChunkList")->node_children("Chunk").size() != 1) {
                        boost::throw_exception (XMLError ("unsupported asset chunk count"));
                }
-               paths.insert (make_pair (
-                       (*i)->string_child ("Id"),
-                       (*i)->node_child("ChunkList")->node_child("Chunk")->string_child ("Path")
-                                     ));
+               string p = (*i)->node_child("ChunkList")->node_child("Chunk")->string_child ("Path");
+               if (starts_with (p, "file://")) {
+                       p = p.substr (7);
+               }
+               paths.insert (make_pair ((*i)->string_child ("Id"), p));
        }
 
        /* Read all the assets from the asset map */
        for (map<string, boost::filesystem::path>::const_iterator i = paths.begin(); i != paths.end(); ++i) {
                boost::filesystem::path path = _directory / i->second;
+
+               if (!boost::filesystem::exists (path)) {
+                       survivable_error (keep_going, errors, FileError ("file not found", path, -1));
+                       continue;
+               }
+               
                if (boost::algorithm::ends_with (path.string(), ".xml")) {
                        xmlpp::DomParser* p = new xmlpp::DomParser;
                        try {
index 450a3c00a4b72db6d39a8f6a0c62bd15c8fc0c88..48b2df3c201a81167777fa2c40b81b49d8cfd86d 100644 (file)
--- a/src/dcp.h
+++ b/src/dcp.h
@@ -68,7 +68,11 @@ public:
         */
        DCP (boost::filesystem::path directory);
 
-       void read ();
+       /** Read the DCP's structure into this object.
+        *  @param keep_going true to try to keep going in the face of (some) errors.
+        *  @param notes List of errors that will be added to if keep_going is true.
+        */
+       void read (bool keep_going = false, std::list<std::string>* errors = 0);
 
        /** Compare this DCP with another, according to various options.
         *  @param other DCP to compare this one to.