Bug 178103

Summary: Digikam error: Failed to revise Exif orientation
Product: [Applications] digikam Reporter: Michael <m.mickey>
Component: Metadata-OrientationAssignee: Digikam Developers <digikam-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: ahuggel, caulier.gilles, marcel.wiesweg
Priority: NOR    
Version: 0.10.0   
Target Milestone: ---   
Platform: Ubuntu   
OS: Linux   
Latest Commit: Version Fixed In: 0.10.0
Sentry Crash Report:

Description Michael 2008-12-18 22:09:15 UTC
Version:           0.10 latest svn (using KDE 4.1.3)
OS:                Linux
Installed from:    Ubuntu Packages

Hi, 
I used the svn version of exiv2 and today I updated to exiv2 0.18, in both cases I get the Error dialog "Failed to revise Exif orientation" then changing the orientation of PEF-files of my Pentax K100D, but the orientation is changed correctly, so just the dialog should not appear...
greets, mike
Comment 1 Marcel Wiesweg 2008-12-19 09:55:21 UTC
Are there any error messages prined on the console when you change orientation? DMetadata::apply sees a reason to signal failure here.
Comment 2 Michael 2008-12-19 11:30:59 UTC
here is the output:

digikam(6733) KDcrawIface::KDcraw::loadEmbeddedPreview: Preview data size: 2281421
digikam(6733) KDcrawIface::KDcraw::loadEmbeddedPreview: Using embedded RAW preview extraction
digikam(6733) KExiv2Iface::KExiv2::getImageOrientation: Orientation => Exif.Image.Orientation =>  1
digikam(6733) Digikam::AlbumIconView::slotSetExifOrientation: Setting Exif Orientation tag to  8
digikam(6733) KExiv2Iface::KExiv2::setImageOrientation: Exif.Image.Orientation tag set to:  8
digikam(6733) KExiv2Iface::KExiv2Priv::printExiv2ExceptionError: Cannot save metadata using Exiv2   (Error # 2 :  /media/E/DCIM/143/IMGP1623.PEF6733:  (1) (chmod)
digikam(6733) Digikam::AlbumManager::slotDirty: AlbumManager::slotDirty "/media/E/DCIM/143"
digikam(6733) Digikam::DImg::load: "/media/E/DCIM/143/IMGP1623.PEF"  : RAW file identified
digikam(6733) Digikam::ScanControllerLoadingCacheFileWatch::slotImageChanged: 4220 "/media/E/DCIM/143/IMGP1623.PEF"
digikam(6733) KDcrawIface::KDcraw::loadEmbeddedPreview: Preview data size: 1630793
digikam(6733) KDcrawIface::KDcraw::loadEmbeddedPreview: Preview data size: 1630793
digikam(6733) KDcrawIface::KDcraw::loadEmbeddedPreview: Using embedded RAW preview extraction
digikam(6733) KDcrawIface::KDcraw::loadEmbeddedPreview: Using embedded RAW preview extraction
digikam(6733) KExiv2Iface::KExiv2::getImageOrientation: Orientation => Exif.Image.Orientation =>  8
digikam(6733) KExiv2Iface::KExiv2::getImageOrientation: Orientation => Exif.Image.Orientation =>  8
digikam(6733) Digikam::AlbumManager::slotDirty: AlbumManager::slotDirty "/media/E/DCIM"
digikam(6733) KDcrawIface::KDcraw::loadEmbeddedPreview: Preview data size: 1630793
digikam(6733) KDcrawIface::KDcraw::loadEmbeddedPreview: Preview data size: 1630793
digikam(6733) KDcrawIface::KDcraw::loadEmbeddedPreview: Using embedded RAW preview extraction
digikam(6733) KDcrawIface::KDcraw::loadEmbeddedPreview: Using embedded RAW preview extraction
digikam(6733) Digikam::AlbumManager::slotDirty: AlbumManager::slotDirty "/media/E/DCIM"
digikam(6733) KExiv2Iface::KExiv2::getImageOrientation: Orientation => Exif.Image.Orientation =>  8
digikam(6733) Digikam::AlbumManager::slotDirty: Filtering out db-file-triggered dir watch signal
digikam(6733) KExiv2Iface::KExiv2::getImageOrientation: Orientation => Exif.Image.Orientation =>  8

greets mike
Comment 3 Marcel Wiesweg 2008-12-20 20:58:13 UTC
Gilles, do you know why this exception from exiv2 is thrown:

digikam(6733) KExiv2Iface::KExiv2Priv::printExiv2ExceptionError: 
Cannot save metadata using Exiv2   
(Error # 2 :  /media/E/DCIM/143/IMGP1623.PEF6733:  (1) (chmod)
Comment 4 caulier.gilles 2008-12-20 21:03:11 UTC
No, but Andreas certainly...

Gilles
Comment 5 Andreas Huggel 2008-12-21 03:17:43 UTC
I don't think that message is from Exiv2...

-ahu.
Comment 6 caulier.gilles 2008-12-21 08:28:19 UTC
Andreas,

digikam(6733) KExiv2Iface::KExiv2Priv::printExiv2ExceptionError: << libkexiv2
Cannot save metadata using Exiv2                                 << libkexiv2
(Error # 2 :  /media/E/DCIM/143/IMGP1623.PEF6733:  (1) (chmod)   << Exiv2

Dixit these lines from source code :

http://lxr.kde.org/source/KDE/kdegraphics/libs/libkexiv2/libkexiv2/kexiv2.cpp#428
http://lxr.kde.org/source/KDE/kdegraphics/libs/libkexiv2/libkexiv2/kexiv2private.cpp#044

Gilles
Comment 7 Andreas Huggel 2008-12-21 13:54:07 UTC
Oh, ok, now I get it.

The error message means that the system call to chmod() failed (with rc == -1) for the given file and errno is 1. The error message actually also includes a textual description of the system error before '(1)', but that is empty here.

This happens in FileIo::transfer, presumably called from TiffImage::writeMetadata in this case (based on the file name).

When the file is written, it is saved to a temporary file first. Then the temporary file is renamed to the original filename and the original permissions are applied to the new file. The actual implementation is a bit more complicated: http://dev.exiv2.org/repositories/entry/exiv2/trunk/src/basicio.cpp#L217

What are the permissions of the original file and that of the directory? What filesystem is this on?

Andreas
Comment 8 Michael 2008-12-21 17:19:07 UTC
Since I needed the compatibility to windows, the files are on a ntfs volume, belong to root and the group plugdev has read and write rights, everything with ubuntu 8.10, the partition is mounted with "ntfs defaults,umask=007,gid=46 0 1"

greets, mike
Comment 9 Andreas Huggel 2008-12-22 02:32:40 UTC
Mike,

What happens if you do this from the command line as the user which you use to run digiKam:
+ create a new file in the same directory as the image files (eg, "touch ttt")
+ change the permissions of that file to those of the images (chmod)
+ echo $?

Does the chmod succeed? 

-ahu.
Comment 10 Michael 2008-12-28 23:51:44 UTC
hi andreas, 
I hope I did it right, but it didn't succeed. I got "chmod: Beim Setzen der Zugriffsrechte für „ttt“: Operation not permitted" and "1".
greets, mike
Comment 11 Andreas Huggel 2008-12-29 00:39:50 UTC
Mike,
Good. That reproduces the error that you get in digiKam. But do you understand why you can't change the permissions? What are the permissions of the images, the ttt file and the directory? 

cd /the/directory
ls -lad .
ls -la ttt 
ls -la <image>

(I could simply remove the check for success of chmod in Exiv2, since it is the last operation. But I'd like to understand what's the root cause of the problem before modifying anything.)

Andreas
Comment 12 Marcel Wiesweg 2008-12-29 13:01:30 UTC
If you google for it you will find at least some forum posts stating that chmod is not / not fully supported / read only for NTFS.
Comment 13 Michael 2008-12-30 00:49:33 UTC
hi, here is the output. I hope it helps. I can read and write on that NTFS volume.

drwxrwx--- 1 root plugdev 16384 2008-12-01 20:14 .
-rwxrwx--- 1 root plugdev 0 2008-12-30 00:39 ttt
-rwxrwx--- 1 root plugdev 10446538 2007-06-09 18:47 IMGP1441.PEF

greets, mike

Comment 14 Marcel Wiesweg 2008-12-30 11:45:59 UTC
I can fully reproduce this here: chmod'ing a file on an NTFS partition (mounted with ntfs-3g) as non-superuser fails with errno=1, regardless of seemingly sufficient privileges in the directory. Doing the same as superuser does not give an error, but gives no effect either, i.e. permissions are unchanged.
   whoami
marcel
   groups
users dialout video
   dir -d /windows/Users/marcel/Pictures/
drwxrwxr-x 1 root users 0 24. Dez 23:03 /windows/Users/marcel/Pictures/
   dir /windows/Users/marcel/Pictures/
insgesamt 5
-rw-rw-r-- 1 root users 674 24. Dez 23:03 desktop.ini
-rw-rw-r-- 2 root users 669 24. Dez 23:03 Sample Pictures.lnk
   LANG=C chmod a-w /windows/Users/marcel/Pictures/Sample\ Pictures.lnk
chmod: changing permissions of `/windows/Users/marcel/Pictures/Sample Pictures.lnk': Operation not permitted


Comment 15 Andreas Huggel 2008-12-30 17:06:41 UTC
http://dev.exiv2.org/repositories/diff/exiv2?rev=1719

+ do not chmod if the permissions of the new file are the same as those of the old file
+ do not throw if stat or chmod fails here, just issue a warning
+ use correct version of strerror_r when compiling with g++

Marcel, Mike,
Can you please try if this fixes the problem for you?

Marcel,
I would appreciate if you had a look at the code changes too - as a sanity check. Thanks!

Andreas
Comment 16 Marcel Wiesweg 2008-12-30 17:19:16 UTC
Your changes look all right to me.
Comment 17 caulier.gilles 2009-01-01 17:05:29 UTC
For me code sound fine now (patch not tested with NTFS).

Michael, 

can you test using last Exiv2 code from svn, and recompile libkexiv2 from trunk using it and test again with digiKam. 

thanks in advance.

Gilles Caulier
Comment 18 Michael 2009-01-02 01:33:38 UTC
works fine for me...
thank you all and happy new year ;-)

greets, mike