Fix: If no database entry exists, the status is set to NEW.

This commit is contained in:
Klaas Freitag 2012-08-20 19:11:18 +03:00
parent 4a6b0e7241
commit ec63ab4e16

View file

@ -115,39 +115,44 @@ static int _csync_detect_update(CSYNC *ctx, const char *file,
} }
} }
#endif #endif
if (tmp && tmp->phash == h) { if(tmp) { /* there is an entry in the database */
/* we have an update! */ if (tmp->phash == h) {
CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE, "time compare: %lu <-> %lu, md5: %s <-> %s", /* we have an update! */
fs->mtime, tmp->modtime, fs->md5, tmp->md5); CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE, "time compare: %lu <-> %lu, md5: %s <-> %s",
if( !fs->md5) { fs->mtime, tmp->modtime, fs->md5, tmp->md5);
st->instruction = CSYNC_INSTRUCTION_EVAL; if( !fs->md5) {
goto out; st->instruction = CSYNC_INSTRUCTION_EVAL;
} goto out;
if( !c_streq(fs->md5, tmp->md5 )) { }
// if (!fs->mtime > tmp->modtime) { if( !c_streq(fs->md5, tmp->md5 )) {
st->instruction = CSYNC_INSTRUCTION_EVAL; // if (!fs->mtime > tmp->modtime) {
goto out; st->instruction = CSYNC_INSTRUCTION_EVAL;
} goto out;
st->instruction = CSYNC_INSTRUCTION_NONE; }
} else { st->instruction = CSYNC_INSTRUCTION_NONE;
/* check if it's a file and has been renamed */
if (type == CSYNC_FTW_TYPE_FILE && ctx->current == LOCAL_REPLICA) {
tmp = csync_statedb_get_stat_by_inode(ctx, fs->inode);
if (tmp && tmp->inode == fs->inode) {
/* inode found so the file has been renamed */
st->instruction = CSYNC_INSTRUCTION_RENAME;
goto out;
} else { } else {
/* file not found in statedb */ /* check if it's a file and has been renamed */
st->instruction = CSYNC_INSTRUCTION_NEW; if (type == CSYNC_FTW_TYPE_FILE && ctx->current == LOCAL_REPLICA) {
goto out; tmp = csync_statedb_get_stat_by_inode(ctx, fs->inode);
if (tmp && tmp->inode == fs->inode) {
CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE, "inodes: %ld <-> %ld", tmp->inode, fs->inode);
/* inode found so the file has been renamed */
st->instruction = CSYNC_INSTRUCTION_RENAME;
goto out;
} else {
/* file not found in statedb */
st->instruction = CSYNC_INSTRUCTION_NEW;
goto out;
}
}
/* directory, remote and file not found in statedb */
st->instruction = CSYNC_INSTRUCTION_NEW;
} }
} } else {
/* directory, remote and file not found in statedb */ st->instruction = CSYNC_INSTRUCTION_NEW;
st->instruction = CSYNC_INSTRUCTION_NEW;
} }
} else { } else {
st->instruction = CSYNC_INSTRUCTION_NEW; st->instruction = CSYNC_INSTRUCTION_NEW;
} }
out: out:
@ -329,7 +334,7 @@ int csync_ftw(CSYNC *ctx, const char *uri, csync_walker_fn fn,
int len = strlen( path ); int len = strlen( path );
uint64_t h = c_jhash64((uint8_t *) path, len, 0); uint64_t h = c_jhash64((uint8_t *) path, len, 0);
fs->md5 = csync_statedb_get_uniqId( ctx, h, fs ); fs->md5 = csync_statedb_get_uniqId( ctx, h, fs );
CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "Uniq ID read from Database: %s -> %s", path, fs->md5); CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "Uniq ID read from Database: %s -> %s", path, fs->md5 ? fs->md5 : "<NULL>" );
} }
CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE, "walk: %s", filename); CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE, "walk: %s", filename);