#include "mbtasklog.h"
|
#include <QMutex>
|
#include <QDir>
|
#include "mbfileutil.h"
|
|
|
CMBTaskLog::CMBTaskLog()
|
{
|
m_pMdWare = NULL;
|
m_pWatchDb = new CMBWatchDb();
|
}
|
|
CMBTaskLog::~CMBTaskLog()
|
{
|
if( m_pWatchDb ){
|
delete m_pWatchDb;
|
m_pWatchDb = NULL;
|
}
|
}
|
|
void CMBTaskLog::set(QString logDbPath, QString backupDir, QString svrPath)
|
{
|
m_logDbPath = logDbPath;
|
m_backupDir = backupDir;
|
m_svrPath = svrPath;
|
}
|
|
void CMBTaskLog::setMdWare(CMBMdware *pMdWare)
|
{
|
m_pMdWare = pMdWare;
|
}
|
|
// 查找文件
|
bool CMBTaskLog::findFile(const QString &path,QString &errInfo)
|
{
|
int i = 0;
|
bool bIsDir = false;
|
|
QDir dir(path);
|
|
if(!dir.exists())
|
{
|
return false;
|
}
|
|
dir.setFilter(QDir::Dirs | QDir::Files);
|
dir.setSorting(QDir::DirsFirst);//文件夹排在前面
|
QFileInfoList list = dir.entryInfoList();
|
|
do
|
{
|
QFileInfo fileInfo = list.at(i);
|
if(fileInfo.fileName() == "." | fileInfo.fileName() == "..")
|
{
|
++i;
|
continue;
|
}
|
bIsDir = fileInfo.isDir();
|
if(bIsDir)
|
{
|
if(!findFile(fileInfo.filePath(),errInfo))
|
return false;
|
}
|
else
|
{
|
QString fileName = fileInfo.absoluteFilePath();
|
QString svrPath = CMBFileUtil::genSvrPath(m_backupDir,fileName, m_svrPath);
|
QString lastMdfTime = CMBFileUtil::lastModifiedTime(fileName);
|
m_pWatchDb->insertBackupDirDB(fileName,"",svrPath,lastMdfTime);
|
}
|
++i;
|
}while(i < list.size());
|
|
|
return true;
|
}
|
|
void CMBTaskLog::run()
|
{
|
QString errInfo;
|
if(!m_pWatchDb->init(m_logDbPath,errInfo)){
|
emit m_pMdWare->sigErrInfo(errInfo);
|
return ;
|
}
|
// 遍历文件夹 备份文件夹
|
if(!findFile(m_backupDir,errInfo)){
|
emit m_pMdWare->sigErrInfo(errInfo);
|
return ;
|
}
|
|
}
|