[Pkg-owncloud-commits] [owncloud-client] 20/47: Fix removing and renaming directories from the Shared directory

Sandro Knauß hefee-guest at moszumanska.debian.org
Mon Feb 17 18:06:33 UTC 2014


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit a677f97b7fd81a64de15368c7757b6662892be75
Author: Olivier Goffart <ogoffart at woboq.com>
Date:   Wed Feb 12 13:44:55 2014 +0100

    Fix removing and renaming directories from the Shared directory
---
 src/mirall/owncloudpropagator.cpp | 30 ++++++++++++++++++++++++------
 src/mirall/syncjournaldb.cpp      | 19 +++++++++++++++++++
 src/mirall/syncjournaldb.h        |  1 +
 3 files changed, 44 insertions(+), 6 deletions(-)

diff --git a/src/mirall/owncloudpropagator.cpp b/src/mirall/owncloudpropagator.cpp
index d935c8a..fa0ff99 100644
--- a/src/mirall/owncloudpropagator.cpp
+++ b/src/mirall/owncloudpropagator.cpp
@@ -100,18 +100,36 @@ void PropagateItemJob::done(SyncFileItem::Status status, const QString &errorStr
 }
 
 
+/**
+ * For delete or remove, check that we are not removing from a shared directory.
+ * If we are, try to restore the file
+ *
+ * Return true if the problem is handled.
+ */
 bool PropagateItemJob::checkForProblemsWithShared()
 {
     QString errorString = QString::fromUtf8(ne_get_error(_propagator->_session));
     int httpStatusCode = errorString.mid(0, errorString.indexOf(QChar(' '))).toInt();
 
     if( httpStatusCode == 403 && _propagator->isInSharedDirectory(_item._file )) {
-        // the file was removed locally from a read only Shared sync
-        // the file is gone locally and it should be recovered.
-        SyncFileItem downloadItem(_item);
-        downloadItem._instruction = CSYNC_INSTRUCTION_SYNC;
-        downloadItem._dir = SyncFileItem::Down;
-        _restoreJob.reset(new PropagateDownloadFile(_propagator, downloadItem));
+        if( _item._type != SyncFileItem::Directory ) {
+            // the file was removed locally from a read only Shared sync
+            // the file is gone locally and it should be recovered.
+            SyncFileItem downloadItem(_item);
+            downloadItem._instruction = CSYNC_INSTRUCTION_SYNC;
+            downloadItem._dir = SyncFileItem::Down;
+            _restoreJob.reset(new PropagateDownloadFile(_propagator, downloadItem));
+        } else {
+            // Directories are harder to recover.
+            // But just re-create the directory, next sync will be able to recover the files
+            SyncFileItem mkdirItem(_item);
+            mkdirItem._instruction = CSYNC_INSTRUCTION_SYNC;
+            mkdirItem._dir = SyncFileItem::Down;
+            _restoreJob.reset(new PropagateLocalMkdir(_propagator, mkdirItem));
+            // Also remove the inodes and fileid from the db so no further renames are tried for
+            // this item.
+            _propagator->_journal->avoidRenamesOnNextSync(_item._file);
+        }
         connect(_restoreJob.data(), SIGNAL(completed(SyncFileItem)),
                 this, SLOT(slotRestoreJobCompleted(SyncFileItem)));
         _restoreJob->start();
diff --git a/src/mirall/syncjournaldb.cpp b/src/mirall/syncjournaldb.cpp
index c9298ed..d58dced 100644
--- a/src/mirall/syncjournaldb.cpp
+++ b/src/mirall/syncjournaldb.cpp
@@ -776,6 +776,25 @@ void SyncJournalDb::updateBlacklistEntry( const SyncJournalBlacklistRecord& item
 
 }
 
+void SyncJournalDb::avoidRenamesOnNextSync(const QString& path)
+{
+    QMutexLocker locker(&_mutex);
+
+    if( !checkConnect() ) {
+        return;
+    }
+
+    QSqlQuery query(_db);
+    query.prepare("UPDATE metadata SET fileid = '', inode = '0' WHERE path LIKE(?||'/%')");
+    query.bindValue(0, path);
+    if( !query.exec() ) {
+        qDebug() << "SQL error in avoidRenamesOnNextSync: "<< query.lastError().text();
+    } else {
+        qDebug() << query.executedQuery()  << path;
+    }
+}
+
+
 void SyncJournalDb::commit(const QString& context, bool startTrans)
 {
     QMutexLocker lock(&_mutex);
diff --git a/src/mirall/syncjournaldb.h b/src/mirall/syncjournaldb.h
index 35d255a..ae49937 100644
--- a/src/mirall/syncjournaldb.h
+++ b/src/mirall/syncjournaldb.h
@@ -64,6 +64,7 @@ public:
     UploadInfo getUploadInfo(const QString &file);
     void setUploadInfo(const QString &file, const UploadInfo &i);
     SyncJournalBlacklistRecord blacklistEntry( const QString& );
+    void avoidRenamesOnNextSync(const QString &path);
 
     bool postSyncCleanup( const QHash<QString, QString>& items );
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list