]> gitweb.hamatoma.de Git - reqt/commitdiff
rebackgui: clean works
authorhama <hama@siduction.net>
Wed, 10 Feb 2016 23:09:16 +0000 (00:09 +0100)
committerhama <hama@siduction.net>
Wed, 10 Feb 2016 23:09:16 +0000 (00:09 +0100)
appl/rebackgui/BackupEngine.cpp

index 5ce4c66d2c138bf511eb3ffe7ba015e45037af0f..d27e74447257e9753b747ecc0986e192fc347c2c 100644 (file)
@@ -91,9 +91,12 @@ void BackupEngine::initializeShadowDir(){
                }
        }
        m_shadowDirs.clear();
+       QString path;
        for (int ix = 0; ix < m_sourceDirs.size(); ix++){
+               path = m_sourceDirs.at(ix);
+               ReQStringUtils::chomp(path, OS_SEPARATOR);
                m_shadowDirs.append(m_shadowBaseDir + OS_SEPARATOR_STR
-                                                + ReFileUtils::nodeOf(m_sourceDirs.at(ix)));
+                                                + ReFileUtils::nodeOf(path) + OS_SEPARATOR);
        }
 }
 
@@ -114,7 +117,7 @@ bool BackupEngine::log(const QString& message){
  *
  * Note: this method is recursive.
  *
- * @param directory    directory to inspect
+ * @param directory    directory to inspect, e.g. "/media/trg/x"
  * @param maxAge       all files older than this time point will be deleted
  * @param index                the index in the shadow directories
  */
@@ -128,13 +131,6 @@ void BackupEngine::removeOlder(const QString& directory, const QDateTime& time,
        m_mutex.lock();
        m_totalDirs++;
        m_mutex.unlock();
-       if (directory.length() > lengthBase){
-               prefix = QChar(1 + index)
-                               + ReFileUtils::nativePath(directory.mid(lengthBase)) + OS_SEPARATOR_STR
-                               + m_separator;
-       } else {
-               prefix = QChar(1 + index) + m_separatorString;
-       }
        bool isEmpty = true;
        while (it.hasNext()){
           if (m_shouldStop){
@@ -149,7 +145,8 @@ void BackupEngine::removeOlder(const QString& directory, const QDateTime& time,
                   }
           } else if (it.fileInfo().lastModified() < time){
                   isEmpty = false;
-                  info = prefix + QChar(CmdRemove) + it.filePath();
+                  info = QChar(index + 1) + it.filePath() + m_separatorString
+                                  + QChar(CmdRemove) ;
                   m_mutex.lock();
                   m_files.append(info);
                   m_hotFiles++;
@@ -159,7 +156,8 @@ void BackupEngine::removeOlder(const QString& directory, const QDateTime& time,
           }
        }
        if (isEmpty){
-               info = QChar(index + 1) + it.filePath() + "\t" + QChar(CmdRemoveDir);
+               info = QChar(index + 1) + it.filePath() + m_separatorString
+                               + QChar(CmdRemoveDir);
                m_mutex.lock();
                m_files.append(info);
                m_matchedFiles++;
@@ -545,7 +543,7 @@ void CleanTask::run()
                                QString target = m_targetDirs.at(index) + relPath + node;
                                QString shadowDir = m_shadowDirs.at(index) + relPath;
                                ReQStringUtils::chomp(shadowDir, OS_SEPARATOR);
-                               QString shadow = shadowDir + node;
+                               QString shadow = shadowDir + OS_SEPARATOR_STR + node;
                                if (! ReFileUtils::makeDirWithParents(shadowDir))
                                        error(QObject::tr("cannot create the shadow directory: %1")
                                                  .arg(shadowDir));
@@ -750,9 +748,8 @@ 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(QDateTime::currentDateTime())
+       m_maxAge(QDateTime::currentDateTime().addSecs(- maxAgeSec))
 {
-       m_maxAge.addSecs(- maxAgeSec);
        initializeShadowDir();
 }
 
@@ -768,7 +765,7 @@ SearchTargetTask::SearchTargetTask(const QString& name, const QStringList& sourc
 void SearchTargetTask::searchOneDirectory(const QString& target,
                                                                         const QString& source, int index){
        QDirIterator it(target);
-       QString info, node;
+       QString info, node, relPath;
        int lengthBase = m_targetDirs.at(index).length();
        assert(index < 0x7fff);
        QString prefix;
@@ -776,9 +773,8 @@ void SearchTargetTask::searchOneDirectory(const QString& target,
        m_totalDirs++;
        m_mutex.unlock();
        if (source.length() > lengthBase){
-               prefix = QChar(1 + index)
-                               + ReFileUtils::nativePath(source.mid(lengthBase)) + OS_SEPARATOR_STR
-                               + m_separator;
+               relPath = ReFileUtils::nativePath(source.mid(lengthBase));
+               prefix = QChar(1 + index) + relPath + OS_SEPARATOR_STR + m_separator;
        } else {
                prefix = QChar(1 + index) + m_separatorString;
        }
@@ -796,7 +792,8 @@ void SearchTargetTask::searchOneDirectory(const QString& target,
                   QFileInfo src(fullSrc);
                   if (! src.exists()){
                           const QFileInfo trg = it.fileInfo();
-                          if (trg.lastModified() < m_maxAge){
+                          QDateTime trgTime = trg.lastModified();
+                          if (trgTime < m_maxAge){
                                   command = CmdRemove;
                                   info =  QChar(1 + index) + it.filePath() + "\t" + QChar(command);
                           } else {
@@ -830,7 +827,7 @@ void SearchTargetTask::searchOneDirectory(const QString& target,
                           if (src.exists() && src.isDir())
                                   searchOneDirectory(it2.filePath(), newSource + OS_SEPARATOR_STR, index);
                           else{
-                                  moveToShadow(it2.filePath(), prefix, index);
+                                  moveToShadow(it2.filePath(), relPath, index);
                           }
                   }
                }
@@ -855,7 +852,7 @@ void SearchTargetTask::moveToShadow(const QString& target, const QString& relPat
                        error(QObject::tr("cannot move to shadow directory (%1): %2 -> %3")
                                  .arg(errno).arg(target).arg(shadow));
                } else {
-                       removeOlder(shadowDir, m_maxAge, index);
+                       removeOlder(shadow, m_maxAge, index);
                }
        }
 }