Fix problems if a file is moved, and another file is created with the same name

This commit is contained in:
Olivier Goffart 2014-02-12 13:44:32 +01:00
Родитель 153aa31da2
Коммит 1a9a14bdec
2 изменённых файлов: 30 добавлений и 17 удалений

Просмотреть файл

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

Просмотреть файл

@ -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();