Bug 138540 - Pictures files are updated (but not modified) when setting new metadatas albeit they are unset
Summary: Pictures files are updated (but not modified) when setting new metadatas albe...
Status: RESOLVED WORKSFORME
Alias: None
Product: digikam
Classification: Applications
Component: Setup-Metadata (show other bugs)
Version: 0.9.0
Platform: Ubuntu Linux
: NOR normal
Target Milestone: ---
Assignee: Digikam Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-12-08 16:33 UTC by Fabien
Modified: 2017-08-10 20:14 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In: 0.9.0


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fabien 2006-12-08 16:33:44 UTC
Version:           0.9.0-svn (using KDE KDE 3.5.2)
Installed from:    Ubuntu Packages
OS:                Linux

When digikam is configured to not save any metadata, it still call exiv2 to write metadata to file.
Note: as expected, it doesn't put new comment, tag, rating into the file, it just rewrite the file, without modifying it.

1) digikam configuration
[Metadata Settings]
IPTC Author=
IPTC Author Title=
IPTC Copyright=
IPTC Credit=
IPTC Source=
Save Date Time=false
Save EXIF Comments=false
Save IPTC Credits=false
Save IPTC Photographer ID=false
Save IPTC Rating=false
Save IPTC Tags=false


2) example
if I modify a comment (or tags, rating) on a picture, its file has a new date. File is still the same (same md5sum).

3) how to check that exiv2 is called for that

I have an album directory with that (note that the directory is not writable):
$ ls -la
total 3079
dr-x------  2 fabien fabien     112 2006-12-08 16:05 .
drwxr-xr-x 14 fabien fabien     408 2006-12-08 16:06 ..
-rw-r--r--  1 fabien fabien 1642429 2006-12-08 16:05 img_3402.jpg
-rw-r--r--  1 fabien fabien 1506637 2006-12-07 19:39 img_3403.jpg

When a change the comment, this is what I have :
digikam: Cannot save metadata using Exiv2 (/localhome/fabien/Pictures/test04/img_3402.jpg: Failed to open file (w+b): Permission denied (13))

Why Exiv2 returns an error although file is read/write ?
Because it first writes a temporary file (if size > 1MB), then remove the old one and rename the created file to the original name.

Why trying to save metadata (digikam is configured to not save metadata to image file) ?
Well, I guess that's the bug :)

This behavior applies to album gui and image editor.
Comment 1 caulier.gilles 2006-12-12 15:14:38 UTC
>Why trying to save metadata (digikam is configured to not save metadata to image file) ? 
> Well, I guess that's the bug :) 

Because digiKam check only the right permission of file, not album...

Gilles
Comment 2 caulier.gilles 2006-12-12 15:22:22 UTC
SVN commit 612751 by cgilles:

digikam from trunk : if file dir-path is read-only, do not try to save metadata on pictures.
BUG: 138540

 M  +11 -4     dmetadata.cpp  


--- trunk/extragear/graphics/digikam/libs/dmetadata/dmetadata.cpp #612750:612751
@@ -349,14 +349,21 @@
 
 bool DMetadata::save(const QString& filePath, DImg::FORMAT ff)
 {
-    // NOTE: see B.K.O #137770 : never touch the file if is read only.
-    QFileInfo info(filePath); 
-    if (!info.isWritable())
+    // NOTE: see B.K.O #137770 & #138540 : never touch the file if is read only.
+    QFileInfo finfo(filePath); 
+    QFileInfo dinfo(finfo.dirPath()); 
+    if (!finfo.isWritable())
     {
-        DDebug() << "File '" << info.fileName() << "' is read-only. Metadata not saved." << endl;
+        DDebug() << "File '" << finfo.fileName() << "' is read-only. Metadata not saved." << endl;
         return false;
     }
+    if (!dinfo.isWritable())
+    {
+        DDebug() << "Dir '" << finfo.filePath() << "' is read-only. Metadata not saved." << endl;
+        return false;
+    }
 
+
     switch (ff)
     {
         case(DImg::JPEG):
Comment 3 caulier.gilles 2006-12-12 15:39:03 UTC
SVN commit 612755 by cgilles:

kipi-plugins from trunk : if file dir-path is read-only, do not try to save metadata on pictures.
CCBUGS: 138540

 M  +10 -4     exiv2iface.cpp  


--- trunk/extragear/libs/kipi-plugins/common/exiv2iface/exiv2iface.cpp #612754:612755
@@ -282,13 +282,19 @@
     if (filePath.isEmpty())
         return false;
 
-    // NOTE: see B.K.O #137770 : never touch the file if is read only.
-    QFileInfo info(filePath); 
-    if (!info.isWritable())
+    // NOTE: see B.K.O #137770 & #138540 : never touch the file if is read only.
+    QFileInfo finfo(filePath); 
+    QFileInfo dinfo(finfo.dirPath()); 
+    if (!finfo.isWritable())
     {
-        kdDebug() << "File '" << info.fileName() << "' is read-only. Metadata not saved." << endl;
+        kdDebug() << "File '" << finfo.fileName() << "' is read-only. Metadata not saved." << endl;
         return false;
     }
+    if (!dinfo.isWritable())
+    {
+        kdDebug() << "Dir '" << dinfo.filePath() << "' is read-only. Metadata not saved." << endl;
+        return false;
+    }
 
     try
     {    
Comment 4 Fabien 2006-12-12 18:59:49 UTC
Thanks a lot Gilles ! Now, it's getting better :)

But, I'm going to ask you one more thing ;-)
Since the beginning, my concern is to avoid any action to a file if there's no reason to touch it.

Even with your latest modification, the file is still touched even if there's nothing to do on it.
If I'm not wrong (as I don't know C++), it looks like in file digikam/libs/imageproperties/imagedescedittab.cpp there's something that could be changed about :
ImageDescEditTab::applyAllChanges()

You check each setting before setting new metadata, but at the end, in all case, you do a "metadata.applyChanges();".
So, maybe it could be possible to check if there's at least one modification in the different metadatas and then avoid the applyChanges if there's nothing to apply.

I hope I'm not too wrong ;-)
Comment 5 caulier.gilles 2006-12-12 22:20:26 UTC
Fabien,

I just need some holidays (:=))). I have forget to commit another change in svn. Fixed now by commit #612869. Please checkout and confirm if all is ok now...

Gilles
Comment 6 Fabien 2006-12-13 15:04:49 UTC
One word: perfect !

It's fine now, thanks a lot Gilles !!
You really deserves come holidays ;-)

I close the bug.