diff --git a/thumbnail/thumbnail.cpp b/thumbnail/thumbnail.cpp --- a/thumbnail/thumbnail.cpp +++ b/thumbnail/thumbnail.cpp @@ -28,6 +28,7 @@ #ifndef Q_OS_WIN #include #include +#include #include // nice() #endif @@ -77,6 +78,7 @@ #endif #include "imagefilter.h" +#include // Recognized metadata entries: // mimeType - the mime type of the file, used for the overlay icon if any @@ -722,6 +724,21 @@ if (!thumbnail.load(thumbPath.absoluteFilePath(thumbName))) { // no cached version is available, a new thumbnail must be created + // If file is on the same filesystem as thumbnail directory, we can cache it. + bool allowCache = false; +#ifdef _SYS_STAT_H + struct stat baseStat, fileStat; + if (!lstat(m_thumbBasePath.toStdString().c_str(), &baseStat) && lstat(filePath.toStdString().c_str(), &fileStat)) { + allowCache = baseStat.st_dev == fileStat.st_dev; + } +#endif + if (!allowCache) { + // If file is on encrypted filesystem different than thumbnail directory, we can't cache it + const auto mountsList = KMountPoint::currentMountPoints(); + const auto mount = mountsList.findByPath(filePath); + allowCache = !(mount->mountType() == QLatin1String("fuse.cryfs") || mount->mountType() == QLatin1String("fuse.encfs")); + } + QSaveFile thumbnailfile(thumbPath.absoluteFilePath(thumbName)); bool savedCorrectly = false; if (subCreator->create(filePath, cacheSize, cacheSize, thumbnail)) { @@ -729,7 +746,7 @@ // The thumbnail has been created successfully. Store the thumbnail // to the cache for future access. - if (thumbnailfile.open(QIODevice::WriteOnly | QIODevice::Truncate)) { + if (allowCache && thumbnailfile.open(QIODevice::WriteOnly | QIODevice::Truncate)) { savedCorrectly = thumbnail.save(&thumbnailfile, "PNG"); } } else {