[Digikam-devel] [Bug 163602] New: Race condition during image download from Camera/ USB device: image corruption and/or loss (patch attached)

Chris Drexler kde at ac-drexler.de
Mon Jun 9 12:36:27 BST 2008


------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
         
http://bugs.kde.org/show_bug.cgi?id=163602         
           Summary: Race condition during image download from Camera/ USB
                    device: image corruption and/or loss (patch attached)
           Product: digikam
           Version: unspecified
          Platform: SuSE RPMs
        OS/Version: Linux
            Status: UNCONFIRMED
          Severity: normal
          Priority: NOR
         Component: Camera GUI
        AssignedTo: digikam-devel kde org
        ReportedBy: kde ac-drexler de


Version:           0.9.3, but still in latest SVN (using KDE 3.5.9)
Installed from:    SuSE RPMs
Compiler:          gcc version 4.2.1 (SUSE Linux)
 
OS:                Linux

CameraGUI does a download of images by copying it to local file within the destination directory and manipulating this one before renaming it to the final name. 
A race condition exists because the download and the renaming is done asynchronously and the same temp filename is used for all downloaded images (".digikam-camera-tmp1-%1" whereas %1 is replaced by the PID).

What happens is that in the best case, the renaming is happening while the next download is running, therefore an error happens (access denied) and the rename fails. This is shown by a "X" in the thumbnail view of the CameraGui. At least the problem is visible.

In the not-so-good case it can happen, that one ends up with two times the same image on the local disk, because somehow (why exactly is not clear to me) the second downloaded image is renamed twice (I didn't go into details of how this can happen). This is worse than case one, because in the thumbnail view the images show up as correctly downloaded, but on disk you find duplicates of certain images while others are missing.

The solution for me was to generate temporary filenames that depend on the filename that is actually downloaded. As you can see in the provided patch, the changes are minimal and very local. Only cameracontroller.cpp needs to be changed!

BTW: This problem showed up when I upgraded a $1.99 USB 1.1 card reader to a faster 2.0 version after using digiKam already for many years!

Please feel free to contact me with any questions that you might have regarding this!

digiKam is a really cool piece of software and I'm happy to be able to contribute to making it even better!



More information about the Digikam-devel mailing list