mirror of https://gitee.com/openkylin/peony.git
story 19796,空间不足时拷贝大文件提前报错
This commit is contained in:
parent
a62c59d99b
commit
058d8f7c0f
|
@ -793,6 +793,11 @@ 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();
|
||||
m_destUrisOfCopyDspsFiles.clear();
|
||||
|
||||
|
|
|
@ -231,6 +231,11 @@ 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();
|
||||
|
||||
if (!errNode.isEmpty()) {
|
||||
|
|
|
@ -65,7 +65,8 @@ FileOperationManager::FileOperationManager(QObject *parent) : QObject(parent)
|
|||
qRegisterMetaType<Peony::GErrorWrapperPtr>("Peony::GErrorWrapperPtr&");
|
||||
m_thread_pool = new QThreadPool(this);
|
||||
m_progressbar = FileOperationProgressBar::getInstance();
|
||||
|
||||
m_operation_use_list = new QMap<FileOperation*, qint64>;
|
||||
m_current_total_file_size = 0;
|
||||
if (!m_allow_parallel) {
|
||||
//Imitating queue execution.
|
||||
m_thread_pool->setMaxThreadCount(1);
|
||||
|
@ -308,6 +309,30 @@ start:
|
|||
|
||||
bool allowParallel = m_allow_parallel;
|
||||
|
||||
|
||||
connect(operation, &FileOperation::operationTotalFileSize, this, [=](const qint64& total_file_size) {
|
||||
auto info = operation->getOperationInfo();
|
||||
if (!info || info->operationType() != FileOperationInfo::Copy
|
||||
&& info->operationType() != FileOperationInfo::Move) {
|
||||
return;
|
||||
}
|
||||
if (m_operation_use_list->contains(operation)) {
|
||||
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)) {
|
||||
QMessageBox::critical(nullptr,
|
||||
tr("Insufficient storage space"),
|
||||
tr("there is not enough space left"));
|
||||
m_current_total_file_size -= total_file_size;
|
||||
operation->cancel();
|
||||
return;
|
||||
}
|
||||
m_operation_use_list->insert(operation, total_file_size);
|
||||
}, Qt::BlockingQueuedConnection);
|
||||
|
||||
auto opType = operationInfo->operationType();
|
||||
switch (opType) {
|
||||
case FileOperationInfo::Trash:
|
||||
|
@ -369,6 +394,10 @@ 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);
|
||||
m_operation_use_list->remove(operation);
|
||||
}
|
||||
Q_EMIT this->operationFinished(operation->getOperationInfo(), !operation->hasError());
|
||||
if (operation->hasError()) {
|
||||
this->clearHistory();
|
||||
|
|
|
@ -145,6 +145,8 @@ private:
|
|||
FileOperationProgressBar *m_progressbar = nullptr;
|
||||
QStack<std::shared_ptr<FileOperationInfo>> m_undo_stack;
|
||||
QStack<std::shared_ptr<FileOperationInfo>> m_redo_stack;
|
||||
qint64 m_current_total_file_size = 0;
|
||||
QMap<FileOperation*, qint64> *m_operation_use_list = nullptr;
|
||||
};
|
||||
|
||||
class FileOperationInfo : public QObject
|
||||
|
|
|
@ -336,6 +336,8 @@ Q_SIGNALS:
|
|||
*/
|
||||
void operationCancel();
|
||||
|
||||
void operationTotalFileSize(const qint64& total_file_size);
|
||||
|
||||
public Q_SLOTS:
|
||||
virtual void cancel();
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include <QDir>
|
||||
#include <QIcon>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/statvfs.h>
|
||||
#include <udisks/udisks.h>
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusInterface>
|
||||
|
@ -1004,7 +1005,6 @@ double FileUtils::getDeviceSize(const gchar * device_name)
|
|||
UDisksObject *object, *crypto_backing_object;
|
||||
UDisksBlock *block;
|
||||
UDisksClient *client =udisks_client_new_sync (NULL,NULL);
|
||||
|
||||
object = NULL;
|
||||
if (stat (device_name, &statbuf) != 0)
|
||||
{
|
||||
|
@ -1039,6 +1039,19 @@ double FileUtils::getDeviceSize(const gchar * device_name)
|
|||
return volume_size;
|
||||
}
|
||||
|
||||
quint64 FileUtils::getDiskFreeSpace(const gchar * path)
|
||||
{
|
||||
struct statvfs vfs;
|
||||
quint64 freeSize = 0;
|
||||
auto state = statvfs(path, &vfs);
|
||||
if(0 > state) {
|
||||
qDebug() << "read statvfs error";
|
||||
} else {
|
||||
freeSize = vfs.f_bavail * vfs.f_bsize;
|
||||
}
|
||||
return freeSize;
|
||||
}
|
||||
|
||||
quint64 FileUtils::getFileSystemSize(QString uri)
|
||||
{
|
||||
QString unixDevice,dbusPath;
|
||||
|
|
|
@ -110,6 +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);
|
||||
|
||||
NO_BLOCKING static QString getIconStringFromGIcon(GIcon *gicon, QString deviceFile = nullptr);
|
||||
static void saveCreateTime (const QString& url);
|
||||
|
|
Loading…
Reference in New Issue