From c53802cc2600e3f92d36a00a2a77071634aa31d9 Mon Sep 17 00:00:00 2001 From: lizhuoan Date: Thu, 20 Apr 2023 16:31:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E6=93=8D=E4=BD=9C=E7=9A=84?= =?UTF-8?q?=E6=8C=82=E8=BD=BD=E8=B7=AF=E5=BE=84=E8=BF=9B=E8=A1=8C=E5=88=A4?= =?UTF-8?q?=E6=96=AD=EF=BC=8C=E7=84=B6=E5=90=8E=E8=BF=9B=E8=A1=8C=E9=A2=84?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../file-operation/file-copy-operation.cpp | 3 -- .../file-operation/file-move-operation.cpp | 3 -- .../file-operation/file-operation-manager.cpp | 53 ++++++++++++++++--- .../file-operation/file-operation-manager.h | 10 +++- libpeony-qt/file-utils.cpp | 5 +- libpeony-qt/file-utils.h | 2 +- 6 files changed, 57 insertions(+), 19 deletions(-) diff --git a/libpeony-qt/file-operation/file-copy-operation.cpp b/libpeony-qt/file-operation/file-copy-operation.cpp index d93699a9..47d32d9f 100644 --- a/libpeony-qt/file-operation/file-copy-operation.cpp +++ b/libpeony-qt/file-operation/file-copy-operation.cpp @@ -793,9 +793,6 @@ void FileCopyOperation::run() m_total_szie = *total_size; delete total_size; - auto destGfile = g_file_new_for_uri(m_dest_dir_uri.toUtf8().constData()); - auto destPath = g_file_get_path(destGfile); - Peony::FileUtils::getDiskFreeSpace(destPath); Q_EMIT operationTotalFileSize(m_total_szie); m_srcUrisOfCopyDspsFiles.clear(); diff --git a/libpeony-qt/file-operation/file-move-operation.cpp b/libpeony-qt/file-operation/file-move-operation.cpp index 4d0940ab..15c1d5c8 100644 --- a/libpeony-qt/file-operation/file-move-operation.cpp +++ b/libpeony-qt/file-operation/file-move-operation.cpp @@ -231,9 +231,6 @@ void FileMoveOperation::move() operationPreparedOne("", m_total_szie); delete total_size; - auto destGfile = g_file_new_for_uri(m_dest_dir_uri.toUtf8().constData()); - auto destPath = g_file_get_path(destGfile); - Peony::FileUtils::getDiskFreeSpace(destPath); Q_EMIT operationTotalFileSize(m_total_szie); operationPrepared(); diff --git a/libpeony-qt/file-operation/file-operation-manager.cpp b/libpeony-qt/file-operation/file-operation-manager.cpp index dd740a25..48e7958b 100644 --- a/libpeony-qt/file-operation/file-operation-manager.cpp +++ b/libpeony-qt/file-operation/file-operation-manager.cpp @@ -65,8 +65,8 @@ FileOperationManager::FileOperationManager(QObject *parent) : QObject(parent) qRegisterMetaType("Peony::GErrorWrapperPtr&"); m_thread_pool = new QThreadPool(this); m_progressbar = FileOperationProgressBar::getInstance(); - m_operation_use_list = new QMap; - m_current_total_file_size = 0; + m_mount_operation_list = new QHash; + m_operation_use_list = new QHash; if (!m_allow_parallel) { //Imitating queue execution. m_thread_pool->setMaxThreadCount(1); @@ -311,26 +311,54 @@ start: connect(operation, &FileOperation::operationTotalFileSize, this, [=](const qint64& total_file_size) { + //story 19796 空间不足时预处理 auto info = operation->getOperationInfo(); if (!info || info->operationType() != FileOperationInfo::Copy && info->operationType() != FileOperationInfo::Move) { return; } if (m_operation_use_list->contains(operation)) { + qWarning() << "this operation already exist"; return; } - m_current_total_file_size += total_file_size; auto destGfile = g_file_new_for_uri(info->target().toUtf8().constData()); auto destPath = g_file_get_path(destGfile); - if(m_current_total_file_size > Peony::FileUtils::getDiskFreeSpace(destPath)) { + bool isState = true; +// 调用底层接口获取剩余空间 +// auto diskFreeSpace = Peony::FileUtils::getDiskFreeSpace(destPath, isState); +// if (!isState) { +// return; +// } +// 使用QStorageInfo的接口进行处理 + QStorageInfo storage(destPath); + if (!storage.isValid()) { + qWarning() << "The file path is not mounted correctly"; + return; + } + quint64 diskFreeSpace = storage.bytesAvailable(); + QString mountName = storage.rootPath(); + + qint64 currentTotalSize = 0; + if (m_mount_operation_list->contains(mountName)) { + qint64 currentUseSize = m_mount_operation_list->value(mountName); + currentTotalSize = currentUseSize + total_file_size; + } else { + currentTotalSize = total_file_size; + } + if(currentTotalSize > diskFreeSpace) { QMessageBox::critical(nullptr, tr("Insufficient storage space"), - tr("there is not enough space left")); - m_current_total_file_size -= total_file_size; + tr("no space left on device")); operation->cancel(); return; } - m_operation_use_list->insert(operation, total_file_size); + +// 记录处理数值 + currentOpertionInfo opertionInfo; + opertionInfo.mountRootName = mountName; + opertionInfo.total_size = total_file_size; + m_mount_operation_list->insert(mountName, currentTotalSize); + m_operation_use_list->insert(operation, opertionInfo); }, Qt::BlockingQueuedConnection); auto opType = operationInfo->operationType(); @@ -395,7 +423,16 @@ start: operation->connect(operation, &FileOperation::errored, this, &FileOperationManager::handleError, Qt::BlockingQueuedConnection); operation->connect(operation, &FileOperation::operationFinished, this, [=](){ if (m_operation_use_list->contains(operation)) { - m_current_total_file_size -= m_operation_use_list->value(operation); +// story 19796,需求后续数据处理 + currentOpertionInfo operationInfo = m_operation_use_list->value(operation); + QString name = operationInfo.mountRootName; + quint64 size = operationInfo.total_size; + size = m_mount_operation_list->value(name) - size; + if (size == 0){ + m_mount_operation_list->remove(name); + } else { + m_mount_operation_list->insert(name, size); + } m_operation_use_list->remove(operation); } Q_EMIT this->operationFinished(operation->getOperationInfo(), !operation->hasError()); diff --git a/libpeony-qt/file-operation/file-operation-manager.h b/libpeony-qt/file-operation/file-operation-manager.h index 3ba60824..75426ecb 100644 --- a/libpeony-qt/file-operation/file-operation-manager.h +++ b/libpeony-qt/file-operation/file-operation-manager.h @@ -138,6 +138,12 @@ private: static void systemSleep (GDBusConnection* connection, const gchar* senderName, const gchar* objectPath, const gchar* interfaceName, const gchar* signalName, GVariant* parameters, gpointer udata); private: + struct currentOpertionInfo + { + QString mountRootName; + quint64 total_size; + }; + QThreadPool *m_thread_pool; bool m_allow_parallel = false; QVector m_watchers; @@ -145,8 +151,8 @@ private: FileOperationProgressBar *m_progressbar = nullptr; QStack> m_undo_stack; QStack> m_redo_stack; - qint64 m_current_total_file_size = 0; - QMap *m_operation_use_list = nullptr; + QHash *m_mount_operation_list = nullptr; + QHash *m_operation_use_list = nullptr; }; class FileOperationInfo : public QObject diff --git a/libpeony-qt/file-utils.cpp b/libpeony-qt/file-utils.cpp index 9aa575e3..083bfe70 100644 --- a/libpeony-qt/file-utils.cpp +++ b/libpeony-qt/file-utils.cpp @@ -1039,13 +1039,14 @@ double FileUtils::getDeviceSize(const gchar * device_name) return volume_size; } -quint64 FileUtils::getDiskFreeSpace(const gchar * path) +quint64 FileUtils::getDiskFreeSpace(const gchar * path, bool &isState) { struct statvfs vfs; quint64 freeSize = 0; auto state = statvfs(path, &vfs); if(0 > state) { - qDebug() << "read statvfs error"; + isState = false; + qWarning() << "read statvfs error"; } else { freeSize = vfs.f_bavail * vfs.f_bsize; } diff --git a/libpeony-qt/file-utils.h b/libpeony-qt/file-utils.h index 27101f25..c4f4d347 100644 --- a/libpeony-qt/file-utils.h +++ b/libpeony-qt/file-utils.h @@ -110,7 +110,7 @@ public: static bool isRemoteServerUri(const QString &uri); static bool isEmptyDisc(const QString &unixDevice);/* 判断是否是空光盘 */ static bool isBusyDevice(const QString &unixDevice);/* 判断光盘是否正在使用 */ - static quint64 getDiskFreeSpace(const gchar *path); + static quint64 getDiskFreeSpace(const gchar *path, bool &isState); /* 获取磁盘剩余空间*/ NO_BLOCKING static QString getIconStringFromGIcon(GIcon *gicon, QString deviceFile = nullptr); static void saveCreateTime (const QString& url);