metadata: don't raise error if exif is empty when opening an image for saving

Fixes #79 (regression introduced by 26b8860d4bb803cff0277c7b2353b58b5e02fbc6)

(cherry picked from commit 62ae8e15b8ca07cbe545ed42c323e986448c3213)
This commit is contained in:
Alberto Griggio
2020-05-08 02:11:08 -07:00
committed by Lawrence Lee
parent 6224921843
commit 700eeccb39

View File

@@ -52,7 +52,8 @@ private:
constexpr size_t IMAGE_CACHE_SIZE = 200;
std::unique_ptr<Exiv2::Image> open_exiv2(const Glib::ustring& fname)
std::unique_ptr<Exiv2::Image> open_exiv2(const Glib::ustring& fname,
bool check_exif)
{
#ifdef EXV_UNICODE_PATH
glong ws_size = 0;
@@ -68,7 +69,7 @@ std::unique_ptr<Exiv2::Image> open_exiv2(const Glib::ustring& fname)
auto image = Exiv2::ImageFactory::open(Glib::filename_from_utf8(fname));
#endif
image->readMetadata();
if (!image->good() || image->exifData().empty()) {
if (!image->good() || (check_exif && image->exifData().empty())) {
#if EXIV2_TEST_VERSION(0,27,0)
auto error_code = Exiv2::kerErrorMessage;
#else
@@ -121,7 +122,7 @@ void Exiv2Metadata::load() const
if (cache_ && cache_->get(src_, val) && val.second >= finfo->modification_time()) {
image_ = val.first;
} else {
auto img = open_exiv2(src_);
auto img = open_exiv2(src_, true);
image_.reset(img.release());
if (cache_) {
cache_->set(src_, CacheVal(image_, finfo->modification_time()));
@@ -218,7 +219,7 @@ void Exiv2Metadata::do_merge_xmp(Exiv2::Image *dst) const
void Exiv2Metadata::saveToImage(const Glib::ustring &path) const
{
auto dst = open_exiv2(path);
auto dst = open_exiv2(path, false);
if (image_.get()) {
dst->setIptcData(image_->iptcData());
dst->setXmpData(image_->xmpData());
@@ -432,7 +433,7 @@ Exiv2::XmpData Exiv2Metadata::getXmpSidecar(const Glib::ustring &path)
Exiv2::XmpData ret;
auto fname = xmpSidecarPath(path);
if (Glib::file_test(fname, Glib::FILE_TEST_EXISTS)) {
auto image = open_exiv2(fname);
auto image = open_exiv2(fname, false);
ret = image->xmpData();
}
return ret;