CopyError(std::string message) : std::runtime_error(message) {}
};
- auto maybe_copy = [&assets, output_dir](
+ vector<string> already_copied;
+
+ auto maybe_copy = [&assets, &already_copied, output_dir](
string asset_id,
bool rename,
bool hard_link,
bool soft_link,
boost::optional<boost::filesystem::path> extra = boost::none
) {
+
+ if (std::find(already_copied.begin(), already_copied.end(), asset_id) != already_copied.end()) {
+ return;
+ }
+
auto iter = std::find_if(assets.begin(), assets.end(), [asset_id](shared_ptr<const dcp::Asset> a) { return a->id() == asset_id; });
if (iter != assets.end()) {
DCP_ASSERT((*iter)->file());
throw CopyError(String::compose("Could not copy asset %1: %2", input_path.string(), ec.message()));
}
}
- (*iter)->set_file(output_path);
+ (*iter)->set_file_preserving_hash(output_path);
+ already_copied.push_back(asset_id);
} else {
boost::system::error_code ec;
boost::filesystem::remove_all(*output_dir, ec);
}
};
+ auto maybe_copy_font = [&maybe_copy](shared_ptr<const dcp::SubtitleAsset> asset, bool rename, bool hard_link, bool soft_link) {
+ auto interop = dynamic_pointer_cast<const dcp::InteropSubtitleAsset>(asset);
+ boost::optional<boost::filesystem::path> extra;
+ if (interop) {
+ extra = interop->id();
+ for (auto font_asset: interop->font_assets()) {
+ maybe_copy(font_asset->id(), rename, hard_link, soft_link, extra);
+ }
+ }
+ return extra;
+ };
+
/* Copy assets that the CPLs need */
try {
for (auto cpl: cpls) {
for (auto reel: cpl->reels()) {
maybe_copy_from_reel(reel->main_picture(), rename, hard_link, soft_link);
maybe_copy_from_reel(reel->main_sound(), rename, hard_link, soft_link);
- boost::optional<boost::filesystem::path> extra;
if (reel->main_subtitle()) {
- auto interop = dynamic_pointer_cast<dcp::InteropSubtitleAsset>(reel->main_subtitle()->asset());
- if (interop) {
- extra = interop->id();
- for (auto font_asset: interop->font_assets()) {
- maybe_copy(font_asset->id(), rename, hard_link, soft_link, extra);
- }
- }
+ auto extra = maybe_copy_font(reel->main_subtitle()->asset(), rename, hard_link, soft_link);
+ maybe_copy_from_reel(reel->main_subtitle(), rename, hard_link, soft_link, extra);
}
- maybe_copy_from_reel(reel->main_subtitle(), rename, hard_link, soft_link, extra);
for (auto ccap: reel->closed_captions()) {
- maybe_copy_from_reel(ccap, rename, hard_link, soft_link);
+ auto extra = maybe_copy_font(ccap->asset(), rename, hard_link, soft_link);
+ maybe_copy_from_reel(ccap, rename, hard_link, soft_link, extra);
}
maybe_copy_from_reel(reel->atmos(), rename, hard_link, soft_link);
}
dcp.resolve_refs(assets);
dcp.set_annotation_text(cpls[0]->annotation_text().get_value_or(""));
- dcp.write_xml(Config::instance()->signer_chain());
+ try {
+ dcp.write_xml(Config::instance()->signer_chain());
+ } catch (dcp::UnresolvedRefError& e) {
+ return String::compose("%1\nPerhaps you need to give a -d parameter to say where this asset is located.", e.what());
+ }
return {};
}