From ba7d09616f8e529d71ff1e7843f39f22d2823409 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 25 Apr 2022 21:59:26 +0200 Subject: Update PKL assets before writing it. --- src/dcp.cc | 18 +++++++++--------- src/pkl.cc | 7 +++++++ src/pkl.h | 1 + 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/dcp.cc b/src/dcp.cc index 5da4bbd6..f7b83b01 100644 --- a/src/dcp.cc +++ b/src/dcp.cc @@ -400,16 +400,16 @@ DCP::write_xml ( i->write_xml (_directory / (name_format.get(values, "_" + i->id() + ".xml")), signer); } - shared_ptr pkl; - if (_pkls.empty()) { - pkl = make_shared(standard, annotation_text, issue_date, issuer, creator); - _pkls.push_back (pkl); - for (auto i: assets()) { - i->add_to_pkl (pkl, _directory); - } - } else { - pkl = _pkls.front (); + _pkls.push_back(make_shared(standard, annotation_text, issue_date, issuer, creator)); + } + + auto pkl = _pkls.front(); + + /* The assets may have changed since we read the PKL, so re-add them */ + pkl->clear_assets(); + for (auto asset: assets()) { + asset->add_to_pkl(pkl, _directory); } NameFormat::Map values; diff --git a/src/pkl.cc b/src/pkl.cc index 22589b4d..5846b68d 100644 --- a/src/pkl.cc +++ b/src/pkl.cc @@ -159,3 +159,10 @@ PKL::type (string id) const return {}; } + + +void +PKL::clear_assets() +{ + _asset_list.clear(); +} diff --git a/src/pkl.h b/src/pkl.h index 01988e70..9313f0f6 100644 --- a/src/pkl.h +++ b/src/pkl.h @@ -76,6 +76,7 @@ public: boost::optional hash (std::string id) const; boost::optional type (std::string id) const; + void clear_assets(); void add_asset (std::string id, boost::optional annotation_text, std::string hash, int64_t size, std::string type); void write (boost::filesystem::path file, std::shared_ptr signer) const; -- cgit v1.2.3