*/
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);
}
}
}
} 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++;
}
}
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++;
const QString& targetDir, MainWindow* mainWindow) :
BackupEngine(name, sourceDirs, targetDir, mainWindow)
{
-
+ initializeShadowDir();
}
/**
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:
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();
}
// 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){