]> gitweb.hamatoma.de Git - reqt/commitdiff
dayly work
authorhama <hama@siduction.net>
Mon, 8 Feb 2016 23:22:25 +0000 (00:22 +0100)
committerhama <hama@siduction.net>
Mon, 8 Feb 2016 23:22:25 +0000 (00:22 +0100)
appl/rebackgui/BackupEngine.cpp
appl/rebackgui/mainwindow.cpp

index dbab03f611314644b9574408420f10d2138cc2db..5ce4c66d2c138bf511eb3ffe7ba015e45037af0f 100644 (file)
@@ -77,14 +77,16 @@ bool BackupEngine::error(const QString& message){
  */
 void BackupEngine::initializeShadowDir(){
        if (m_shadowBaseDir.isEmpty()){
-               int fullLength = m_targetBaseDir.length();
-               QString node = ReFileUtils::nodeOf(m_targetBaseDir);
+               QString baseDir = m_targetBaseDir;
+               ReQStringUtils::chomp(baseDir, OS_SEPARATOR);
+               int fullLength = baseDir.length();
+               QString node = ReFileUtils::nodeOf(baseDir);
                int nodeLength = node.length();
                if (nodeLength <= 2)
-                       m_shadowBaseDir = ReFileUtils::parentOf(m_targetBaseDir) + "$";
+                       m_shadowBaseDir = ReFileUtils::parentOf(baseDir) + "$";
                else {
                        int middle = nodeLength / 2;
-                       m_shadowBaseDir = "." + m_targetBaseDir;
+                       m_shadowBaseDir = ReFileUtils::parentOf(baseDir) + "." + node;
                        m_shadowBaseDir.remove(fullLength - middle, 1);
                }
        }
@@ -147,7 +149,7 @@ void BackupEngine::removeOlder(const QString& directory, const QDateTime& time,
                   }
           } else if (it.fileInfo().lastModified() < time){
                   isEmpty = false;
-                  info = prefix + QChar(CmdRemove) + it.fileName();
+                  info = prefix + QChar(CmdRemove) + it.filePath();
                   m_mutex.lock();
                   m_files.append(info);
                   m_hotFiles++;
@@ -157,7 +159,7 @@ void BackupEngine::removeOlder(const QString& directory, const QDateTime& time,
           }
        }
        if (isEmpty){
-               info = prefix + QChar(CmdRemoveDir) + it.fileName();
+               info = QChar(index + 1) + it.filePath() + "\t" + QChar(CmdRemoveDir);
                m_mutex.lock();
                m_files.append(info);
                m_matchedFiles++;
@@ -492,7 +494,7 @@ CleanTask::CleanTask(const QString& name, const QStringList& sourceDirs,
                                         const QString& targetDir, MainWindow* mainWindow) :
        BackupEngine(name, sourceDirs, targetDir, mainWindow)
 {
-
+       initializeShadowDir();
 }
 
 /**
@@ -529,20 +531,35 @@ void CleanTask::run()
                        node = info.mid(pos + 2);
                        switch(command){
                        case CmdRemove:
-                               m_mainWindow->addToFileList("-" + relPath);
+                               if (unlink(I18N::s2b(relPath)) != 0)
+                                       error(QObject::tr("cannot delete target (%1): %2").arg(errno)
+                                                 .arg(relPath));
+                               else
+                                       m_mainWindow->addToFileList("- " + relPath);
                                break;
                        case CmdRemoveDir:
-                               m_mainWindow->addToFileList("/" + relPath);
+                               m_mainWindow->addToFileList("/ " + relPath);
                                break;
                        case CmdMove:
                        {
                                QString target = m_targetDirs.at(index) + relPath + node;
                                QString shadowDir = m_shadowDirs.at(index) + relPath;
+                               ReQStringUtils::chomp(shadowDir, OS_SEPARATOR);
                                QString shadow = shadowDir + node;
                                if (! ReFileUtils::makeDirWithParents(shadowDir))
                                        error(QObject::tr("cannot create the shadow directory: %1")
                                                  .arg(shadowDir));
-                               m_mainWindow->addToFileList(">" + target + " -> " + shadow);
+                               QByteArray shadow2 = I18N::s2b(shadow);
+                               struct stat info;
+                               if (stat(shadow2.constData(), &info) == 0){
+                                       if (unlink(shadow2.constData()) != 0){
+                                               error(QObject::tr("cannot delete shadow file (%1): %2").arg(errno).arg(shadow));
+                                       }
+                               }
+                               if (rename(I18N::s2b(target).constData(), shadow2.constData()) != 0)
+                                       error(QObject::tr("cannot rename target file (%1): %2 -> %3")
+                                                 .arg(errno).arg(target).arg(shadow));
+                               m_mainWindow->addToFileList(">" + target);
                                break;
                        }
                        default:
@@ -733,9 +750,9 @@ void SearchTask::searchOneDirectory(const QString& source,
 SearchTargetTask::SearchTargetTask(const QString& name, const QStringList& sourceDirs,
                                         const QString& targetDir, qint64 maxAgeSec, MainWindow* mainWindow) :
        BackupEngine(name, sourceDirs, targetDir, mainWindow),
-       m_maxAge()
+       m_maxAge(QDateTime::currentDateTime())
 {
-       m_maxAge.setMSecsSinceEpoch(maxAgeSec * 1000);
+       m_maxAge.addSecs(- maxAgeSec);
        initializeShadowDir();
 }
 
@@ -775,11 +792,17 @@ void SearchTargetTask::searchOneDirectory(const QString& target,
                   // nothing to do
           } else{
                   Command command = CmdUndef;
-                  QFileInfo src(source + it.fileName());
+                  QString fullSrc = source + it.fileName();
+                  QFileInfo src(fullSrc);
                   if (! src.exists()){
                           const QFileInfo trg = it.fileInfo();
-                          command = trg.lastModified() < m_maxAge ? CmdRemove : CmdMove;
-                          info = prefix + QChar(command) + it.fileName();
+                          if (trg.lastModified() < m_maxAge){
+                                  command = CmdRemove;
+                                  info =  QChar(1 + index) + it.filePath() + "\t" + QChar(command);
+                          } else {
+                                  command = CmdMove;
+                                  info = prefix + QChar(command) + it.fileName();
+                          }
                   }
                   m_mutex.lock();
                   if (command != CmdUndef){
index 63970b16c41caabd728fe3cfb4318896fc9e95a9..b3bc904de2a74087d9cb83c301a1886ef46d2de9 100644 (file)
@@ -381,12 +381,12 @@ void MainWindow::onClean()
                        initializeStart();
                        delete m_searchTargetTask;
                        m_searchTargetTask = new SearchTargetTask(item.m_name,
-                                                                               item.m_sources, target, this);
+                                                       item.m_sources, target, 14*24*3600, this);
                        m_searchTargetTask->start();
                        delete m_cleanTask;
                        m_cleanTask = new CleanTask(item.m_name, item.m_sources, target,
-                                                                                 this);
-                       m_backupTask->start();
+                                                       this);
+                       m_cleanTask->start();
                }
        }
 }