[-]
[+]
|
Added |
ocsync.changes
|
|
[-]
[+]
|
Changed |
ocsync.spec
^
|
|
[-]
[+]
|
Changed |
ocsync-0.70.7.tar.bz2/.tag
^
|
@@ -1 +1 @@
-b216b9f5465d2ac11163022fabd7cf1efcd6cdd4
+317b3149f31e4a8a780b6e47545a5e3ce7b009b0
|
[-]
[+]
|
Changed |
ocsync-0.70.7.tar.bz2/CMakeLists.txt
^
|
@@ -8,7 +8,7 @@
set(APPLICATION_VERSION_MAJOR "0")
set(APPLICATION_VERSION_MINOR "70")
-set(APPLICATION_VERSION_PATCH "4")
+set(APPLICATION_VERSION_PATCH "7")
set(APPLICATION_VERSION "${APPLICATION_VERSION_MAJOR}.${APPLICATION_VERSION_MINOR}.${APPLICATION_VERSION_PATCH}")
|
[-]
[+]
|
Changed |
ocsync-0.70.7.tar.bz2/CPackConfig.cmake
^
|
@@ -13,7 +13,7 @@
### versions
set(CPACK_PACKAGE_VERSION_MAJOR "0")
set(CPACK_PACKAGE_VERSION_MINOR "70")
-set(CPACK_PACKAGE_VERSION_PATCH "4")
+set(CPACK_PACKAGE_VERSION_PATCH "6")
set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
set(CPACK_GENERATOR "TGZ")
|
[-]
[+]
|
Changed |
ocsync-0.70.7.tar.bz2/ChangeLog
^
|
@@ -1,5 +1,38 @@
ChangeLog
==========
+
+version 0.70.7 (released 2013-04-23)
+ * [Fixes] Resource exhaustion
+ * Better logging of statedb-related errors
+
+version 0.70.6 (released 2013-04-11)
+ * [Fixes] Try to avoid to upload incomplete files
+ * [Fixes] Increase read timeout to 300 seconds
+ * [Fixes] Handle IGNORE status correctly
+ * [Fixes] Set path and phash for ignored files
+ * [Fixes] Fix some issues discovered by Coverity
+ * [Fixes] Make sure to never allow empty pathes in rmdir
+ * [Fixes] Fix a crash caused by superfluous free() calls
+
+version 0.70.5 (released 2013-04-02)
+ * detect 'wrong' conflict files on client side.
+ * [Fixes] Give context to module to enable logging (cmd client).
+ * [Fixes] Fix version table contents.
+ * [Fixes] Fix handling of non statable files on Win32.
+ * [Fixes] Fix renames on clientside on read only shares.
+ * [Fixes] Various small fixes and improvements.
+
+version 0.70.4 (released 2013-02-26)
+ * [Win32] Ship with upto-date openssl version to fix SSL problems we saw.
+ * [Fixes] Fix crash during mkdir.
+ * [Fixes] Added workaround for problem that server sometimes does
+ not respond properly to PROPFIND (mirall#285)
+ * [Fixes] Fix handling of deletion of non empty or locked
+ directories.
+ * [Fixes] Fixed some potential memory leaks.
+ * [Fixes] Files with filenames with unix extensions
+ are ignored now.
+
version 0.70.3 (released 2013-01-24)
* [Platform] Fix session cookie extraction (mirall bug #260).
|
[-]
[+]
|
Changed |
ocsync-0.70.7.tar.bz2/client/csync_client.c
^
|
@@ -47,7 +47,7 @@
csync -- a user level file synchronizer which synchronizes the files\n\
at LOCAL with the ones at REMOTE.\n\
\n\
--c, --conflict-copys Create conflict copys if file changed on both\n\
+-c, --conflict-copies Create conflict copys if file changed on both\n\
sides.\n\
-d, --debug-level=DEBUGLVL Set debug level\n\
--disable-statedb Disable the usage and creation of a statedb.\n\
|
[-]
[+]
|
Changed |
ocsync-0.70.7.tar.bz2/modules/csync_owncloud.c
^
|
@@ -746,7 +746,7 @@
}
if (dav_session.read_timeout == 0)
- dav_session.read_timeout = 30; // Default from old code
+ dav_session.read_timeout = 300; // set 300 seconds as default.
ne_set_read_timeout(dav_session.ctx, dav_session.read_timeout);
@@ -1004,7 +1004,7 @@
if( ret == NE_OK ) {
fetchCtx->currResource = fetchCtx->list;
/* Check the request status. */
- if( req_status->klass != 2 ) {
+ if( req_status && req_status->klass != 2 ) {
set_errno_from_http_errcode(req_status->code);
DEBUG_WEBDAV("ERROR: Request failed: status %d (%s)", req_status->code,
req_status->reason_phrase);
@@ -1896,6 +1896,10 @@
int rc = NE_OK;
char* curi = _cleanPath( uri );
+ if( curi == NULL ) {
+ DEBUG_WEBDAV("Can not clean path for %s, bailing out.", uri ? uri:"<empty>");
+ return -1;
+ }
rc = dav_connect(uri);
if (rc < 0) {
errno = EINVAL;
@@ -2026,8 +2030,10 @@
SAFE_FREE(curi);
if( rc != NE_OK ) {
+ const char *err = ne_get_error(dav_session.ctx);
set_errno_from_neon_errcode(rc);
- DEBUG_WEBDAV("Error in propatch: %d", rc);
+
+ DEBUG_WEBDAV("Error in propatch: %s", err == NULL ? "<empty err msg.>" : err);
return -1;
}
|
[-]
[+]
|
Changed |
ocsync-0.70.7.tar.bz2/src/csync.c
^
|
@@ -349,6 +349,8 @@
ctx->status = CSYNC_STATUS_INIT;
+ csync_set_module_property(ctx, "csync_context", ctx);
+
/* initialize random generator */
srand(time(NULL));
@@ -566,8 +568,11 @@
cur = (csync_file_stat_t *) obj;
ctx = (CSYNC *) data;
+ if (ctx == NULL) {
+ return -1;
+ }
- if (!(ctx && obj && data)) {
+ if (obj == NULL || data == NULL) {
ctx->error_code = CSYNC_ERR_PARAM;
return -1;
}
@@ -1053,10 +1058,14 @@
int csync_set_progress_callback(CSYNC* ctx, csync_progress_callback cb)
{
- if (ctx == NULL || cb == NULL) {
+ if (ctx == NULL) {
+ return -1;
+ }
+ if (cb == NULL ) {
ctx->error_code = CSYNC_ERR_PARAM;
return -1;
}
+
ctx->error_code = CSYNC_ERR_NONE;
ctx->callbacks.progresscb = cb;
|
[-]
[+]
|
Changed |
ocsync-0.70.7.tar.bz2/src/csync.h
^
|
@@ -51,7 +51,7 @@
/* csync version */
#define LIBCSYNC_VERSION_MAJOR 0
#define LIBCSYNC_VERSION_MINOR 70
-#define LIBCSYNC_VERSION_MICRO 4
+#define LIBCSYNC_VERSION_MICRO 6
#define LIBCSYNC_VERSION_INT CSYNC_VERSION_INT(LIBCSYNC_VERSION_MAJOR, \
LIBCSYNC_VERSION_MINOR, \
@@ -129,7 +129,8 @@
enum csync_ftw_type_e {
CSYNC_FTW_TYPE_FILE,
CSYNC_FTW_TYPE_SLINK,
- CSYNC_FTW_TYPE_DIR
+ CSYNC_FTW_TYPE_DIR,
+ CSYNC_FTW_TYPE_SKIP
};
|
[-]
[+]
|
Changed |
ocsync-0.70.7.tar.bz2/src/csync_exclude.c
^
|
@@ -73,7 +73,7 @@
fd = _topen(wfname, O_RDONLY);
c_free_multibyte(wfname);
- if ( !fd ) {
+ if ( fd < 0 ) {
return -1;
}
|
[-]
[+]
|
Changed |
ocsync-0.70.7.tar.bz2/src/csync_misc.c
^
|
@@ -27,6 +27,7 @@
#include <limits.h>
#include <string.h>
#include <stdlib.h>
+#include <stdio.h>
#include <sys/types.h>
#include <errno.h>
@@ -47,7 +48,7 @@
#ifdef _WIN32
char *csync_get_user_home_dir(void) {
wchar_t tmp[MAX_PATH];
- const char *szPath = NULL;
+ char *szPath = NULL;
if( SHGetFolderPathW( NULL,
CSIDL_PROFILE|CSIDL_FLAG_CREATE,
@@ -87,24 +88,28 @@
#endif /* NSS_BUFLEN_PASSWD */
char *csync_get_user_home_dir(void) {
- char *szPath = NULL;
+ char home[PATH_MAX] = {0};
+ const char *envp;
struct passwd pwd;
struct passwd *pwdbuf;
char buf[NSS_BUFLEN_PASSWD];
int rc;
- szPath = getenv("HOME");
- if( szPath ) {
- return c_strdup(szPath);
+ envp = getenv("HOME");
+ if (envp != NULL) {
+ snprintf(home, sizeof(home), "%s", envp);
+ if (home[0] != '\0') {
+ return c_strdup(home);
+ }
}
/* Still nothing found, read the password file */
rc = getpwuid_r(getuid(), &pwd, buf, NSS_BUFLEN_PASSWD, &pwdbuf);
if (rc != 0) {
- szPath = c_strdup(pwd.pw_dir);
+ return c_strdup(pwd.pw_dir);
}
- return szPath;
+ return NULL;
}
char *csync_get_local_username(void) {
|
[-]
[+]
|
Changed |
ocsync-0.70.7.tar.bz2/src/csync_propagate.c
^
|
@@ -32,6 +32,8 @@
#include "csync_private.h"
#include "csync_propagate.h"
+#include "csync_statedb.h"
+#include "vio/csync_vio_local.h"
#include "vio/csync_vio.h"
#include "c_jhash.h"
@@ -120,6 +122,7 @@
csync_vio_handle_t *dfp = NULL;
csync_vio_file_stat_t *tstat = NULL;
+ csync_vio_file_stat_t *vst = NULL;
char errbuf[256] = {0};
char buf[MAX_XFER_BUF_SIZE] = {0};
@@ -130,6 +133,7 @@
int rc = -1;
int count = 0;
int flags = 0;
+ bool do_pre_copy_stat = false; /* do an additional stat before actually copying */
rep_bak = ctx->replica;
@@ -145,6 +149,7 @@
rc = -1;
goto out;
}
+ do_pre_copy_stat = true;
break;
case REMOTE_REPLICA:
srep = ctx->remote.type;
@@ -162,6 +167,27 @@
break;
}
+ /* Check if the file is still untouched since the update run. */
+ if (do_pre_copy_stat) {
+ vst = csync_vio_file_stat_new();
+ if (csync_vio_stat(ctx, suri, vst) < 0) {
+ /* Pre copy stat failed */
+ rc = 1;
+ goto out;
+ } else {
+ /* Pre copy stat succeeded */
+ if (st->modtime != vst->mtime ||
+ st->size != vst->size) {
+ /* The size or modtime has changed. Skip this file copy for now. */
+ rc = 1; /* soft problem */
+ CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG,
+ "Source file has changed since update run, SKIP it for now.");
+ goto out;
+ }
+ csync_vio_file_stat_destroy(vst);
+ }
+ }
+
/* Open the source file */
ctx->replica = srep;
flags = O_RDONLY|O_NOFOLLOW;
@@ -572,12 +598,11 @@
}
-static int _csync_backup_file(CSYNC *ctx, csync_file_stat_t *st) {
+static int _csync_backup_file(CSYNC *ctx, csync_file_stat_t *st, char **duri) {
enum csync_replica_e drep = -1;
enum csync_replica_e rep_bak = -1;
char *suri = NULL;
- char *duri = NULL;
char errbuf[256] = {0};
@@ -596,7 +621,7 @@
goto out;
}
- if (_backup_path(ctx, &duri, ctx->remote.uri,st->path) < 0) {
+ if (_backup_path(ctx, duri, ctx->remote.uri,st->path) < 0) {
rc = -1;
goto out;
}
@@ -608,7 +633,7 @@
goto out;
}
- if ( _backup_path(ctx, &duri, ctx->local.uri, st->path) < 0) {
+ if ( _backup_path(ctx, duri, ctx->local.uri, st->path) < 0) {
rc = -1;
goto out;
}
@@ -626,12 +651,12 @@
}
CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE,"suri: %s",suri);
- CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE,"duri: %s",duri);
+ CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE,"duri: %s",*duri);
/* rename the older file to conflict */
ctx->replica = drep;
- if (csync_vio_rename(ctx, suri, duri) < 0) {
+ if (csync_vio_rename(ctx, suri, *duri) < 0) {
switch (errno) {
case ENOMEM:
rc = -1;
@@ -643,7 +668,7 @@
strerror_r(errno, errbuf, sizeof(errbuf));
CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR,
"file: %s, command: rename, error: %s",
- duri,
+ *duri,
errbuf);
goto out;
}
@@ -652,7 +677,7 @@
/* set instruction for the statedb merger */
st->instruction = CSYNC_INSTRUCTION_NONE;
- CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "BACKUP file: %s", duri);
+ CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "BACKUP file: %s", *duri);
rc = 0;
@@ -663,7 +688,6 @@
}
SAFE_FREE(suri);
- SAFE_FREE(duri);
ctx->replica = rep_bak;
@@ -719,7 +743,7 @@
"dir: %s, command: rename, error: %s",
suri,
errbuf);
- rc = -1;
+ rc = 1;
break;
}
goto out;
@@ -789,14 +813,35 @@
static int _csync_conflict_file(CSYNC *ctx, csync_file_stat_t *st) {
int rc = -1;
-
- rc = _csync_backup_file(ctx, st);
+ char *conflict_file_name;
+ char *uri = NULL;
+
+ rc = _csync_backup_file(ctx, st, &conflict_file_name);
if(rc>=0)
{
rc = _csync_push_file(ctx, st);
}
+ if( rc >= 0 ) {
+ /* if its the local repository, check if both files are equal. */
+ if( ctx->current == REMOTE_REPLICA ) {
+ if (asprintf(&uri, "%s/%s", ctx->local.uri, st->path) < 0) {
+ return -1;
+ }
+
+ if( c_compare_file(uri, conflict_file_name) == 1 ) {
+ /* the files are byte wise equal. The conflict can be erased. */
+ if (csync_vio_local_unlink(conflict_file_name) < 0) {
+ CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "REMOVE of csync conflict file %s failed.", conflict_file_name );
+ } else {
+ CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "REMOVED csync conflict file %s as files are equal.",
+ conflict_file_name );
+ }
+ }
+ }
+ }
+
return rc;
}
|
[-]
[+]
|
Changed |
ocsync-0.70.7.tar.bz2/src/csync_reconcile.c
^
|
@@ -233,6 +233,9 @@
case CSYNC_INSTRUCTION_NONE:
cur->instruction = CSYNC_INSTRUCTION_SYNC;
break;
+ case CSYNC_INSTRUCTION_IGNORE:
+ cur->instruction = CSYNC_INSTRUCTION_IGNORE;
+ break;
default:
break;
}
|
[-]
[+]
|
Changed |
ocsync-0.70.7.tar.bz2/src/csync_statedb.c
^
|
@@ -119,7 +119,7 @@
_csync_win32_hide_file(statedb);
return 0;
}
- CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, "%s %s", sqlite3_errmsg(db), statedb);
+ CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, "sqlite3_open failed: %s %s", sqlite3_errmsg(db), statedb);
sqlite3_close(db);
return -1;
@@ -188,6 +188,8 @@
* its not there.
*/
if (_csync_statedb_check(ctx, statedb) < 0) {
+ CSYNC_LOG(CSYNC_LOG_PRIORITY_NOTICE, "ERR: checking csync database failed - bail out.");
+
rc = -1;
goto out;
}
@@ -199,19 +201,27 @@
* statedb.
*/
if (asprintf(&statedb_tmp, "%s.ctmp", statedb) < 0) {
+ CSYNC_LOG(CSYNC_LOG_PRIORITY_NOTICE, "ERR: could not create statedb name - bail out.");
+
rc = -1;
goto out;
}
if (c_copy(statedb, statedb_tmp, 0644) < 0) {
+ CSYNC_LOG(CSYNC_LOG_PRIORITY_NOTICE, "ERR: Failed to copy statedb -> statedb_tmp - bail out.");
+
rc = -1;
goto out;
}
_csync_win32_hide_file( statedb_tmp );
- /* Open the temporary database */
+ /* Open or create the temporary database */
if (sqlite3_open(statedb_tmp, &ctx->statedb.db) != SQLITE_OK) {
+ const char *errmsg= sqlite3_errmsg(ctx->statedb.db);
+ CSYNC_LOG(CSYNC_LOG_PRIORITY_NOTICE, "ERR: Failed to sqlite3 open statedb - bail out: %s.",
+ errmsg ? errmsg : "<no sqlite3 errormsg>");
+
rc = -1;
goto out;
}
@@ -384,6 +394,14 @@
);
if (result == NULL) {
return -1;
+ }
+ c_strlist_destroy(result);
+
+ result = csync_statedb_query(ctx,
+ "DROP TABLE IF EXISTS version;"
+ );
+ if (result == NULL) {
+ return -1;
}
c_strlist_destroy(result);
|
[-]
[+]
|
Changed |
ocsync-0.70.7.tar.bz2/src/csync_update.c
^
|
@@ -42,6 +42,40 @@
#define CSYNC_LOG_CATEGORY_NAME "csync.updater"
#include "csync_log.h"
+/* calculate the hash of a given uri */
+static uint64_t _hash_of_file(CSYNC *ctx, const char *file) {
+ const char *path;
+ int len;
+ uint64_t h = 0;
+
+ if( ctx && file ) {
+ path = file;
+ switch (ctx->current) {
+ case LOCAL_REPLICA:
+ if (strlen(path) <= strlen(ctx->local.uri)) {
+ return 0;
+ }
+ path += strlen(ctx->local.uri) + 1;
+ break;
+ case REMOTE_REPLICA:
+ if (strlen(path) <= strlen(ctx->remote.uri)) {
+ return 0;
+ }
+ path += strlen(ctx->remote.uri) + 1;
+ break;
+ default:
+ path = NULL;
+ return 0;
+ break;
+ }
+ len = strlen(path);
+
+ h = c_jhash64((uint8_t *) path, len, 0);
+ }
+ return h;
+}
+
+
static int _csync_detect_update(CSYNC *ctx, const char *file,
const csync_vio_file_stat_t *fs, const int type) {
uint64_t h = 0;
@@ -58,26 +92,30 @@
path = file;
switch (ctx->current) {
- case LOCAL_REPLICA:
- if (strlen(path) <= strlen(ctx->local.uri)) {
- return -1;
- }
- path += strlen(ctx->local.uri) + 1;
- break;
- case REMOTE_REPLICA:
- if (strlen(path) <= strlen(ctx->remote.uri)) {
- return -1;
- }
- path += strlen(ctx->remote.uri) + 1;
- break;
- default:
- path = NULL;
+ case LOCAL_REPLICA:
+ if (strlen(path) <= strlen(ctx->local.uri)) {
return -1;
- break;
+ }
+ path += strlen(ctx->local.uri) + 1;
+ break;
+ case REMOTE_REPLICA:
+ if (strlen(path) <= strlen(ctx->remote.uri)) {
+ return -1;
+ }
+ path += strlen(ctx->remote.uri) + 1;
+ break;
+ default:
+ path = NULL;
+ return -1;
+ break;
+ }
+
+ h = _hash_of_file(ctx, file );
+ if( h == 0 ) {
+ return -1;
}
len = strlen(path);
- h = c_jhash64((uint8_t *) path, len, 0);
size = sizeof(csync_file_stat_t) + len + 1;
st = c_malloc(size);
@@ -92,9 +130,28 @@
st->md5 = NULL;
/* check hardlink count */
- if (type == CSYNC_FTW_TYPE_FILE && fs->nlink > 1) {
- st->instruction = CSYNC_INSTRUCTION_IGNORE;
- goto out;
+ if (type == CSYNC_FTW_TYPE_FILE ) {
+ if( fs->nlink > 1) {
+ st->instruction = CSYNC_INSTRUCTION_IGNORE;
+ goto out;
+ }
+
+ if (fs->mtime == 0) {
+ tmp = csync_statedb_get_stat_by_hash(ctx, h);
+ CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE, "file: %s - mtime is zero!", path);
+ if (tmp == NULL) {
+ CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE, "file: %s - not found in db, IGNORE!", path);
+ st->instruction = CSYNC_INSTRUCTION_IGNORE;
+ } else {
+ SAFE_FREE(st);
+ st = tmp;
+ st->instruction = CSYNC_INSTRUCTION_NONE;
+ CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE, "file: %s - tmp non zero, mtime %llu", path, st->modtime );
+ tmp = NULL;
+ }
+ goto fastout; /* Skip copying of the etag. That's an important difference to upstream
+ * without etags. */
+ }
}
/* Update detection: Check if a database entry exists.
@@ -146,7 +203,7 @@
}
}
/* directory, remote and file not found in statedb */
- st->instruction = CSYNC_INSTRUCTION_NEW;
+ st->instruction = CSYNC_INSTRUCTION_NEW;
}
} else {
st->instruction = CSYNC_INSTRUCTION_NEW;
@@ -156,17 +213,19 @@
if( tmp) SAFE_FREE(tmp->md5);
SAFE_FREE(tmp);
st->inode = fs->inode;
- st->mode = fs->mode;
- st->size = fs->size;
+ st->mode = fs->mode;
+ st->size = fs->size;
st->modtime = fs->mtime;
- st->uid = fs->uid;
- st->gid = fs->gid;
+ st->uid = fs->uid;
+ st->gid = fs->gid;
st->nlink = fs->nlink;
- st->type = type;
- st->md5 = NULL;
+ st->type = type;
+ st->md5 = NULL;
if( fs->md5 ) {
st->md5 = c_strdup(fs->md5);
}
+
+fastout: /* target if the file information is read from database into st */
st->phash = h;
st->pathlen = len;
memcpy(st->path, (len ? path : ""), len + 1);
@@ -195,36 +254,37 @@
int csync_walker(CSYNC *ctx, const char *file, const csync_vio_file_stat_t *fs,
enum csync_ftw_flags_e flag) {
- switch (flag) {
- case CSYNC_FTW_FLAG_FILE:
- CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE, "file: %s", file);
-
- return _csync_detect_update(ctx, file, fs, CSYNC_FTW_TYPE_FILE);
- break;
- case CSYNC_FTW_FLAG_SLINK:
- /* FIXME: implement support for symlinks, see csync_propagate.c too */
-#if 0
- if (ctx->options.sync_symbolic_links) {
- CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE, "symlink: %s", file);
-
- return _csync_detect_update(ctx, file, fs, CSYNC_FTW_TYPE_SLINK);
- }
-#endif
- break;
- case CSYNC_FTW_FLAG_DIR: /* enter directory */
- CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE, "directory: %s", file);
+ int rc = -1;
+ int type = CSYNC_FTW_TYPE_SKIP;
- return _csync_detect_update(ctx, file, fs, CSYNC_FTW_TYPE_DIR);
- case CSYNC_FTW_FLAG_NSTAT: /* not statable file */
- case CSYNC_FTW_FLAG_DNR:
- case CSYNC_FTW_FLAG_DP:
- case CSYNC_FTW_FLAG_SLN:
- break;
- default:
- break;
+ switch (flag) {
+ case CSYNC_FTW_FLAG_FILE:
+ CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE, "file: %s", file);
+ type = CSYNC_FTW_TYPE_FILE;
+ break;
+ case CSYNC_FTW_FLAG_DIR: /* enter directory */
+ CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE, "directory: %s", file);
+ type = CSYNC_FTW_TYPE_DIR;
+ break;
+ case CSYNC_FTW_FLAG_NSTAT: /* not statable file */
+ /* if file was here before and now is not longer stat-able, still
+ * add it to the db, otherwise not. */
+ CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE, "non statable file: %s", file);
+ type = CSYNC_FTW_TYPE_FILE;
+ break;
+ case CSYNC_FTW_FLAG_SLINK:
+ CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE, "symlink: %s - not supported", file);
+ case CSYNC_FTW_FLAG_DNR:
+ case CSYNC_FTW_FLAG_DP:
+ case CSYNC_FTW_FLAG_SLN:
+ default:
+ return 0;
+ break;
}
- return 0;
+ rc = _csync_detect_update(ctx, file, fs, type );
+
+ return rc;
}
/* check if the dirent entries for the directory can be read from db
@@ -410,7 +470,7 @@
flag = CSYNC_FTW_FLAG_NSTAT;
}
- if( ctx->current == LOCAL_REPLICA ) {
+ if( flag != CSYNC_FTW_FLAG_NSTAT && ctx->current == LOCAL_REPLICA ) {
char *md5 = NULL;
int len = strlen( path );
uint64_t h = c_jhash64((uint8_t *) path, len, 0);
|
[-]
[+]
|
Changed |
ocsync-0.70.7.tar.bz2/src/csync_util.c
^
|
@@ -139,10 +139,10 @@
/* check if the file is new or has been synced */
node = c_rbtree_find(tree, &fs->phash);
if (node == NULL) {
- csync_file_stat_t *new = NULL;
+ csync_file_stat_t *new_stat = NULL;
- new = c_malloc(sizeof(csync_file_stat_t) + fs->pathlen + 1);
- if (new == NULL) {
+ new_stat = c_malloc(sizeof(csync_file_stat_t) + fs->pathlen + 1);
+ if (new_stat == NULL) {
strerror_r(errno, errbuf, sizeof(errbuf));
CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR,
"file: %s, merge malloc, error: %s",
@@ -151,15 +151,15 @@
rc = -1;
goto out;
}
- new = memcpy(new, fs, sizeof(csync_file_stat_t) + fs->pathlen + 1);
+ new_stat = memcpy(new_stat, fs, sizeof(csync_file_stat_t) + fs->pathlen + 1);
if (fs->md5)
- new->md5 = c_strdup(fs->md5);
+ new_stat->md5 = c_strdup(fs->md5);
if (fs->destpath)
- new->destpath = c_strdup(fs->destpath);
+ new_stat->destpath = c_strdup(fs->destpath);
- if (c_rbtree_insert(tree, new) < 0) {
+ if (c_rbtree_insert(tree, new_stat) < 0) {
strerror_r(errno, errbuf, sizeof(errbuf));
- SAFE_FREE(new);
+ SAFE_FREE(new_stat);
CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR,
"file: %s, rb tree insert, error: %s",
fs->path,
|
[-]
[+]
|
Changed |
ocsync-0.70.7.tar.bz2/src/std/c_file.c
^
|
@@ -30,6 +30,7 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
+#include <string.h>
#include "c_file.h"
#include "c_string.h"
@@ -163,3 +164,83 @@
#endif
}
+int c_compare_file( const char *f1, const char *f2 ) {
+ _TCHAR *wf1, *wf2;
+ int fd1 = -1, fd2 = -1;
+ size_t size1, size2;
+ char buffer1[BUFFER_SIZE];
+ char buffer2[BUFFER_SIZE];
+ csync_stat_t stat1;
+ csync_stat_t stat2;
+
+ int rc = -1;
+
+ if(f1 == NULL || f2 == NULL) return -1;
+
+ wf1 = c_multibyte(f1);
+ if(wf1 == NULL) {
+ return -1;
+ }
+ wf2 = c_multibyte(f2);
+ if(wf2 == NULL) {
+ return -1;
+ }
+
+ /* compare size first. */
+ rc = _tstat(wf1, &stat1);
+ if(rc< 0) {
+ goto out;
+ }
+ rc = _tstat(wf2, &stat2);
+ if(rc < 0) {
+ goto out;
+ }
+
+ /* if sizes are different, the files can not be equal. */
+ if( stat1.st_size != stat2.st_size ) {
+ rc = 0;
+ goto out;
+ }
+
+#ifdef _WIN32
+ _fmode = _O_BINARY;
+#endif
+
+ fd1 = _topen(wf1, O_RDONLY);
+ if(fd1 < 0) {
+ rc = -1;
+ goto out;
+ }
+ fd2 = _topen(wf2, O_RDONLY);
+ if(fd2 < 0) {
+ rc = -1;
+ goto out;
+ }
+
+ while( (size1 = read(fd1, buffer1, BUFFER_SIZE)) > 0 ) {
+ size2 = read( fd2, buffer2, BUFFER_SIZE );
+
+ if( size1 != size2 ) {
+ rc = 0;
+ goto out;
+ }
+ if(memcmp(buffer1, buffer2, size1) != 0) {
+ /* buffers are different */
+ rc = 0;
+ goto out;
+ }
+ }
+
+ rc = 1;
+
+out:
+
+ if(fd1 > -1) close(fd1);
+ if(fd2 > -1) close(fd2);
+
+ c_free_multibyte(wf1);
+ c_free_multibyte(wf2);
+ return rc;
+
+}
+
|
[-]
[+]
|
Changed |
ocsync-0.70.7.tar.bz2/src/std/c_file.h
^
|
@@ -64,6 +64,16 @@
int c_copy(const char *src, const char *dst, mode_t mode);
/**
+ * @brief Compare the content of two files byte by byte.
+ * @param f1 Path of file 1
+ * @param f2 Path of file 2
+ *
+ * @return 0 if the files differ, 1 if the files are equal or -1 on
+ * error with errno set.
+ */
+int c_compare_file( const char *f1, const char *f2 );
+
+/**
* }@
*/
#endif /* _C_FILE_H */
|
[-]
[+]
|
Changed |
ocsync-0.70.7.tar.bz2/src/vio/csync_vio.c
^
|
@@ -217,12 +217,15 @@
(*ctx->module.finish_fn)(ctx->module.method);
}
+/* GnuTLS, used on most linux distros, does not support dlclose without leaking. */
+#if defined(__APPLE__) || defined(_WIN32)
/* close the plugin */
dlclose(ctx->module.handle);
ctx->module.handle = NULL;
ctx->module.method = NULL;
ctx->module.finish_fn = NULL;
+#endif
}
}
@@ -552,8 +555,13 @@
break;
case LOCAL_REPLICA:
rc = csync_vio_local_stat(uri, buf);
+ if (rc < 0) {
+ CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, "Local stat failed, errno %d", errno);
+ }
#ifdef _WIN32
- CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "Win32: STAT-inode for %s: %llu", uri, buf->inode );
+ else {
+ CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "Win32: STAT-inode for %s: %llu", uri, buf->inode );
+ }
#endif
break;
default:
|
[-]
[+]
|
Changed |
ocsync-0.70.7.tar.bz2/src/vio/csync_vio_local.c
^
|
@@ -303,7 +303,6 @@
buf->name = c_basename(uri);
if (buf->name == NULL) {
- csync_vio_file_stat_destroy(buf);
c_free_multibyte(wuri);
return -1;
}
@@ -359,9 +358,7 @@
HANDLE h = CreateFileW( wuri, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL+FILE_FLAG_BACKUP_SEMANTICS, NULL );
if( h == INVALID_HANDLE_VALUE ) {
- DWORD err = GetLastError();
- /* CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "ERR: Failed to create a handle for %s: %ld", uri,err ); */
- csync_vio_file_stat_destroy(buf);
+ errno = GetLastError();
c_free_multibyte(wuri);
return -1;
@@ -432,6 +429,7 @@
buf->fields |= CSYNC_VIO_FILE_STAT_FIELDS_SIZE;
c_free_multibyte(wuri);
+
return 0;
}
|
[-]
[+]
|
Changed |
ocsync-0.70.7.tar.bz2/src/vio/csync_vio_method.h
^
|
@@ -30,8 +30,8 @@
#include "vio/csync_vio_handle.h"
#define VIO_METHOD_HAS_FUNC(method,func) \
- (((size_t)(((char *)&((method)->func)) - ((char *)(method))) < (method)->method_table_size) \
- && method->func != NULL)
+ (method != NULL && method->func != NULL \
+ && ((size_t)(((char *)&((method)->func)) - ((char *)(method))) < (method)->method_table_size))
typedef struct csync_vio_method_s csync_vio_method_t;
|
[-]
[+]
|
Changed |
ocsync-0.70.7.tar.bz2/tests/ownCloud/t1.pl
^
|
@@ -1,6 +1,6 @@
#!/usr/bin/perl
#
-# Test script for the ownCloud module of csync.
+# Test script for the ownCloud module of csync.
# This script requires a running ownCloud instance accessible via HTTP.
# It does quite some fancy tests and asserts the results.
#
@@ -25,7 +25,7 @@
# user => "joe",
# passwd => "XXXXXX",
# url => "http://localhost/oc/files/webdav.php"
-
+
my $owncloud = "http://localhost/oc/files/webdav.php/";
my $user = "joe";
my $passwd = 'XXXXX'; # Mind to be secure.
@@ -52,7 +52,7 @@
my ($d, $dir) = @_;
my $url = $owncloud . $dir ;
-
+
$d->open( $owncloud );
print $d->message . "\n";
@@ -81,7 +81,7 @@
$d->open( -url => $owncloud );
print "Cleaning Remote!\n";
-
+
my $re = $d->delete( $dir );
if( $re == 0 ) {
@@ -108,15 +108,15 @@
$url =~ s#^http://##; # Remove the leading http://
$url = "owncloud://$user:$passwd@". $url . $remote;
print "CSync URL: $url\n";
-
- my $cmd = "LD_LIBRARY_PATH=$ld_libpath $csync $local $url";
+
+ my $cmd = "LD_LIBRARY_PATH=$ld_libpath $csync --debug-level=11 $local $url";
print "Starting: $cmd\n";
system( $cmd ) == 0 or die("CSync died!\n");
}
#
-# Check local directories if they have the same content.
+# Check local directories if they have the same content.
#
sub assertLocalDirs( $$ )
{
@@ -135,7 +135,7 @@
}
#
-# Check if a local and a remote dir have the same content
+# Check if a local and a remote dir have the same content
#
sub assertLocalAndRemoteDir( $$$ )
{
@@ -145,7 +145,7 @@
if( my $r = $d->propfind( -url => $owncloud . $remote, -depth => 1 ) ) {
if( $r->is_collection ) {
print "\nXX" . $r->get_resourcelist->as_string ."\n";
-
+
foreach my $res ( $r->get_resourcelist->get_resources() ) {
print "Checking " . $res-> get_uri()->as_string ."\n";
my $filename = $res->get_property("rel_uri");
@@ -156,12 +156,14 @@
my $remoteModTime = $res->get_property( "lastmodifiedepoch" ) ;
my @info = stat( "$local/$filename" );
my $localModTime = $info[9];
- assert( $remoteModTime == $localModTime, "Modfied-Times differ: remote: $remoteModTime <-> local: $localModTime" );
-
+ assert( abs($remoteModTime - $localModTime) < 5, "Modfied-Times differ for $filename: remote: $remoteModTime <-> local: $localModTime" );
+
# check for the same file size
my $localSize = $info[7];
my $remoteSize = $res->get_property( "getcontentlength" );
- assert( $localSize == $remoteSize );
+ if( $remoteSize ) { # Directories have no contentlength
+ assert( $localSize == $remoteSize, "Local size <$localSize> different from remote size <$remoteSize>" );
+ }
# remember the files seen on the server.
$seen{$filename} = 1;
@@ -169,17 +171,18 @@
}
# Now loop over the local directory content and check if all files in the dir
# were seen on the server.
-
+
print "\n* Cross checking with local dir: \n";
opendir(my $dh, $local ) || die;
while( readdir $dh ) {
next if( /^\.+$/ );
assert( -e "$local/$_" );
- assert( $seen{$_} == 1, "Filename only local, but not remte: $_\n" );
+ my $isHere = (exists $seen{$_} || exists $seen{$_ . "/"});
+ assert( $isHere, "Filename only local, but not remote: $_\n" );
}
closedir $dh;
-
+
}
}
@@ -189,7 +192,7 @@
my( $d, $globber, $target ) = @_;
$d->open( $target );
-
+
my @puts = bsd_glob( $globber );
foreach my $lfile( @puts ) {
if( $lfile =~ /.*\/(.+)$/g ) {
|
[-]
[+]
|
Changed |
ocsync-0.70.7.tar.bz2/tests/std_tests/check_std_c_file.c
^
|
@@ -85,12 +85,66 @@
assert_int_equal(errno, EISDIR);
}
+static void check_c_compare_file(void **state)
+{
+ int rc;
+ (void) state;
+
+ rc = c_copy(check_src_file, check_dst_file, 0644);
+ assert_int_equal(rc, 0);
+
+ rc = c_compare_file( check_src_file, check_dst_file );
+ assert_int_equal(rc, 1);
+
+ /* Check error conditions */
+ rc = c_compare_file( NULL, check_dst_file );
+ assert_int_equal(rc, -1);
+ rc = c_compare_file( check_dst_file, NULL );
+ assert_int_equal(rc, -1);
+ rc = c_compare_file( NULL, NULL );
+ assert_int_equal(rc, -1);
+
+ rc = c_compare_file( check_src_file, "/I_do_not_exist_in_the_filesystem.dummy");
+ assert_int_equal(rc, -1);
+ rc = c_compare_file( "/I_do_not_exist_in_the_filesystem.dummy", check_dst_file);
+ assert_int_equal(rc, -1);
+
+ rc = system("echo \"hallo42\" > /tmp/check/foo.txt");
+ assert_int_equal(rc, 0);
+ rc = system("echo \"hallo52\" > /tmp/check/bar.txt");
+ assert_int_equal(rc, 0);
+ rc = c_compare_file( check_src_file, check_dst_file );
+ assert_int_equal(rc, 0);
+
+ /* Create two 1MB random files */
+ rc = system("dd if=/dev/urandom of=/tmp/check/foo.txt bs=1024 count=1024");
+ assert_int_equal(rc, 0);
+ rc = system("dd if=/dev/urandom of=/tmp/check/bar.txt bs=1024 count=1024");
+ assert_int_equal(rc, 0);
+ rc = c_compare_file( check_src_file, check_dst_file );
+ assert_int_equal(rc, 0);
+
+ /* Create two 1MB random files with different size */
+ rc = system("dd if=/dev/urandom of=/tmp/check/foo.txt bs=1024 count=1024");
+ assert_int_equal(rc, 0);
+ rc = system("dd if=/dev/urandom of=/tmp/check/bar.txt bs=1024 count=1020");
+ assert_int_equal(rc, 0);
+ rc = c_compare_file( check_src_file, check_dst_file );
+ assert_int_equal(rc, 0);
+
+ /* compare two big files which are equal */
+ rc = c_copy(check_src_file, check_dst_file, 0644);
+ assert_int_equal(rc, 0);
+
+}
+
int torture_run_tests(void)
{
const UnitTest tests[] = {
unit_test_setup_teardown(check_c_copy, setup, teardown),
unit_test(check_c_copy_same_file),
unit_test_setup_teardown(check_c_copy_isdir, setup, teardown),
+ unit_test_setup_teardown(check_c_compare_file, setup, teardown),
};
return run_tests(tests);
|
[-]
[+]
|
Changed |
ocsync-0.70.7.tar.bz2/tests/std_tests/check_std_c_str.c
^
|
@@ -176,14 +176,14 @@
static void check_iconv_setup(void **state)
{
+#ifdef __APPLE__
int rc = 0;
- (void) state; /* unused */
-
-#ifdef __APPLE__
rc = c_setup_iconv("UTF-8-MAC");
assert_int_equal(rc, 0);
#endif
+ (void) state; /* unused */
+
}
static void check_iconv_teardown(void **state)
|