From 3e1690ff7abbcfe00d8d565860511110bc61cc7b Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Wed, 14 Sep 2016 15:42:19 +0200 Subject: [PATCH] Improvements to file recall --- csync/tests/ownCloud/t_recall.pl | 6 +++++ src/libsync/propagatedownload.cpp | 45 ++++++++++++++++++++++--------- 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/csync/tests/ownCloud/t_recall.pl b/csync/tests/ownCloud/t_recall.pl index 244618cf8..de0e17069 100755 --- a/csync/tests/ownCloud/t_recall.pl +++ b/csync/tests/ownCloud/t_recall.pl @@ -56,6 +56,8 @@ assertLocalAndRemoteDir( '', 0); printInfo( "Testing with a .sys.admin#recall#" ); system("echo 'dir/file2.dat' > ". $tmpdir . ".sys.admin\#recall\#"); system("echo 'dir/file3.dat' >> ". $tmpdir . ".sys.admin\#recall\#"); +system("echo 'nonexistant' >> ". $tmpdir . ".sys.admin\#recall\#"); +system("echo '/tmp/t_recall/file4.dat' >> ". $tmpdir . ".sys.admin\#recall\#"); glob_put( "$tmpdir/.sys.admin\#recall\#", "" ); csync(); @@ -68,6 +70,10 @@ assert( -e glob(localDir().'dir/file3_.sys.admin#recall#-*.dat' ) ); assert( -e glob(localDir().'dir/file2.dat' ) ); assert( -e glob(localDir().'dir/file3.dat' ) ); +assert( !-e glob(localDir().'nonexistant*' ) ); +assert( !-e glob('/tmp/t_recall/file4_.sys.admin#recall#-*.dat' ) ); +assert( -e glob('/tmp/t_recall/file4.dat' ) ); + #Remove the recall file unlink(localDir() . ".sys.admin#recall#"); diff --git a/src/libsync/propagatedownload.cpp b/src/libsync/propagatedownload.cpp index 27a214d75..92618e7b7 100644 --- a/src/libsync/propagatedownload.cpp +++ b/src/libsync/propagatedownload.cpp @@ -617,30 +617,47 @@ static QString makeRecallFileName(const QString &fn) return recallFileName; } -static void handleRecallFile(const QString &fn) +void handleRecallFile(const QString& filePath, const QString& folderPath, SyncJournalDb& journal) { - qDebug() << "handleRecallFile: " << fn; + qDebug() << "handleRecallFile: " << filePath; - FileSystem::setFileHidden(fn, true); + FileSystem::setFileHidden(filePath, true); - QFile file(fn); + QFile file(filePath); if (!file.open(QIODevice::ReadOnly)) { qWarning() << "Could not open recall file" << file.errorString(); return; } - QFileInfo existingFile(fn); - QDir thisDir = existingFile.dir(); + QFileInfo existingFile(filePath); + QDir baseDir = existingFile.dir(); while (!file.atEnd()) { QByteArray line = file.readLine(); line.chop(1); // remove trailing \n - QString fpath = thisDir.filePath(line); - QString rpath = makeRecallFileName(fpath); - qDebug() << "Copy recall file: " << fpath << " -> " << rpath; + QString recalledFile = QDir::cleanPath(baseDir.filePath(line)); + if (!recalledFile.startsWith(folderPath) || !recalledFile.startsWith(baseDir.path())) { + qDebug() << "Ignoring recall of " << recalledFile; + continue; + } + + // Path of the recalled file in the local folder + QString localRecalledFile = recalledFile.mid(folderPath.size()); + + SyncJournalFileRecord record = journal.getFileRecord(localRecalledFile); + if (!record.isValid()) { + qDebug() << "No db entry for recall of" << localRecalledFile; + continue; + } + + qDebug() << "Recalling" << localRecalledFile << "Checksum:" << record._contentChecksumType << record._contentChecksum; + + QString targetPath = makeRecallFileName(recalledFile); + + qDebug() << "Copy recall file: " << recalledFile << " -> " << targetPath; // Remove the target first, QFile::copy will not overwrite it. - FileSystem::remove(rpath); - QFile::copy(fpath, rpath); + FileSystem::remove(targetPath); + QFile::copy(recalledFile, targetPath); } } @@ -797,8 +814,10 @@ void PropagateDownloadFileQNAM::downloadFinished() done(isConflict ? SyncFileItem::Conflict : SyncFileItem::Success); // handle the special recall file - if(_item->_file == QLatin1String(".sys.admin#recall#") || _item->_file.endsWith("/.sys.admin#recall#")) { - handleRecallFile(fn); + if(!_item->_remotePerm.contains("S") + && (_item->_file == QLatin1String(".sys.admin#recall#") + || _item->_file.endsWith("/.sys.admin#recall#"))) { + handleRecallFile(fn, _propagator->_localDir, *_propagator->_journal); } qint64 duration = _stopwatch.elapsed(); -- 2.30.2