Use destination path in case of file rename.

This commit is contained in:
Klaas Freitag 2012-09-24 15:57:32 +03:00
parent 2354b9c52f
commit 34249e9f64

View file

@ -175,6 +175,11 @@ static int _merge_file_trees_visitor(void *obj, void *data) {
switch (ctx->current) {
case LOCAL_REPLICA:
/* If there is a destpath, this is a rename and the target must be used. */
if( fs->destpath ) {
asprintf(&uri, "%s/%s", ctx->local.uri, fs->destpath);
SAFE_FREE(fs->destpath);
} else {
if (asprintf(&uri, "%s/%s", ctx->local.uri, fs->path) < 0) {
rc = -1;
strerror_r(errno, errbuf, sizeof(errbuf));
@ -182,6 +187,7 @@ static int _merge_file_trees_visitor(void *obj, void *data) {
errbuf);
goto out;
}
}
break;
case REMOTE_REPLCIA:
if (asprintf(&uri, "%s/%s", ctx->remote.uri, fs->path) < 0) {
@ -212,7 +218,7 @@ static int _merge_file_trees_visitor(void *obj, void *data) {
fs->inode = vst->inode;
fs->modtime = vst->mtime;
/* update with the id from the remote repo */
/* update with the id from the remote repo. This method always works on the local repo */
node = c_rbtree_find(ctx->remote.tree, &fs->phash);
if (node == NULL) {
rc = -1;
@ -221,13 +227,14 @@ static int _merge_file_trees_visitor(void *obj, void *data) {
}
tfs = c_rbtree_node_data(node);
if( tfs->md5 ) {
if( tfs && tfs->md5 ) {
if( fs->md5 ) SAFE_FREE(fs->md5);
fs->md5 = c_strdup( tfs->md5 );
CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "PRE UPDATED %s: %s <-> %s", uri, fs->md5, tfs->md5);
CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "PRE UPDATED %s: %s <-> %s", fs->path, fs->md5, tfs->md5);
} else {
CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "md5 is empty in merger!");
}
CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "file: %s, instruction: UPDATED (%s)", uri, fs->md5);
fs->instruction = CSYNC_INSTRUCTION_NONE;