ownCloud: Don't require time sync between server and client.

This commit is contained in:
Klaas Freitag 2012-07-04 16:32:17 +02:00
parent 6eb4e707d9
commit de209ecdb9
4 changed files with 45 additions and 24 deletions

View file

@ -553,7 +553,7 @@ static int fetch_resource_list( const char *curi,
dav_session.time_delta = time_diff;
/* DEBUG_WEBDAV("%d <0> %d", server_time, now); */
dav_session.time_delta = time_diff;
}
ne_propfind_destroy(hdl);
@ -594,7 +594,7 @@ static csync_vio_file_stat_t *resourceToFileStat( struct resource *res )
DEBUG_WEBDAV("WRN: Delta time not yet computed.");
lfs->mtime = res->modtime;
} else {
lfs->mtime = res->modtime + dav_session.time_delta;
lfs->mtime = res->modtime - dav_session.time_delta;
}
lfs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_MTIME;
lfs->size = res->size;
@ -897,13 +897,18 @@ static void install_content_reader( ne_request *req, void *userdata, const ne_st
static char*_lastDir = NULL;
/* capabilities are currently:
* bool atomar_copy_support
* bool do_post_copy_stat
* bool atomar_copy_support - oC provides atomar copy
* bool do_post_copy_stat - oC does not want the post copy check
* bool time_sync_required - oC does not require the time sync
* int unix_extensions - oC supports unix extensions.
*/
static csync_vio_capabilities_t _owncloud_capabilities = { true, false };
static csync_vio_capabilities_t _owncloud_capabilities = { true, false, false, 1 };
static csync_vio_capabilities_t *owncloud_get_capabilities(void)
{
#ifdef _WIN32
_owncloud_capabilities.unix_extensions = 0;
#endif
return &_owncloud_capabilities;
}
@ -1520,6 +1525,8 @@ static int owncloud_utimes(const char *uri, const struct timeval *times) {
int rc = NE_OK;
char val[255];
char *curi = NULL;
const struct timeval *modtime = times+1;
long newmodtime;
curi = _cleanPath( uri );
@ -1534,7 +1541,10 @@ static int owncloud_utimes(const char *uri, const struct timeval *times) {
pname.nspace = NULL;
pname.name = "lastmodified";
snprintf( val, sizeof(val), "%ld", times->tv_sec );
newmodtime = modtime->tv_sec;
newmodtime += dav_session.time_delta;
snprintf( val, sizeof(val), "%ld", newmodtime );
DEBUG_WEBDAV("Setting LastModified of %s to %s", curi, val );
ops[0].name = &pname;

View file

@ -315,28 +315,34 @@ retry_vio_init:
}
if( !ctx->options.local_only_mode ) {
if(ctx->module.capabilities.time_sync_required) {
timediff = csync_timediff(ctx);
if (timediff > ctx->options.max_time_difference) {
CSYNC_LOG(CSYNC_LOG_PRIORITY_FATAL,
"Clock skew detected. The time difference is greater than %d seconds!",
ctx->options.max_time_difference);
ctx->error_code = CSYNC_ERR_TIMESKEW;
rc = -1;
goto out;
CSYNC_LOG(CSYNC_LOG_PRIORITY_FATAL,
"Clock skew detected. The time difference is greater than %d seconds!",
ctx->options.max_time_difference);
ctx->error_code = CSYNC_ERR_TIMESKEW;
rc = -1;
goto out;
} else if (timediff < 0) {
/* error code was set in csync_timediff() */
CSYNC_LOG(CSYNC_LOG_PRIORITY_FATAL, "Synchronisation is not possible!");
ctx->error_code = CSYNC_ERR_TIMESKEW;
rc = -1;
goto out;
/* error code was set in csync_timediff() */
CSYNC_LOG(CSYNC_LOG_PRIORITY_FATAL, "Synchronisation is not possible!");
ctx->error_code = CSYNC_ERR_TIMESKEW;
rc = -1;
goto out;
}
}
if(ctx->module.capabilities.unix_extensions == -1) { /* detect */
if (csync_unix_extensions(ctx) < 0) {
CSYNC_LOG(CSYNC_LOG_PRIORITY_FATAL, "Could not detect filesystem type.");
ctx->error_code = CSYNC_ERR_FILESYSTEM;
rc = -1;
goto out;
CSYNC_LOG(CSYNC_LOG_PRIORITY_FATAL, "Could not detect filesystem type.");
ctx->error_code = CSYNC_ERR_FILESYSTEM;
rc = -1;
goto out;
}
} else {
/* The module specifies the value for the unix_extensions. */
ctx->options.unix_extensions = ctx->module.capabilities.unix_extensions;
}
}
if (c_rbtree_create(&ctx->local.tree, _key_cmp, _data_cmp) < 0) {

View file

@ -131,6 +131,8 @@ int csync_vio_init(CSYNC *ctx, const char *module, const char *args) {
/* Useful defaults to the module capabilities */
ctx->module.capabilities.atomar_copy_support = false;
ctx->module.capabilities.do_post_copy_stat = true;
ctx->module.capabilities.time_sync_required = true;
ctx->module.capabilities.unix_extensions = -1; /* detect automatically */
/* Load the module capabilities from the module if it implements the it. */
if( VIO_METHOD_HAS_FUNC(m, get_capabilities)) {

View file

@ -38,8 +38,11 @@ typedef struct csync_vio_method_s csync_vio_method_t;
/* module capabilities definition.
* remember to set useful defaults in csync_vio.c if you add something here. */
struct csync_vio_capabilities_s {
bool atomar_copy_support;
bool do_post_copy_stat;
bool atomar_copy_support; /* set to true if the backend provides atomar copy */
bool do_post_copy_stat; /* true if csync should check the copy afterwards */
bool time_sync_required; /* true if local and remote need to be time synced */
int unix_extensions; /* -1: do csync detection, 0: no unix extensions,
1: extensions available */
};
typedef struct csync_vio_capabilities_s csync_vio_capabilities_t;