mirror of https://gitee.com/openkylin/peony.git
根据操作的挂载路径进行判断,然后进行预处理
This commit is contained in:
parent
058d8f7c0f
commit
c53802cc26
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -65,8 +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;
|
||||
m_mount_operation_list = new QHash<QString, qint64>;
|
||||
m_operation_use_list = new QHash<FileOperation*, currentOpertionInfo>;
|
||||
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());
|
||||
|
|
|
@ -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<FileWatcher *> m_watchers;
|
||||
|
@ -145,8 +151,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;
|
||||
QHash<QString, qint64> *m_mount_operation_list = nullptr;
|
||||
QHash<FileOperation*, currentOpertionInfo> *m_operation_use_list = nullptr;
|
||||
};
|
||||
|
||||
class FileOperationInfo : public QObject
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue