Don't reset the md5 if the mtime change locally.

Consider this case when one creates a file with an invalid filename (for
the server) in a directory in the local side.
say: foo/bar/%invalid%.txt

The following would happen:
- in the update for the local parent folder  foo/bar/, the md5 is 0
  because the mtime has changed
- During the reconcile, we try to send %invalid%, but there will be an
  error and nothing will be changed on the server, the etags stay the
  same
- We do not do any PROPFIND at the end so we do not fetch the etag
  anymore.  The md5 is still 0 and will be saved like that in the DB
- Next run, since the etags have  not changed on the server, we read
  from the DB.  But a md5 of 0 in the DB means the folder was removed on
  the server.  That would remove the local folder (BAD!)

So we load the md5 from the db even if the local mtime change.
That means we need to compare the mtime in the local case rather than
the md5 to see if something has changed.
This commit is contained in:
Olivier Goffart 2013-04-24 14:09:20 +02:00 committed by Klaas Freitag
parent b49aaaabfc
commit b1fc9b2a64
2 changed files with 4 additions and 2 deletions

View file

@ -661,10 +661,11 @@ char *csync_statedb_get_uniqId( CSYNC *ctx, uint64_t jHash, csync_vio_file_stat_
char *ret = NULL;
c_strlist_t *result = NULL;
char *stmt = NULL;
(void)buf;
if( ! csync_get_statedb_exists(ctx)) return ret;
stmt = sqlite3_mprintf("SELECT md5 FROM metadata WHERE phash='%lld' AND modtime=%lu", jHash, buf->mtime);
stmt = sqlite3_mprintf("SELECT md5 FROM metadata WHERE phash='%lld'", jHash);
result = csync_statedb_query(ctx, stmt);
sqlite3_free(stmt);

View file

@ -188,7 +188,8 @@ static int _csync_detect_update(CSYNC *ctx, const char *file,
st->instruction = CSYNC_INSTRUCTION_EVAL;
goto out;
}
if( !c_streq(fs->md5, tmp->md5 )) {
if((ctx->current == REMOTE_REPLICA && !c_streq(fs->md5, tmp->md5 ))
|| (ctx->current == LOCAL_REPLICA && fs->mtime != tmp->modtime)) {
// if (!fs->mtime > tmp->modtime) {
st->instruction = CSYNC_INSTRUCTION_EVAL;
goto out;