diff --git a/thumbnail/thumbnail.h b/thumbnail/thumbnail.h --- a/thumbnail/thumbnail.h +++ b/thumbnail/thumbnail.h @@ -69,6 +69,13 @@ **/ bool drawSubThumbnail(QPainter& p, const QString& filePath, int width, int height, int xPos, int yPos, int frameWidth); + + /** + * Checks if path is on the same filesystem as thumbnail cache directory. + * Returns true if so. False otherwise or if filesystem couldn't be checked. + */ + bool sharesFilesystemWithThumbRoot(const QString &path); + private: QString m_mimeType; int m_width; @@ -83,6 +90,8 @@ QSet m_propagationDirectories; QString m_thumbBasePath; qint64 m_maxFileSize; + dev_t m_thumbnailDirDeviceId = 0; + short allowDirCached; }; #endif 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 @@ -533,6 +535,8 @@ const int maxYPos = folderHeight - bottomMargin - segmentHeight; int validThumbnails = 0; + // we need to reset this check per directory + allowDirCached = -1; while ((skipped <= skipValidItems) && (yPos <= maxYPos) && validThumbnails == 0) { QDirIterator dir(localFile, QDir::Files | QDir::Readable); @@ -722,6 +726,25 @@ if (!thumbnail.load(thumbPath.absoluteFilePath(thumbName))) { // no cached version is available, a new thumbnail must be created + // If file is on encrypted filesystem, we can't cache it unless it's on the same filesystem as thumbnail directory + bool allowCache; + if (allowDirCached != -1) { + allowCache = allowDirCached; + } + else { +#ifdef _SYS_STAT_H + allowCache = sharesFilesystemWithThumbRoot(filePath); +#else + allowCache = false; +#endif + if (!allowCache) { + const auto mountsList = KMountPoint::currentMountPoints(); + const auto mount = mountsList.findByPath(filePath); + allowCache = !(mount->mountType() == QLatin1String("fuse.cryfs") || mount->mountType() == QLatin1String("fuse.encfs")); + } + allowDirCached = allowCache; + } + QSaveFile thumbnailfile(thumbPath.absoluteFilePath(thumbName)); bool savedCorrectly = false; if (subCreator->create(filePath, cacheSize, cacheSize, thumbnail)) { @@ -729,7 +752,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 { @@ -746,6 +769,18 @@ return true; } +bool ThumbnailProtocol::sharesFilesystemWithThumbRoot(const QString& path) +{ + if (!m_thumbnailDirDeviceId) { + struct stat baseStat; + if (!lstat(QFile::encodeName(m_thumbBasePath).data(), &baseStat)) { + m_thumbnailDirDeviceId = baseStat.st_dev; + } + } + struct stat fileStat; + return m_thumbnailDirDeviceId && !lstat(QFile::encodeName(path).data(), &fileStat) && m_thumbnailDirDeviceId == fileStat.st_dev; +} + void ThumbnailProtocol::scaleDownImage(QImage& img, int maxWidth, int maxHeight) { if (img.width() > maxWidth || img.height() > maxHeight) {