metadata: better error handling
(cherry picked from commit 0e26c15a730854883ae31d164b460d70393c2848)
This commit is contained in:
committed by
Lawrence Lee
parent
e90ffe979b
commit
200779aa84
@@ -54,6 +54,10 @@ Exiv2::Image::AutoPtr open_exiv2(const Glib::ustring& fname)
|
|||||||
#else
|
#else
|
||||||
auto image = Exiv2::ImageFactory::open(Glib::filename_from_utf8(fname));
|
auto image = Exiv2::ImageFactory::open(Glib::filename_from_utf8(fname));
|
||||||
#endif
|
#endif
|
||||||
|
image->readMetadata();
|
||||||
|
if (!image->good()) {
|
||||||
|
throw Exiv2::Error(Exiv2::kerErrorMessage, "exiv2: invalid image");
|
||||||
|
}
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,7 +104,6 @@ void Exiv2Metadata::load() const
|
|||||||
} else {
|
} else {
|
||||||
auto img = open_exiv2(src_);
|
auto img = open_exiv2(src_);
|
||||||
image_.reset(img.release());
|
image_.reset(img.release());
|
||||||
image_->readMetadata();
|
|
||||||
if (cache_) {
|
if (cache_) {
|
||||||
cache_->set(src_, CacheVal(image_, finfo->modification_time()));
|
cache_->set(src_, CacheVal(image_, finfo->modification_time()));
|
||||||
}
|
}
|
||||||
@@ -197,7 +200,6 @@ void Exiv2Metadata::do_merge_xmp(Exiv2::Image *dst) const
|
|||||||
void Exiv2Metadata::saveToImage(const Glib::ustring &path) const
|
void Exiv2Metadata::saveToImage(const Glib::ustring &path) const
|
||||||
{
|
{
|
||||||
auto dst = open_exiv2(path);
|
auto dst = open_exiv2(path);
|
||||||
dst->readMetadata();
|
|
||||||
if (image_.get()) {
|
if (image_.get()) {
|
||||||
dst->setMetadata(*image_);
|
dst->setMetadata(*image_);
|
||||||
if (merge_xmp_) {
|
if (merge_xmp_) {
|
||||||
@@ -323,7 +325,6 @@ Exiv2::XmpData Exiv2Metadata::getXmpSidecar(const Glib::ustring &path)
|
|||||||
auto fname = xmpSidecarPath(path);
|
auto fname = xmpSidecarPath(path);
|
||||||
if (Glib::file_test(fname, Glib::FILE_TEST_EXISTS)) {
|
if (Glib::file_test(fname, Glib::FILE_TEST_EXISTS)) {
|
||||||
auto image = open_exiv2(fname);
|
auto image = open_exiv2(fname);
|
||||||
image->readMetadata();
|
|
||||||
ret = image->xmpData();
|
ret = image->xmpData();
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
Reference in New Issue
Block a user