}
}
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);
}
}
*
* 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
*/
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){
}
} 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++;
}
}
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++;
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));
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();
}
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;
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;
}
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 {
if (src.exists() && src.isDir())
searchOneDirectory(it2.filePath(), newSource + OS_SEPARATOR_STR, index);
else{
- moveToShadow(it2.filePath(), prefix, index);
+ moveToShadow(it2.filePath(), relPath, index);
}
}
}
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);
}
}
}