Bug 376815

Summary: Restore from Trash works incorrectly
Product: [Applications] digikam Reporter: Andrius <aegoreev>
Component: Database-TrashAssignee: Digikam Developers <digikam-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: caulier.gilles, johannes.hirte, mario.frank, metzpinguin
Priority: NOR    
Version: 5.5.0   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In: 5.5.0
Sentry Crash Report:

Description Andrius 2017-02-22 18:05:07 UTC
If I delete a pair of files e.g.

20170201_181823_414.JPG
20170201_181823_414.DNG

and the restore them from Trash
digiKam renames them to:

20170201_181823_414.DNG
20170201_181823_4141.DNG

which causes crashes after:

digikam.rawengine: LibRaw: failed to run open_file:  Unsupported file format or not RAW file
digikam.rawengine: Failed to load embedded RAW preview
digikam.rawengine: Try to use reduced RAW picture extraction
digikam.rawengine: LibRaw: failed to run open_file:  Unsupported file format or not RAW file
digikam.general: Cannot extract preview for  "/media/data/Pictures/2017/February/20170201/20170201_181823_414.DNG"
digikam.metaengine: Orientation => Exif.Image.Orientation =>  1
ASSERT: "!qFuzzyIsNull(c)" in file /usr/include/x86_64-linux-gnu/qt5/QtCore/qsize.h, line 347
Aborted

Tested on both digikam 5.4.0 installed and 5.5.0 latest appimage
Comment 1 Andrius 2017-02-22 18:42:11 UTC
Sometimes it renames the files the other way around.

20170201_183418_460.JPG
20170201_183418_4601.JPG

instead of 

20170201_183418_460.JPG
20170201_183418_460.DNG
Comment 2 Maik Qualmann 2017-02-22 22:11:23 UTC
Git commit f528f24b54894b271a4bee44a850b1ac46c10cc9 by Maik Qualmann.
Committed on 22/02/2017 at 22:10.
Pushed by mqualmann into branch 'master'.

add random string to the trash filename to prevent another thread use the filename already
FIXED-IN: 5.5.0

M  +2    -1    NEWS
M  +10   -0    libs/dtrash/dtrash.cpp

https://commits.kde.org/digikam/f528f24b54894b271a4bee44a850b1ac46c10cc9
Comment 3 Maik Qualmann 2017-02-23 18:51:28 UTC
Git commit 38e1582672ddd32bef4f0dbc3750654fdd128b07 by Maik Qualmann.
Committed on 23/02/2017 at 18:50.
Pushed by mqualmann into branch 'master'.

use QUuid to generate random string for filename

M  +4    -8    libs/dtrash/dtrash.cpp

https://commits.kde.org/digikam/38e1582672ddd32bef4f0dbc3750654fdd128b07
Comment 4 Johannes Hirte 2017-02-24 14:44:49 UTC
This leads now to the following compile error:

/var/tmp/portage/media-gfx/digikam-9999/work/digikam-9999/libs/dtrash/dtrash.cpp: In static member function ‘static QString Digikam::DTrash::getAvialableJsonFilePathInTrash(const QString&, const QString&, int)’:
/var/tmp/portage/media-gfx/digikam-9999/work/digikam-9999/libs/dtrash/dtrash.cpp:222:41: error: ‘QChar::QChar(char)’ is private within this context
     randomString.replace(0, 1, QChar('-'));
                                         ^
In file included from /usr/include/qt5/QtCore/qstring.h:48:0,
                 from /usr/include/qt5/QtCore/qobject.h:47,
                 from /usr/include/qt5/QtCore/QObject:1,
                 from /var/tmp/portage/media-gfx/digikam-9999/work/digikam-9999/libs/dtrash/dtrash.h:29,
                 from /var/tmp/portage/media-gfx/digikam-9999/work/digikam-9999/libs/dtrash/dtrash.cpp:24:
/usr/include/qt5/QtCore/qchar.h:562:5: note: declared private here
     QChar(char c) Q_DECL_NOTHROW;
     ^~~~~
make[2]: *** [libs/dtrash/CMakeFiles/dtrash_src.dir/build.make:63: libs/dtrash/CMakeFiles/dtrash_src.dir/dtrash.cpp.o] Error 1


possible fix

diff --git a/libs/dtrash/dtrash.cpp b/libs/dtrash/dtrash.cpp
index 7b65f3844d..4eed798c3e 100644
--- a/libs/dtrash/dtrash.cpp
+++ b/libs/dtrash/dtrash.cpp
@@ -219,7 +219,7 @@ QString DTrash::createJsonRecordForFile(const QString& collectionPath, const QSt
 QString DTrash::getAvialableJsonFilePathInTrash(const QString& collectionPath, const QString& baseName, int version)
 {
     QString randomString = QUuid::createUuid().toString();
-    randomString.replace(0, 1, QChar('-'));
+    randomString.replace(0, 1, QChar(0x2D));
     randomString.chop(1);

     QString pathToCreateJsonFile = collectionPath + QLatin1Char('/') +


QChar::fromLatin1() should work too
Comment 5 Maik Qualmann 2017-02-24 17:35:38 UTC
Git commit 2d6880ab9cc7d9d714a767ff4be090fbb8092e7d by Maik Qualmann.
Committed on 24/02/2017 at 17:34.
Pushed by mqualmann into branch 'master'.

fix compile QChar()->QLatin1Char()

M  +1    -1    libs/dtrash/dtrash.cpp

https://commits.kde.org/digikam/2d6880ab9cc7d9d714a767ff4be090fbb8092e7d
Comment 6 Andrius 2017-07-24 17:34:20 UTC
This fug is fixed