Skip to content

Commit

Permalink
fix: [thumbnail] The thumbnails save failed
Browse files Browse the repository at this point in the history
The directory for saving the thumbnail does not exist, causing the saving to fail

Log: fix bug
Bug: https://pms.uniontech.com/bug-view-211721.html
  • Loading branch information
Kakueeen authored and deepin-bot[bot] committed Jul 27, 2023
1 parent f52284e commit f10fcaf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions src/dfm-base/utils/thumbnail/thumbnailhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <dfm-io/dfmio_utils.h>

#include <QImageReader>
#include <QDir>

#include <sys/stat.h>

Expand Down Expand Up @@ -114,11 +115,11 @@ bool ThumbnailHelper::checkMimeTypeSupport(const QMimeType &mime)
return false;
}

void ThumbnailHelper::makeDir(const QString &path)
void ThumbnailHelper::makePath(const QString &path)
{
struct stat info;
if (stat(path.toLocal8Bit().data(), &info) != 0)
mkdir(path.toLocal8Bit().data(), 0755);
QDir dir(path);
if (!dir.exists())
dir.mkpath(".");
}

QString ThumbnailHelper::saveThumbnail(const QUrl &url, const QImage &img, ThumbnailSize size)
Expand All @@ -140,7 +141,7 @@ QString ThumbnailHelper::saveThumbnail(const QUrl &url, const QImage &img, Thumb
const qint64 fileModify = info->timeOf(TimeInfoType::kLastModifiedSecond).toLongLong();
tmpImg.setText(QT_STRINGIFY(Thumb::MTime), QString::number(fileModify));

makeDir(thumbnailPath);
makePath(thumbnailPath);
if (!tmpImg.save(thumbnailFilePath, Q_NULLPTR, 50)) {
qWarning() << "thumbnail: save failed." << fileUrl;
return "";
Expand Down
2 changes: 1 addition & 1 deletion src/dfm-base/utils/thumbnail/thumbnailhelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ThumbnailHelper
private:
explicit ThumbnailHelper();
bool checkMimeTypeSupport(const QMimeType &mime);
void makeDir(const QString &path);
void makePath(const QString &path);

private:
DMimeDatabase mimeDatabase;
Expand Down

0 comments on commit f10fcaf

Please sign in to comment.