Skip to content

Commit 889e1c6

Browse files
Merge pull request #2000 from postscript-dev/fix_version_param_in_exiv2
Fix exiv2: verbose extract to stdout (see #1934)
2 parents fde8ed0 + 797f86c commit 889e1c6

File tree

9 files changed

+231
-17
lines changed

9 files changed

+231
-17
lines changed

exiv2.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -643,9 +643,6 @@ when extracting XMP sidecar files:
643643
$ exiv2 -e{tgt3}- filename | [ xmllint .... |] exiv2 -i{tgt2}- filename
644644
```
645645

646-
When filtering from extract to insert, do not use the [--verbose](#verbose)
647-
option with [--extract tgt3](#extract_tgt3) as this outputs unwanted text.
648-
649646
<div id="extract_tgt3">
650647

651648
### **-e** *tgt3*, **--extract** *tgt3*
@@ -663,13 +660,10 @@ Extract target(s) for the [extract](#ex_extract) action. Possible targets are:
663660
| C | Extract ICC profile, to a file called *\<file\>.icc* (see [ICC PROFILES](#icc_profiles)) |
664661
| X | Extract metadata to an XMP sidecar file, \<file\>.xmp. Other targets cannot be used with this, as only XMP data is written. Extracted XMP tags include those converted from Exif and IPTC |
665662
| XX | Extract "raw" metadata to a sidecar file, \<file\>.exv. The remaining targets determine which metadata to include, possible are Exif and IPTC (XMP is always included) |
666-
| - | Output to stdout (see [--insert tgt2](#insert_tgt2) for an example of this feature) |
663+
| - | Output to stdout (see [--insert tgt2](#insert_tgt2) for an example of this feature). This argument ignores [--verbose](#verbose) |
667664

668665
To extract to a location other than the current directory, use [--location dir](#location_dir).
669666

670-
When filtering from extract to insert, do not use the [--verbose](#verbose)
671-
option with **--extract** *tgt3* as this outputs unwanted text.
672-
673667
When extracting, the [--Modify cmd](#Modify_cmd) and [--modify cmdfile](#modify_cmdfile)
674668
options can be used to filter the output (see ['MODIFY' COMMANDS](#modify_cmds)).
675669
For example, extracting Exif and IPTC "raw" metadata and adding an

src/actions.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,7 +1294,8 @@ namespace Action {
12941294
int Modify::applyCommands(Exiv2::Image* pImage)
12951295
{
12961296
if (!Params::instance().jpegComment_.empty()) {
1297-
if (Params::instance().verbose_) {
1297+
// If modify is used when extracting to stdout then ignore verbose
1298+
if (Params::instance().verbose_ && !(Params::instance().action_ & Action::extract && Params::instance().target_ & Params::ctStdInOut)) {
12981299
std::cout << _("Setting JPEG comment") << " '"
12991300
<< Params::instance().jpegComment_
13001301
<< "'"
@@ -1335,7 +1336,8 @@ namespace Action {
13351336

13361337
int Modify::addMetadatum(Exiv2::Image* pImage, const ModifyCmd& modifyCmd)
13371338
{
1338-
if (Params::instance().verbose_) {
1339+
// If modify is used when extracting to stdout then ignore verbose
1340+
if (Params::instance().verbose_ && !(Params::instance().action_ & Action::extract && Params::instance().target_ & Params::ctStdInOut)) {
13391341
std::cout << _("Add") << " " << modifyCmd.key_ << " \""
13401342
<< modifyCmd.value_ << "\" ("
13411343
<< Exiv2::TypeInfo::typeName(modifyCmd.typeId_)
@@ -1371,7 +1373,8 @@ namespace Action {
13711373
// empty metadatum if reading the value fails
13721374
int Modify::setMetadatum(Exiv2::Image* pImage, const ModifyCmd& modifyCmd)
13731375
{
1374-
if (Params::instance().verbose_) {
1376+
// If modify is used when extracting to stdout then ignore verbose
1377+
if (Params::instance().verbose_ && !(Params::instance().action_ & Action::extract && Params::instance().target_ & Params::ctStdInOut)) {
13751378
std::cout << _("Set") << " " << modifyCmd.key_ << " \""
13761379
<< modifyCmd.value_ << "\" ("
13771380
<< Exiv2::TypeInfo::typeName(modifyCmd.typeId_)
@@ -1438,7 +1441,8 @@ namespace Action {
14381441

14391442
void Modify::delMetadatum(Exiv2::Image* pImage, const ModifyCmd& modifyCmd)
14401443
{
1441-
if (Params::instance().verbose_) {
1444+
// If modify is used when extracting to stdout then ignore verbose
1445+
if (Params::instance().verbose_ && !(Params::instance().action_ & Action::extract && Params::instance().target_ & Params::ctStdInOut)) {
14421446
std::cout << _("Del") << " " << modifyCmd.key_ << std::endl;
14431447
}
14441448

@@ -1470,7 +1474,8 @@ namespace Action {
14701474

14711475
void Modify::regNamespace(const ModifyCmd& modifyCmd)
14721476
{
1473-
if (Params::instance().verbose_) {
1477+
// If modify is used when extracting to stdout then ignore verbose
1478+
if (Params::instance().verbose_ && !(Params::instance().action_ & Action::extract && Params::instance().target_ & Params::ctStdInOut)) {
14741479
std::cout << _("Reg ") << modifyCmd.key_ << "=\""
14751480
<< modifyCmd.value_ << "\"" << std::endl;
14761481
}
@@ -1920,7 +1925,7 @@ namespace {
19201925
// Copy each type of metadata
19211926
if ( Params::instance().target_ & Params::ctExif
19221927
&& !sourceImage->exifData().empty()) {
1923-
if (Params::instance().verbose_) {
1928+
if (Params::instance().verbose_ && !bStdout) {
19241929
std::cout << _("Writing Exif data from") << " " << source
19251930
<< " " << _("to") << " " << target << std::endl;
19261931
}
@@ -1934,7 +1939,7 @@ namespace {
19341939
}
19351940
if ( Params::instance().target_ & Params::ctIptc
19361941
&& !sourceImage->iptcData().empty()) {
1937-
if (Params::instance().verbose_) {
1942+
if (Params::instance().verbose_ && !bStdout) {
19381943
std::cout << _("Writing IPTC data from") << " " << source
19391944
<< " " << _("to") << " " << target << std::endl;
19401945
}
@@ -1948,7 +1953,7 @@ namespace {
19481953
}
19491954
if ( Params::instance().target_ & (Params::ctXmp|Params::ctXmpRaw)
19501955
&& !sourceImage->xmpData().empty()) {
1951-
if (Params::instance().verbose_) {
1956+
if (Params::instance().verbose_ && !bStdout) {
19521957
std::cout << _("Writing XMP data from") << " " << source
19531958
<< " " << _("to") << " " << target << std::endl;
19541959
}
@@ -1975,7 +1980,7 @@ namespace {
19751980
}
19761981
if ( Params::instance().target_ & Params::ctComment
19771982
&& !sourceImage->comment().empty()) {
1978-
if (Params::instance().verbose_) {
1983+
if (Params::instance().verbose_ && !bStdout) {
19791984
std::cout << _("Writing JPEG comment from") << " " << source
19801985
<< " " << _("to") << " " << tgt << std::endl;
19811986
}

src/exiv2.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ int main(int argc, char* const argv[])
161161
int s = static_cast<int>(params.files_.size());
162162
int w = s > 9 ? s > 99 ? 3 : 2 : 1;
163163
for (auto&& file : params.files_) {
164-
if (params.verbose_) {
164+
// If extracting to stdout then ignore verbose
165+
if (params.verbose_ && !(params.action_ & Action::extract && params.target_ & Params::ctStdInOut)) {
165166
std::cout << _("File") << " " << std::setw(w) << std::right << n++ << "/" << s << ": " << file
166167
<< std::endl;
167168
}
10.6 KB
Loading

test/data/issue_1934_poc4.jpg

20.9 KB
Loading
21 Bytes
Binary file not shown.

test/data/issue_1934_poc4_ref.exv

13.2 KB
Binary file not shown.

test/data/issue_1934_poc4_ref.icc

3.07 KB
Binary file not shown.
Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import system_tests
4+
from system_tests import CaseMeta, path, check_no_ASAN_UBSAN_errors
5+
6+
class TestVerboseExtractXmpSidecarToStdout(metaclass=CaseMeta):
7+
"""
8+
Regression test for 'verbose extracting XMP sidecar to stdout' bug described in:
9+
https://github.com/Exiv2/exiv2/issues/1934
10+
"""
11+
url = "https://github.com/Exiv2/exiv2/issues/1934"
12+
13+
filename = path("$data_path/issue_1934_poc4.jpg")
14+
commands = ["$exiv2 --verbose --extract X- $filename"]
15+
16+
stdout = ["""<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
17+
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 4.4.0-Exiv2">
18+
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
19+
<rdf:Description rdf:about=""
20+
xmlns:dc="http://purl.org/dc/elements/1.1/"
21+
xmlns:exif="http://ns.adobe.com/exif/1.0/">
22+
<dc:subject>
23+
<rdf:Bag>
24+
<rdf:li>Value 1</rdf:li>
25+
</rdf:Bag>
26+
</dc:subject>
27+
<exif:UserComment>
28+
<rdf:Alt>
29+
<rdf:li xml:lang="x-default">Value 1</rdf:li>
30+
</rdf:Alt>
31+
</exif:UserComment>
32+
</rdf:Description>
33+
</rdf:RDF>
34+
</x:xmpmeta>
35+
<?xpacket end="w"?>"""]
36+
37+
stderr = [""]
38+
retval = [0]
39+
40+
class TestVerboseModifyRegAddExtractXmpSidecarToStdout(metaclass=CaseMeta):
41+
"""
42+
Regression test for 'verbose with modify register and add when extracting XMP sidecar to stdout'
43+
bug described in:
44+
https://github.com/Exiv2/exiv2/issues/1934
45+
"""
46+
url = "https://github.com/Exiv2/exiv2/issues/1934"
47+
48+
filename = path("$data_path/issue_1934_poc4.jpg")
49+
commands = ["""$exiv2 --verbose --Modify "reg TempGroup tempgroup/" --Modify "add Xmp.TempGroup.val Value 1" --extract X- $filename"""]
50+
51+
stdout = ["""<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
52+
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 4.4.0-Exiv2">
53+
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
54+
<rdf:Description rdf:about=""
55+
xmlns:dc="http://purl.org/dc/elements/1.1/"
56+
xmlns:TempGroup="tempgroup/"
57+
xmlns:exif="http://ns.adobe.com/exif/1.0/"
58+
TempGroup:val="Value 1">
59+
<dc:subject>
60+
<rdf:Bag>
61+
<rdf:li>Value 1</rdf:li>
62+
</rdf:Bag>
63+
</dc:subject>
64+
<exif:UserComment>
65+
<rdf:Alt>
66+
<rdf:li xml:lang="x-default">Value 1</rdf:li>
67+
</rdf:Alt>
68+
</exif:UserComment>
69+
</rdf:Description>
70+
</rdf:RDF>
71+
</x:xmpmeta>
72+
<?xpacket end="w"?>"""]
73+
74+
stderr = [""]
75+
retval = [0]
76+
77+
class TestVerboseModifySetExtractXmpSidecarToStdout(metaclass=CaseMeta):
78+
"""
79+
Regression test for 'verbose modify set when extracting XMP sidecar to stdout' bug described in:
80+
https://github.com/Exiv2/exiv2/issues/1934
81+
"""
82+
url = "https://github.com/Exiv2/exiv2/issues/1934"
83+
84+
filename = path("$data_path/issue_1934_poc4.jpg")
85+
commands = ["""$exiv2 --verbose --Modify "set Xmp.dc.subject Value 2" --extract X- $filename"""]
86+
87+
stdout = ["""<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
88+
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 4.4.0-Exiv2">
89+
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
90+
<rdf:Description rdf:about=""
91+
xmlns:dc="http://purl.org/dc/elements/1.1/"
92+
xmlns:exif="http://ns.adobe.com/exif/1.0/">
93+
<dc:subject>
94+
<rdf:Bag>
95+
<rdf:li>Value 1</rdf:li>
96+
<rdf:li>Value 2</rdf:li>
97+
</rdf:Bag>
98+
</dc:subject>
99+
<exif:UserComment>
100+
<rdf:Alt>
101+
<rdf:li xml:lang="x-default">Value 1</rdf:li>
102+
</rdf:Alt>
103+
</exif:UserComment>
104+
</rdf:Description>
105+
</rdf:RDF>
106+
</x:xmpmeta>
107+
<?xpacket end="w"?>"""]
108+
109+
stderr = [""]
110+
retval = [0]
111+
112+
class TestVerboseModifyDelExtractXmpSidecarToStdout(metaclass=CaseMeta):
113+
"""
114+
Regression test for 'verbose modify delete when extracting XMP sidecar to stdout' bug described in:
115+
https://github.com/Exiv2/exiv2/issues/1934
116+
"""
117+
url = "https://github.com/Exiv2/exiv2/issues/1934"
118+
119+
filename = path("$data_path/issue_1934_poc4.jpg")
120+
commands = ["""$exiv2 --verbose --Modify "del Xmp.dc.subject" --extract X- $filename"""]
121+
122+
stdout = ["""<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
123+
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 4.4.0-Exiv2">
124+
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
125+
<rdf:Description rdf:about=""
126+
xmlns:exif="http://ns.adobe.com/exif/1.0/">
127+
<exif:UserComment>
128+
<rdf:Alt>
129+
<rdf:li xml:lang="x-default">Value 1</rdf:li>
130+
</rdf:Alt>
131+
</exif:UserComment>
132+
</rdf:Description>
133+
</rdf:RDF>
134+
</x:xmpmeta>
135+
<?xpacket end="w"?>"""]
136+
137+
stderr = [""]
138+
retval = [0]
139+
140+
class TestVerboseExtractRawMetadataToStdout(metaclass=CaseMeta):
141+
"""
142+
Regression test for 'verbose extracting raw metadata to stdout' bug described in:
143+
https://github.com/Exiv2/exiv2/issues/1934
144+
"""
145+
url = "https://github.com/Exiv2/exiv2/issues/1934"
146+
147+
filenameJPG = path("$data_path/issue_1934_poc4.jpg")
148+
filenameEXV = path("$tmp_path/issue_1934_poc4.exv")
149+
filenameRefEXV = path("$data_path/issue_1934_poc4_ref.exv")
150+
151+
commands = ["$exiv2 --verbose --extract XXeix- $filenameJPG > $filenameEXV",
152+
"cmp $filenameEXV $filenameRefEXV"]
153+
154+
stderr = [""]*2
155+
retval = [0]*2
156+
157+
compare_stdout = check_no_ASAN_UBSAN_errors
158+
159+
class TestVerboseExtractThumbnailToStdout(metaclass=CaseMeta):
160+
"""
161+
Regression test for 'verbose extracting the thumbnail to stdout' bug described in:
162+
https://github.com/Exiv2/exiv2/issues/1934
163+
"""
164+
url = "https://github.com/Exiv2/exiv2/issues/1934"
165+
166+
filenameJPG = path("$data_path/issue_1934_poc4.jpg")
167+
filenameThumbnail = path("$tmp_path/issue_1934_poc4-thumb.jpg")
168+
filenameRefThumbnail = path("$data_path/issue_1934_poc4-thumb_ref.jpg")
169+
170+
commands = ["$exiv2 --verbose --extract t- $filenameJPG > $filenameThumbnail",
171+
"cmp $filenameThumbnail $filenameRefThumbnail"]
172+
173+
stderr = [""]*2
174+
retval = [0]*2
175+
176+
compare_stdout = check_no_ASAN_UBSAN_errors
177+
178+
class TestVerboseExtractICCProfileToStdout(metaclass=CaseMeta):
179+
"""
180+
Regression test for 'verbose extracting the ICC profile to stdout' bug described in:
181+
https://github.com/Exiv2/exiv2/issues/1934
182+
"""
183+
url = "https://github.com/Exiv2/exiv2/issues/1934"
184+
185+
filenameJPG = path("$data_path/issue_1934_poc4.jpg")
186+
filenameICC = path("$tmp_path/issue_1934_poc4.icc")
187+
filenameRefICC = path("$data_path/issue_1934_poc4_ref.icc")
188+
189+
commands = ["$exiv2 --verbose --extract C- $filenameJPG > $filenameICC",
190+
"cmp $filenameICC $filenameRefICC"]
191+
192+
stderr = [""]*2
193+
retval = [0]*2
194+
195+
compare_stdout = check_no_ASAN_UBSAN_errors
196+
197+
class TestVerboseExtractCommentToStdout(metaclass=CaseMeta):
198+
"""
199+
Regression test for 'verbose extracting the comment to stdout' bug described in:
200+
https://github.com/Exiv2/exiv2/issues/1934
201+
"""
202+
url = "https://github.com/Exiv2/exiv2/issues/1934"
203+
204+
filenameJPG = path("$data_path/issue_1934_poc4.jpg")
205+
filenameComment = path("$tmp_path/issue_1934_poc4_comment.txt")
206+
filenameRefComment = path("$data_path/issue_1934_poc4_comment_ref.txt")
207+
208+
commands = ["$exiv2 --verbose --extract c- $filenameJPG > $filenameComment",
209+
"cmp $filenameComment $filenameRefComment"]
210+
211+
stderr = [""]*2
212+
retval = [0]*2
213+
214+
compare_stdout = check_no_ASAN_UBSAN_errors

0 commit comments

Comments
 (0)