Add asset_hashes_can_differ option to the equality checks.
[libdcp.git] / src / asset.cc
index b911c70b958435c754d2e153c58edc811789e18e..330bd653082fcb1ff6441322b06c640ee76f7ca7 100644 (file)
  */
 
 
-#include "raw_convert.h"
 #include "asset.h"
-#include "util.h"
-#include "exceptions.h"
-#include "dcp_assert.h"
+#include "asset_map.h"
 #include "compose.hpp"
+#include "dcp_assert.h"
+#include "exceptions.h"
 #include "pkl.h"
+#include "raw_convert.h"
+#include "util.h"
+#include "warnings.h"
+LIBDCP_DISABLE_WARNINGS
 #include <libxml++/libxml++.h>
+LIBDCP_ENABLE_WARNINGS
 #include <boost/algorithm/string.hpp>
 
 
@@ -94,20 +98,20 @@ Asset::add_to_pkl (shared_ptr<PKL> pkl, path root) const
                return;
        }
 
-       pkl->add_asset (_id, _id, hash(), file_size(_file.get()), pkl_type(pkl->standard()));
+       pkl->add_asset(_id, _id, hash(), file_size(_file.get()), pkl_type(pkl->standard()), _file->filename().string());
 }
 
 
 void
-Asset::write_to_assetmap (xmlpp::Node* node, path root) const
+Asset::add_to_assetmap (AssetMap& asset_map, path root) const
 {
        DCP_ASSERT (_file);
-       write_file_to_assetmap (node, root, _file.get(), _id);
+       add_file_to_assetmap (asset_map, root, _file.get(), _id);
 }
 
 
 void
-Asset::write_file_to_assetmap (xmlpp::Node* node, path root, path file, string id)
+Asset::add_file_to_assetmap (AssetMap& asset_map, path root, path file, string id)
 {
        auto path = relative_to_root (
                canonical(root),
@@ -121,15 +125,7 @@ Asset::write_file_to_assetmap (xmlpp::Node* node, path root, path file, string i
                return;
        }
 
-       auto asset = node->add_child ("Asset");
-       asset->add_child("Id")->add_child_text("urn:uuid:" + id);
-       auto chunk_list = asset->add_child ("ChunkList");
-       auto chunk = chunk_list->add_child ("Chunk");
-
-       chunk->add_child("Path")->add_child_text(path.get().generic_string());
-       chunk->add_child("VolumeIndex")->add_child_text("1");
-       chunk->add_child("Offset")->add_child_text("0");
-       chunk->add_child("Length")->add_child_text(raw_convert<string>(file_size(file)));
+       asset_map.add_asset(id, file, false);
 }
 
 
@@ -147,11 +143,15 @@ Asset::hash (function<void (float)> progress) const
 
 
 bool
-Asset::equals (std::shared_ptr<const Asset> other, EqualityOptions, NoteHandler note) const
+Asset::equals(std::shared_ptr<const Asset> other, EqualityOptions opt, NoteHandler note) const
 {
        if (_hash != other->_hash) {
-               note (NoteType::ERROR, "Asset: hashes differ");
-               return false;
+               if (!opt.asset_hashes_can_differ) {
+                       note(NoteType::ERROR, "Asset: hashes differ");
+                       return false;
+               } else {
+                       note(NoteType::NOTE, "Asset: hashes differ");
+               }
        }
 
        return true;
@@ -162,7 +162,21 @@ void
 Asset::set_file (path file) const
 {
        _file = absolute (file);
-       _hash = {};
+       _hash = optional<string>();
+}
+
+
+void
+Asset::set_file_preserving_hash(path file) const
+{
+       _file = absolute(file);
+}
+
+
+void
+Asset::rename_file(path file)
+{
+       _file = absolute(file);
 }
 
 
@@ -171,3 +185,11 @@ Asset::set_hash (string hash)
 {
        _hash = hash;
 }
+
+
+void
+Asset::unset_hash()
+{
+       _hash = optional<string>();
+}
+