[Pkg-owncloud-commits] [owncloud-client] 33/103: Make sure the fileid are saved to the database when upgrading from owncloud5 to owncloud6

Sandro Knauß hefee-guest at moszumanska.debian.org
Wed Apr 30 18:08:56 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 fa38bf7029d6bb6efc39d6c6416ab8d0dece7c1a
Author: Olivier Goffart <ogoffart at woboq.com>
Date:   Fri Apr 18 18:27:27 2014 +0200

    Make sure the fileid are saved to the database when upgrading from owncloud5 to owncloud6
    
    We fetch the id from the server, but don't save them in the database.
    
    I Could have used INSTRUCTION_UPDATED for that, but then i would need to update the
    reconcile algorithm to take in account the fact that UPDATED is possible there.
    
    Instead, use should_update_etag  which means the db is going to be written again
    
    Remove reference to old instruction _UPDATED and _DELETED which does not make sens with
    the new propagator
    
    Improve the test to test this case,  and that etags are properly writen to the DB
    when there is a fake conflict
---
 csync/src/csync.h                            |  5 +----
 csync/src/csync_reconcile.c                  |  3 ++-
 csync/src/csync_update.c                     | 11 ++++++++++-
 csync/src/csync_util.c                       |  2 --
 csync/tests/csync_tests/check_csync_update.c |  7 -------
 csync/tests/ownCloud/t1.pl                   | 20 ++++++++++++++++----
 csync/tests/ownCloud/t2.pl                   | 19 ++++++++++++++++++-
 src/mirall/progressdispatcher.cpp            |  6 ------
 src/mirall/propagatorjobs.cpp                |  1 -
 src/mirall/syncengine.cpp                    | 11 +++++------
 src/mirall/syncrunfilelog.cpp                |  6 ------
 11 files changed, 52 insertions(+), 39 deletions(-)

diff --git a/csync/src/csync.h b/csync/src/csync.h
index 1b7614d..49f3979 100644
--- a/csync/src/csync.h
+++ b/csync/src/csync.h
@@ -130,10 +130,7 @@ enum csync_instructions_e {
   CSYNC_INSTRUCTION_IGNORE     = 0x00000020,  /* The file is ignored (UPDATE|RECONCILE) */
   CSYNC_INSTRUCTION_SYNC       = 0x00000040,  /* The file need to be pushed to the other remote (RECONCILE) */
   CSYNC_INSTRUCTION_STAT_ERROR = 0x00000080,
-  CSYNC_INSTRUCTION_ERROR      = 0x00000100,
-  /* instructions for the propagator */
-  CSYNC_INSTRUCTION_DELETED    = 0x00000200,
-  CSYNC_INSTRUCTION_UPDATED    = 0x00000400
+  CSYNC_INSTRUCTION_ERROR      = 0x00000100
 };
 
 enum csync_ftw_type_e {
diff --git a/csync/src/csync_reconcile.c b/csync/src/csync_reconcile.c
index 038b5c0..5d3e3ab 100644
--- a/csync/src/csync_reconcile.c
+++ b/csync/src/csync_reconcile.c
@@ -235,10 +235,11 @@ static int _csync_merge_algorithm_visitor(void *obj, void *data) {
                 }
                 if (is_equal_files) {
                     /* The files are considered equal. */
-                    cur->instruction = CSYNC_INSTRUCTION_UPDATED; /* update the DB */
+                    cur->instruction = CSYNC_INSTRUCTION_NONE;
                     other->instruction = CSYNC_INSTRUCTION_NONE;
 
                     if( !cur->etag && other->etag ) cur->etag = c_strdup(other->etag);
+                    cur->should_update_etag = true; /* update DB */
                 } else if(ctx->current == REMOTE_REPLICA) {
                         cur->instruction = CSYNC_INSTRUCTION_CONFLICT;
                         other->instruction = CSYNC_INSTRUCTION_NONE;
diff --git a/csync/src/csync_update.c b/csync/src/csync_update.c
index db0c9ac..75b7a4a 100644
--- a/csync/src/csync_update.c
+++ b/csync/src/csync_update.c
@@ -237,10 +237,19 @@ static int _csync_detect_update(CSYNC *ctx, const char *file,
         if (type == CSYNC_FTW_TYPE_DIR && ctx->current == REMOTE_REPLICA
                 && c_streq(fs->file_id, tmp->file_id)) {
             /* If both etag and file id are equal for a directory, read all contents from
-             * the database. */
+             * the database.
+             * The comparison of file id ensure that we fetch all the file id when upgrading from
+             * owncloud 5 to owncloud 6.
+             */
             CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE, "Reading from database: %s", path);
             ctx->remote.read_from_db = true;
         }
+
+        if (!c_streq(fs->file_id, tmp->file_id) && ctx->current == REMOTE_REPLICA) {
+            /* file id has changed. Which means we need to update the DB.
+             * (upgrade from owncloud 5 to owncloud 6 for instence) */
+            st->should_update_etag = true;
+        }
         st->instruction = CSYNC_INSTRUCTION_NONE;
     } else {
         enum csync_vio_file_type_e tmp_vio_type = CSYNC_VIO_FILE_TYPE_UNKNOWN;
diff --git a/csync/src/csync_util.c b/csync/src/csync_util.c
index 0daad23..cca764c 100644
--- a/csync/src/csync_util.c
+++ b/csync/src/csync_util.c
@@ -55,8 +55,6 @@ static const _instr_code_struct _instr[] =
   { "INSTRUCTION_SYNC", CSYNC_INSTRUCTION_SYNC },
   { "INSTRUCTION_STAT_ERR", CSYNC_INSTRUCTION_STAT_ERROR },
   { "INSTRUCTION_ERROR", CSYNC_INSTRUCTION_ERROR },
-  { "INSTRUCTION_DELETED", CSYNC_INSTRUCTION_DELETED },
-  { "INSTRUCTION_UPDATED", CSYNC_INSTRUCTION_UPDATED },
   { NULL, CSYNC_INSTRUCTION_ERROR }
 };
 
diff --git a/csync/tests/csync_tests/check_csync_update.c b/csync/tests/csync_tests/check_csync_update.c
index 5f8be2f..0b4264e 100644
--- a/csync/tests/csync_tests/check_csync_update.c
+++ b/csync/tests/csync_tests/check_csync_update.c
@@ -233,8 +233,6 @@ static void check_csync_detect_update_db_none(void **state)
     st = c_rbtree_node_data(csync->local.tree->root);
     assert_int_equal(st->instruction, CSYNC_INSTRUCTION_NEW);
 
-    /* set the instruction to UPDATED that it gets written to the statedb */
-    st->instruction = CSYNC_INSTRUCTION_UPDATED;
 
     /* create a statedb */
     csync_set_status(csync, 0xFFFF);
@@ -262,9 +260,6 @@ static void check_csync_detect_update_db_eval(void **state)
     st = c_rbtree_node_data(csync->local.tree->root);
     assert_int_equal(st->instruction, CSYNC_INSTRUCTION_NEW);
 
-    /* set the instruction to UPDATED that it gets written to the statedb */
-    st->instruction = CSYNC_INSTRUCTION_UPDATED;
-
     /* create a statedb */
     csync_set_status(csync, 0xFFFF);
 
@@ -344,8 +339,6 @@ static void check_csync_detect_update_db_new(void **state)
     st = c_rbtree_node_data(csync->local.tree->root);
     assert_int_equal(st->instruction, CSYNC_INSTRUCTION_NEW);
 
-    /* set the instruction to UPDATED that it gets written to the statedb */
-    st->instruction = CSYNC_INSTRUCTION_UPDATED;
 
     /* create a statedb */
     csync_set_status(csync, 0xFFFF);
diff --git a/csync/tests/ownCloud/t1.pl b/csync/tests/ownCloud/t1.pl
index 8a578a8..8feedf0 100755
--- a/csync/tests/ownCloud/t1.pl
+++ b/csync/tests/ownCloud/t1.pl
@@ -97,11 +97,23 @@ csync();
 assertLocalAndRemoteDir( 'fromLocal1', 0);
 assert( ! -e localDir().'remoteToLocal1/rtlX' );
 
-# create a false conflict, only the mtimes are changed, by content are equal.
-printInfo( "Create a false conflict.");
-my $srcFile = 'toremote1/kernelcrash.txt';
-put_to_dir( $srcFile, 'remoteToLocal1' );
+# create twos false conflict, only the mtimes are changed, by content are equal.
+printInfo( "Create two false conflict.");
+put_to_dir( 'toremote1/kernelcrash.txt', 'remoteToLocal1' );
+put_to_dir( 'toremote1/kraft_logo.gif', 'remoteToLocal1' );
+# don't wait so mtime are likely the same on the client and the server.
+system( "touch " . localDir() . "remoteToLocal1/kraft_logo.gif" );
+# wait two second so the mtime are different
 system( "sleep 2 && touch " . localDir() . "remoteToLocal1/kernelcrash.txt" );
+
+
+csync( );
+assertLocalAndRemoteDir( 'fromLocal1', 0);
+
+# The previous sync should have updated the etags, and this should NOT be a conflict
+printInfo( "Update the file again");
+system("echo more data >> " .  localDir() . "remoteToLocal1/kernelcrash.txt");
+system("echo corruption >> " .  localDir() . "remoteToLocal1/kraft_logo.gif");
 csync( );
 assertLocalAndRemoteDir( 'fromLocal1', 0);
 
diff --git a/csync/tests/ownCloud/t2.pl b/csync/tests/ownCloud/t2.pl
index 77f1d70..5260f77 100755
--- a/csync/tests/ownCloud/t2.pl
+++ b/csync/tests/ownCloud/t2.pl
@@ -80,7 +80,6 @@ assert( $inode == $inode2, "Inode has changed!");
 
 printInfo("Move a file into a sub directory.");
 # now move the file into a sub directory
-$inode = getInode('remoteToLocal1/kernel.txt');
 moveRemoteFile( 'remoteToLocal1/kernel.txt', 'remoteToLocal1/rtl1/');
 
 csync();
@@ -175,6 +174,24 @@ createLocalFile( localDir(). 'remoteToLocal1/rtl2/newRemoteDir/donat.txt', 8021
 csync();
 assertLocalAndRemoteDir( 'remoteToLocal1', 1);
 
+printInfo("simulate a owncloud 5 update by removing all the fileid");
+## simulate a owncloud 5 update by removing all the fileid
+system( "sqlite3 " . localDir() . ".csync_journal.db \"UPDATE metadata SET fileid='';\"");
+#refresh the ids
+csync();
+assertLocalAndRemoteDir( 'remoteToLocal1', 1);
+
+
+printInfo("Move a file from the server");
+$inode = getInode('remoteToLocal1/rtl2/kb1_local_gone.jpg');
+moveRemoteFile( 'remoteToLocal1/rtl2/kb1_local_gone.jpg', 'remoteToLocal1/rtl2/kb1_local_gone2.jpg');
+csync();
+assertLocalAndRemoteDir( 'remoteToLocal1', 1);
+$inode2 = getInode('remoteToLocal1/rtl2/kb1_local_gone2.jpg');
+assert( $inode == $inode2, "Inode has changed 3!");
+
+
+
 cleanup();
 
 # --
diff --git a/src/mirall/progressdispatcher.cpp b/src/mirall/progressdispatcher.cpp
index 46403c5..9d003f2 100644
--- a/src/mirall/progressdispatcher.cpp
+++ b/src/mirall/progressdispatcher.cpp
@@ -33,7 +33,6 @@ QString Progress::asResultString( const SyncFileItem& item)
         } else {
             return QCoreApplication::translate( "progress", "Uploaded");
         }
-    case CSYNC_INSTRUCTION_DELETED:
     case CSYNC_INSTRUCTION_REMOVE:
         return QCoreApplication::translate( "progress", "Deleted");
     case CSYNC_INSTRUCTION_EVAL_RENAME:
@@ -45,8 +44,6 @@ QString Progress::asResultString( const SyncFileItem& item)
         return QCoreApplication::translate( "progress", "Filesystem access error");
     case CSYNC_INSTRUCTION_ERROR:
         return QCoreApplication::translate( "progress", "Error");
-    case CSYNC_INSTRUCTION_UPDATED:
-        return QCoreApplication::translate( "progress", "Updated");
     case CSYNC_INSTRUCTION_NONE:
     case CSYNC_INSTRUCTION_EVAL:
         return QCoreApplication::translate( "progress", "Unknown");
@@ -66,7 +63,6 @@ QString Progress::asActionString( const SyncFileItem &item )
         else
             return QCoreApplication::translate( "progress", "uploading");
     case CSYNC_INSTRUCTION_REMOVE:
-    case CSYNC_INSTRUCTION_DELETED:
         return QCoreApplication::translate( "progress", "deleting");
     case CSYNC_INSTRUCTION_EVAL_RENAME:
     case CSYNC_INSTRUCTION_RENAME:
@@ -77,8 +73,6 @@ QString Progress::asActionString( const SyncFileItem &item )
         return QCoreApplication::translate( "progress", "error");
     case CSYNC_INSTRUCTION_ERROR:
         return QCoreApplication::translate( "progress", "error");
-    case CSYNC_INSTRUCTION_UPDATED:
-        return QCoreApplication::translate( "progress", "updating");
     case CSYNC_INSTRUCTION_NONE:
     case CSYNC_INSTRUCTION_EVAL:
         return QCoreApplication::translate( "progress", "unknown");
diff --git a/src/mirall/propagatorjobs.cpp b/src/mirall/propagatorjobs.cpp
index 4b4699e..d9fbb02 100644
--- a/src/mirall/propagatorjobs.cpp
+++ b/src/mirall/propagatorjobs.cpp
@@ -181,7 +181,6 @@ void PropagateLocalRename::start()
         QFile::rename(_propagator->_localDir + _item._file, _propagator->_localDir + _item._renameTarget);
     }
 
-    _item._instruction = CSYNC_INSTRUCTION_DELETED;
     _propagator->_journal->deleteFileRecord(_item._originalFile);
 
     // store the rename file name in the item.
diff --git a/src/mirall/syncengine.cpp b/src/mirall/syncengine.cpp
index fec5c5a..cf383aa 100644
--- a/src/mirall/syncengine.cpp
+++ b/src/mirall/syncengine.cpp
@@ -309,12 +309,12 @@ int SyncEngine::treewalkFile( TREE_WALK_FILE *file, bool remote )
     int re = 0;
 
     switch(file->instruction) {
-    case CSYNC_INSTRUCTION_UPDATED:
-        // We need to update the database.
-        _journal->setFileRecord(SyncJournalFileRecord(item, _localPath + item._file));
-        item._instruction = CSYNC_INSTRUCTION_NONE;
-        // fall trough
     case CSYNC_INSTRUCTION_NONE:
+        if (file->should_update_etag && !item._isDirectory) {
+            // Update the database now already  (new fileid or etag)
+            _journal->setFileRecord(SyncJournalFileRecord(item, _localPath + item._file));
+            item._should_update_etag = false;
+        }
         if (item._isDirectory && remote) {
             // Because we want still to update etags of directories
             dir = SyncFileItem::None;
@@ -344,7 +344,6 @@ int SyncEngine::treewalkFile( TREE_WALK_FILE *file, bool remote )
     case CSYNC_INSTRUCTION_NEW:
     case CSYNC_INSTRUCTION_SYNC:
     case CSYNC_INSTRUCTION_STAT_ERROR:
-    case CSYNC_INSTRUCTION_DELETED:
     default:
         dir = remote ? SyncFileItem::Down : SyncFileItem::Up;
         break;
diff --git a/src/mirall/syncrunfilelog.cpp b/src/mirall/syncrunfilelog.cpp
index bd678ea..a30eae6 100644
--- a/src/mirall/syncrunfilelog.cpp
+++ b/src/mirall/syncrunfilelog.cpp
@@ -79,12 +79,6 @@ QString SyncRunFileLog::instructionToStr( csync_instructions_e inst )
     case CSYNC_INSTRUCTION_ERROR:
         re = "INST_ERROR";
         break;
-    case CSYNC_INSTRUCTION_DELETED:
-        re = "INST_DELETED";
-        break;
-    case CSYNC_INSTRUCTION_UPDATED:
-        re = "INST_UPDATED";
-        break;
     }
 
     return re;

-- 
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