[Pkg-owncloud-commits] [owncloud-client] 19/47: Fix problems if a file is moved, and another file is created with the same name

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 1a9a14bdec791f0f80c6a91fa9eaf8343ecf42c5
Author: Olivier Goffart <ogoffart at woboq.com>
Date:   Wed Feb 12 13:44:32 2014 +0100

    Fix problems if a file is moved, and another file is created with the same name
---
 csync/src/csync_reconcile.c | 35 ++++++++++++++++++-----------------
 csync/tests/ownCloud/t3.pl  | 12 ++++++++++++
 2 files changed, 30 insertions(+), 17 deletions(-)

diff --git a/csync/src/csync_reconcile.c b/csync/src/csync_reconcile.c
index b6936e0..d886cfe 100644
--- a/csync/src/csync_reconcile.c
+++ b/csync/src/csync_reconcile.c
@@ -114,25 +114,28 @@ static int _csync_merge_algorithm_visitor(void *obj, void *data) {
 
             if( tmp ) {
                 if( tmp->path ) {
-                    /* Find the temporar file in the other tree. */
                     len = strlen( tmp->path );
                     h = c_jhash64((uint8_t *) tmp->path, len, 0);
-                    node = c_rbtree_find(tree, &h);
-                    CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE, "PHash of temporary opposite (%s): %" PRIu64 " %s",
-                              tmp->path , h, node ? "found": "not found" );
-                    if (!node) {
-                        /* the renamed file could not be found in the opposite tree. That is because it
-                         * is not longer existing there, maybe because it was renamed or deleted.
-                         * The journal is cleaned up later after propagation.
-                         */
-
+                    /* First, check that the file is NOT in our tree (another file with the same name was added) */
+                    node = c_rbtree_find(ctx->current == REMOTE_REPLICA ? ctx->remote.tree : ctx->local.tree, &h);
+                    if (node) {
+                        CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE, "Origin found in our tree : %s", tmp->path);
+                    } else {
+                        /* Find the temporar file in the other tree. */
+                        node = c_rbtree_find(tree, &h);
+                        CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE, "PHash of temporary opposite (%s): %" PRIu64 " %s",
+                                tmp->path , h, node ? "found": "not found" );
+                        if (node) {
+                            other = (csync_file_stat_t*)node->data;
+                        } else {
+                            /* the renamed file could not be found in the opposite tree. That is because it
+                            * is not longer existing there, maybe because it was renamed or deleted.
+                            * The journal is cleaned up later after propagation.
+                            */
+                        }
                     }
                 }
 
-                if(node) {
-                    other = (csync_file_stat_t*)node->data;
-                }
-
                 if(!other) {
                     cur->instruction = CSYNC_INSTRUCTION_NEW;
                 } else if (other->instruction == CSYNC_INSTRUCTION_NONE
@@ -159,9 +162,7 @@ static int _csync_merge_algorithm_visitor(void *obj, void *data) {
                     cur->instruction = CSYNC_INSTRUCTION_NONE;
                     other->instruction = CSYNC_INSTRUCTION_SYNC;
                 }
-
-                SAFE_FREE(tmp->etag);
-                SAFE_FREE(tmp);
+                csync_file_stat_free(tmp);
            }
 
             break;
diff --git a/csync/tests/ownCloud/t3.pl b/csync/tests/ownCloud/t3.pl
index 5ab50e3..84ba255 100755
--- a/csync/tests/ownCloud/t3.pl
+++ b/csync/tests/ownCloud/t3.pl
@@ -79,6 +79,7 @@ system( "echo \"super new\" >> " . localDir() . 'newdir/myfile.txt' );
 #Add some files for the next test.
 system( "echo \"un\" > " . localDir() . '1.txt' );
 system( "echo \"deux\" > " . localDir() . '2.txt' );
+system( "echo \"trois\" > " . localDir() . '3.txt' );
 mkdir( localDir() . 'newdir2' );
 
 csync();
@@ -105,6 +106,17 @@ my $newdir4Id = remoteFileId( localDir(), 'newdir4' );
 assert( $newdirId eq $newdir3Id, "newdir was not MOVE'd to newdir3?" );
 assert( $newdir2Id eq $newdir4Id, "newdir2 was not MOVE'd to newdir4?" );
 
+printInfo("Move a file and replace it by a new one");
+
+
+move( localDir() . '1.txt', localDir() . '1_bis.txt' );
+move( localDir() . '3.txt', localDir() . '3_bis.txt' );
+system( "echo \"new file un\" > " . localDir() . '1.txt' );
+system( "echo \"new file trois\" > " . localDir() . '3.txt' );
+
+csync();
+assertLocalAndRemoteDir( '', 0);
+
 
 cleanup();
 

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