Rename 'md5' to 'etag'

'md5' always has been the etag. The name md5 for it is misleading.
It is still called "md5" in the database to keep compatibility
This commit is contained in:
Olivier Goffart 2013-11-13 14:29:31 +01:00
parent 3a1b868348
commit 908888a44e
11 changed files with 68 additions and 66 deletions

View file

@ -80,7 +80,7 @@ static void clean_caches() {
propfind_cache = NULL;
SAFE_FREE(_stat_cache.name);
SAFE_FREE(_stat_cache.md5 );
SAFE_FREE(_stat_cache.etag );
memset( _stat_cache.file_id, 0, FILE_ID_BUF_SIZE+1 );
SAFE_FREE(_id_cache.uri);
@ -766,7 +766,7 @@ static struct listdir_context *fetch_resource_list_attempts(const char *uri, int
static void fill_stat_cache( csync_vio_file_stat_t *lfs ) {
if( _stat_cache.name ) SAFE_FREE(_stat_cache.name);
if( _stat_cache.md5 ) SAFE_FREE(_stat_cache.md5 );
if( _stat_cache.etag ) SAFE_FREE(_stat_cache.etag );
if( !lfs) return;
@ -777,8 +777,8 @@ static void fill_stat_cache( csync_vio_file_stat_t *lfs ) {
_stat_cache.size = lfs->size;
csync_vio_file_stat_set_file_id(&_stat_cache, lfs->file_id);
if( lfs->md5 ) {
_stat_cache.md5 = c_strdup(lfs->md5);
if( lfs->etag ) {
_stat_cache.etag = c_strdup(lfs->etag);
}
}
@ -819,10 +819,10 @@ static int owncloud_stat(const char *uri, csync_vio_file_stat_t *buf) {
buf->mtime = _stat_cache.mtime;
buf->size = _stat_cache.size;
buf->mode = _stat_perms( _stat_cache.type );
buf->md5 = NULL;
if( _stat_cache.md5 ) {
buf->md5 = c_strdup( _stat_cache.md5 );
buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_MD5;
buf->etag = NULL;
if( _stat_cache.etag ) {
buf->etag = c_strdup( _stat_cache.etag );
buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_ETAG;
}
csync_vio_file_stat_set_file_id( buf, _stat_cache.file_id );
return 0;
@ -867,16 +867,16 @@ static int owncloud_stat(const char *uri, csync_vio_file_stat_t *buf) {
buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_SIZE;
buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_MTIME;
buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_PERMISSIONS;
buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_MD5;
buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_ETAG;
buf->fields = lfs->fields;
buf->type = lfs->type;
buf->mtime = lfs->mtime;
buf->size = lfs->size;
buf->mode = _stat_perms( lfs->type );
buf->md5 = NULL;
if( lfs->md5 ) {
buf->md5 = c_strdup( lfs->md5 );
buf->etag = NULL;
if( lfs->etag ) {
buf->etag = c_strdup( lfs->etag );
}
csync_vio_file_stat_set_file_id( buf, lfs->file_id );
@ -948,7 +948,7 @@ static const char* owncloud_get_etag( const char *path )
return NULL;
}
if( owncloud_stat( path, fs ) == 0 ) {
header = fs->md5;
header = fs->etag;
}
}

View file

@ -309,9 +309,9 @@ csync_vio_file_stat_t *resourceToFileStat( struct resource *res )
lfs->size = res->size;
lfs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_SIZE;
if( res->md5 ) {
lfs->md5 = c_strdup(res->md5);
lfs->etag = c_strdup(res->md5);
}
lfs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_MD5;
lfs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_ETAG;
csync_vio_file_stat_set_file_id(lfs, res->file_id);
return lfs;

View file

@ -552,16 +552,16 @@ static int _csync_treewalk_visitor(void *obj, void *data) {
trav.type = cur->type;
trav.instruction = cur->instruction;
trav.rename_path = cur->destpath;
trav.md5 = cur->md5;
trav.etag = cur->etag;
trav.file_id = cur->file_id;
trav.error_string = cur->error_string;
rc = (*visitor)(&trav, twctx->userdata);
cur->instruction = trav.instruction;
if (trav.md5 != cur->md5) {
SAFE_FREE(cur->md5);
cur->md5 = c_strdup(trav.md5);
if (trav.etag != cur->etag) {
SAFE_FREE(cur->etag);
cur->etag = c_strdup(trav.etag);
}
return rc;
}
@ -1030,7 +1030,7 @@ int csync_abort_requested(CSYNC *ctx)
void csync_file_stat_free(csync_file_stat_t *st)
{
if (st) {
SAFE_FREE(st->md5);
SAFE_FREE(st->etag);
SAFE_FREE(st->error_string);
SAFE_FREE(st->destpath);
SAFE_FREE(st);

View file

@ -193,7 +193,7 @@ struct csync_tree_walk_file_s {
enum csync_instructions_e instruction;
const char *rename_path;
const char *md5;
const char *etag;
const char *error_string;
const char *file_id;

View file

@ -68,7 +68,7 @@ csync_vio_method_handle_t *csync_dbtree_opendir(CSYNC *ctx, const char *name)
"mode INTEGER,"
"modtime INTEGER(8),"
"type INTEGER,"
"md5 VARCHAR(32),"
"md5 VARCHAR(32)," // That's the etag
*/
int col_count = 9;
@ -126,7 +126,7 @@ csync_vio_method_handle_t *csync_dbtree_opendir(CSYNC *ctx, const char *name)
if( cnt < tpath_len ) continue;
if (!list->vector[base+8][0])
continue; /* If md5 is empty, the file was removed on the server */
continue; /* If etag is empty, the file was removed on the server */
fs = csync_vio_file_stat_new();
fs->fields = CSYNC_VIO_FILE_STAT_FIELDS_NONE;
@ -178,8 +178,8 @@ csync_vio_method_handle_t *csync_dbtree_opendir(CSYNC *ctx, const char *name)
fs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_TYPE;
column = list->vector[base+8]; /* type */
fs->md5 = c_strdup(column);
fs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_MD5;
fs->etag = c_strdup(column);
fs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_ETAG;
/* store into result list. */
listing->list = c_list_append( listing->list, fs );

View file

@ -192,10 +192,10 @@ struct csync_file_stat_s {
int nlink; /* u32 */
int type; /* u32 */
int child_modified;/*bool*/
int should_update_md5; /*bool */
int should_update_etag; /*bool */
char *destpath; /* for renames */
const char *md5;
const char *etag;
char file_id[FILE_ID_BUF_SIZE+1]; /* the ownCloud file id is fixed width of 21 byte. */
const char *error_string;

View file

@ -154,7 +154,7 @@ static int _csync_merge_algorithm_visitor(void *obj, void *data) {
other->instruction = CSYNC_INSTRUCTION_SYNC;
}
SAFE_FREE(tmp->md5);
SAFE_FREE(tmp->etag);
SAFE_FREE(tmp);
}
@ -195,7 +195,7 @@ static int _csync_merge_algorithm_visitor(void *obj, void *data) {
cur->instruction = CSYNC_INSTRUCTION_UPDATED; /* update the DB */
other->instruction = CSYNC_INSTRUCTION_NONE;
if( !cur->md5 && other->md5 ) cur->md5 = c_strdup(other->md5);
if( !cur->etag && other->etag ) cur->etag = c_strdup(other->etag);
} else if(ctx->current == REMOTE_REPLICA) {
if(ctx->options.with_conflict_copys) {
cur->instruction = CSYNC_INSTRUCTION_CONFLICT;

View file

@ -392,7 +392,7 @@ csync_file_stat_t *csync_statedb_get_stat_by_hash(sqlite3 *db,
}
if(column_count > 9 && sqlite3_column_text(_by_hash_stmt, 9)) {
st->md5 = c_strdup( (char*) sqlite3_column_text(_by_hash_stmt, 9) );
st->etag = c_strdup( (char*) sqlite3_column_text(_by_hash_stmt, 9) );
}
}
} else {
@ -461,7 +461,7 @@ csync_file_stat_t *csync_statedb_get_stat_by_file_id( sqlite3 *db,
st->modtime = strtoul(result->vector[7], NULL, 10);
st->type = atoi(result->vector[8]);
if( result->vector[9] )
st->md5 = c_strdup(result->vector[9]);
st->etag = c_strdup(result->vector[9]);
csync_vio_set_file_id(st->file_id, file_id);
@ -516,7 +516,7 @@ csync_file_stat_t *csync_statedb_get_stat_by_inode(sqlite3 *db,
st->modtime = strtoul(result->vector[7], NULL, 10);
st->type = atoi(result->vector[8]);
if( result->vector[9] )
st->md5 = c_strdup(result->vector[9]);
st->etag = c_strdup(result->vector[9]);
csync_vio_set_file_id( st->file_id, result->vector[10]);
c_strlist_destroy(result);
@ -524,6 +524,8 @@ csync_file_stat_t *csync_statedb_get_stat_by_inode(sqlite3 *db,
return st;
}
/* Get the etag. (it is called unique id for legacy reason
* and it is the field md5 in the database for legacy reason */
char *csync_statedb_get_uniqId( CSYNC *ctx, uint64_t jHash, csync_vio_file_stat_t *buf ) {
char *ret = NULL;
c_strlist_t *result = NULL;

View file

@ -159,7 +159,7 @@ static int _csync_detect_update(CSYNC *ctx, const char *file,
/* Set instruction by default to none */
st->instruction = CSYNC_INSTRUCTION_NONE;
st->md5 = NULL;
st->etag = NULL;
st->child_modified = 0;
/* check hardlink count */
@ -207,13 +207,13 @@ static int _csync_detect_update(CSYNC *ctx, const char *file,
if(tmp && tmp->phash == h ) { /* there is an entry in the database */
/* we have an update! */
CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE, "Database entry found, compare: %" PRId64 " <-> %" PRId64 ", md5: %s <-> %s, inode: %" PRId64 " <-> %" PRId64,
((int64_t) fs->mtime), ((int64_t) tmp->modtime), fs->md5, tmp->md5, (uint64_t) fs->inode, (uint64_t) tmp->inode);
if( !fs->md5) {
CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE, "Database entry found, compare: %" PRId64 " <-> %" PRId64 ", etag: %s <-> %s, inode: %" PRId64 " <-> %" PRId64,
((int64_t) fs->mtime), ((int64_t) tmp->modtime), fs->etag, tmp->etag, (uint64_t) fs->inode, (uint64_t) tmp->inode);
if( !fs->etag) {
st->instruction = CSYNC_INSTRUCTION_EVAL;
goto out;
}
if((ctx->current == REMOTE_REPLICA && !c_streq(fs->md5, tmp->md5 ))
if((ctx->current == REMOTE_REPLICA && !c_streq(fs->etag, tmp->etag ))
|| (ctx->current == LOCAL_REPLICA && (fs->mtime != tmp->modtime
#if 0
|| fs->inode != tmp->inode
@ -266,7 +266,7 @@ static int _csync_detect_update(CSYNC *ctx, const char *file,
if (fs->type == CSYNC_VIO_FILE_TYPE_DIRECTORY) {
csync_rename_record(ctx, tmp->path, path);
} else {
if( !c_streq(tmp->md5, fs->md5) ) {
if( !c_streq(tmp->etag, fs->etag) ) {
/* CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "ETags are different!"); */
/* File with different etag, don't do a rename, but download the file again */
st->instruction = CSYNC_INSTRUCTION_NEW;
@ -310,9 +310,9 @@ out:
st->gid = fs->gid;
st->nlink = fs->nlink;
st->type = type;
st->md5 = NULL;
if( fs->md5 ) {
st->md5 = c_strdup(fs->md5);
st->etag = NULL;
if( fs->etag ) {
st->etag = c_strdup(fs->etag);
}
csync_vio_set_file_id(st->file_id, fs->file_id);
@ -410,8 +410,8 @@ static int _check_read_from_db(CSYNC *ctx, const char *uri) {
int len;
uint64_t h;
csync_vio_file_stat_t *fs = NULL;
const char *md5_local = NULL;
const char *md5_remote = NULL;
const char *etag_local = NULL;
const char *etag_remote = NULL;
const char *mpath;
int rc = 0; /* FIXME: Error handling! */
csync_file_stat_t* tmp = NULL;
@ -433,20 +433,20 @@ static int _check_read_from_db(CSYNC *ctx, const char *uri) {
len = strlen( mpath );
h = c_jhash64((uint8_t *) mpath, len, 0);
/* search that folder in the db and check that the hash is the md5 (etag) is still the same */
/* search that folder in the db and check that the hash is the etag (etag) is still the same */
if( csync_get_statedb_exists(ctx) ) {
tmp = csync_statedb_get_stat_by_hash(ctx->statedb.db, h);
if (tmp) {
md5_local = tmp->md5;
md5_remote = csync_vio_get_etag(ctx, uri);
etag_local = tmp->etag;
etag_remote = csync_vio_get_etag(ctx, uri);
CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "Compare directory ids for %s: %s -> %s", mpath, md5_local, md5_remote );
CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "Compare directory ids for %s: %s -> %s", mpath, etag_local, etag_remote );
if( c_streq(md5_local, md5_remote) ) {
if( c_streq(etag_local, etag_remote) ) {
ctx->remote.read_from_db = 1;
}
SAFE_FREE(md5_remote);
SAFE_FREE(md5_local);
SAFE_FREE(etag_remote);
SAFE_FREE(etag_local);
SAFE_FREE(tmp);
}
}
@ -478,7 +478,7 @@ int csync_ftw(CSYNC *ctx, const char *uri, csync_walker_fn fn,
goto error;
}
/* If remote, compare the id with the local id. If equal, read all contents from
/* If remote, compare the etag with the local etag. If equal, read all contents from
* the database. */
read_from_db = ctx->remote.read_from_db;
CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE, " => Starting to ftw %s, read_from_db-Flag for: %d",
@ -603,19 +603,19 @@ int csync_ftw(CSYNC *ctx, const char *uri, csync_walker_fn fn,
}
if( ctx->current == LOCAL_REPLICA ) {
char *md5 = NULL;
char *etag = NULL;
int len = strlen( path );
uint64_t h = c_jhash64((uint8_t *) path, len, 0);
md5 = csync_statedb_get_uniqId( ctx, h, fs );
if( md5 ) {
SAFE_FREE(fs->md5);
fs->md5 = md5;
fs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_MD5;
etag = csync_statedb_get_uniqId( ctx, h, fs );
if( etag ) {
SAFE_FREE(fs->etag);
fs->etag = etag;
fs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_ETAG;
}
if( c_streq(md5, "")) {
if( c_streq(etag, "")) {
CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "Uniq ID from Database is EMPTY: %s", path);
} else {
CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "Uniq ID from Database: %s -> %s", path, fs->md5 ? fs->md5 : "<NULL>" );
CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "Uniq ID from Database: %s -> %s", path, fs->etag ? fs->etag : "<NULL>" );
}
}
@ -631,7 +631,7 @@ int csync_ftw(CSYNC *ctx, const char *uri, csync_walker_fn fn,
if( ! do_read_from_db ) {
csync_vio_file_stat_destroy(fs);
} else {
SAFE_FREE(fs->md5);
SAFE_FREE(fs->etag);
}
if (rc < 0) {
@ -655,7 +655,7 @@ int csync_ftw(CSYNC *ctx, const char *uri, csync_walker_fn fn,
if (ctx->current_fs && !ctx->current_fs->child_modified
&& ctx->current_fs->instruction == CSYNC_INSTRUCTION_EVAL) {
ctx->current_fs->instruction = CSYNC_INSTRUCTION_NONE;
ctx->current_fs->should_update_md5 = true;
ctx->current_fs->should_update_etag = true;
}
}
ctx->current_fs = previous_fs;

View file

@ -28,7 +28,7 @@ csync_vio_file_stat_t *csync_vio_file_stat_new(void) {
if (file_stat == NULL) {
return NULL;
}
file_stat->md5 = NULL;
file_stat->etag = NULL;
memset(file_stat->file_id, 0, FILE_ID_BUF_SIZE+1);
return file_stat;
}
@ -45,8 +45,8 @@ void csync_vio_file_stat_destroy(csync_vio_file_stat_t *file_stat) {
if (file_stat->fields & CSYNC_VIO_FILE_STAT_FIELDS_CHECKSUM) {
SAFE_FREE(file_stat->u.checksum);
}
if (file_stat->fields & CSYNC_VIO_FILE_STAT_FIELDS_MD5) {
SAFE_FREE(file_stat->md5);
if (file_stat->fields & CSYNC_VIO_FILE_STAT_FIELDS_ETAG) {
SAFE_FREE(file_stat->etag);
}
SAFE_FREE(file_stat->name);
SAFE_FREE(file_stat);

View file

@ -73,7 +73,7 @@ enum csync_vio_file_stat_fields_e {
CSYNC_VIO_FILE_STAT_FIELDS_ACL = 1 << 14,
CSYNC_VIO_FILE_STAT_FIELDS_UID = 1 << 15,
CSYNC_VIO_FILE_STAT_FIELDS_GID = 1 << 16,
CSYNC_VIO_FILE_STAT_FIELDS_MD5 = 1 << 17,
CSYNC_VIO_FILE_STAT_FIELDS_ETAG = 1 << 17,
CSYNC_VIO_FILE_STAT_FIELDS_FILE_ID = 1 << 18
};
@ -86,7 +86,7 @@ struct csync_vio_file_stat_s {
void *acl;
char *name;
char *md5;
char *etag;
char file_id[FILE_ID_BUF_SIZE+1];
uid_t uid;