Created
August 18, 2013 09:51
-
-
Save guruz/6260817 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 67f5e1651e09be3f3c62203893567b630de5e4f4 Mon Sep 17 00:00:00 2001 | |
From: Markus Goetz <[email protected]> | |
Date: Sun, 18 Aug 2013 11:38:12 +0200 | |
Subject: [PATCH] Try improving local stating | |
--- | |
src/csync_update.c | 6 +++++- | |
src/vio/csync_vio_local.c | 55 +++++++++++++++++++++++++++++++++++++++++++---- | |
2 files changed, 56 insertions(+), 5 deletions(-) | |
diff --git a/src/csync_update.c b/src/csync_update.c | |
index a34a7c5..07d6543 100644 | |
--- a/src/csync_update.c | |
+++ b/src/csync_update.c | |
@@ -395,6 +395,7 @@ int csync_ftw(CSYNC *ctx, const char *uri, csync_walker_fn fn, | |
int res = 0; | |
bool do_read_from_db = (ctx->current == REMOTE_REPLICA && ctx->remote.read_from_db); | |
+ bool do_use_local_stat_result = (ctx->current == LOCAL_REPLICA); | |
if (uri[0] == '\0') { | |
errno = ENOENT; | |
@@ -496,6 +497,9 @@ int csync_ftw(CSYNC *ctx, const char *uri, csync_walker_fn fn, | |
if( do_read_from_db ) { | |
fs = dirent; | |
res = 0; | |
+ } else if ( do_use_local_stat_result ) { | |
+ fs = dirent; | |
+ res = 0; | |
} else { | |
fs = csync_vio_file_stat_new(); | |
res = csync_vio_stat(ctx, filename, fs); | |
@@ -547,7 +551,7 @@ int csync_ftw(CSYNC *ctx, const char *uri, csync_walker_fn fn, | |
if (ctx->current_fs && previous_fs && ctx->current_fs->child_modified) | |
previous_fs->child_modified = ctx->current_fs->child_modified; | |
- if( ! do_read_from_db ) | |
+ if( ! do_read_from_db && ! do_use_local_stat_result ) | |
csync_vio_file_stat_destroy(fs); | |
else | |
SAFE_FREE(fs->md5); | |
diff --git a/src/vio/csync_vio_local.c b/src/vio/csync_vio_local.c | |
index 6bd2908..37dabfe 100644 | |
--- a/src/vio/csync_vio_local.c | |
+++ b/src/vio/csync_vio_local.c | |
@@ -25,6 +25,7 @@ | |
#include <sys/stat.h> | |
#include <fcntl.h> | |
#include <dirent.h> | |
+#include <fts.h> | |
#include <stdio.h> | |
#ifdef _WIN32 | |
@@ -159,10 +160,12 @@ int64_t csync_vio_local_lseek(csync_vio_method_handle_t *fhandle, int64_t offset | |
typedef struct dhandle_s { | |
_TDIR *dh; | |
char *path; | |
+ void *nextChild; | |
} dhandle_t; | |
csync_vio_method_handle_t *csync_vio_local_opendir(const char *name) { | |
dhandle_t *handle = NULL; | |
+ FTSENT *ftsent = NULL; | |
_TCHAR *dirname = c_multibyte(name); | |
handle = c_malloc(sizeof(dhandle_t)); | |
if (handle == NULL) { | |
@@ -170,13 +173,18 @@ csync_vio_method_handle_t *csync_vio_local_opendir(const char *name) { | |
return NULL; | |
} | |
- handle->dh = _topendir( dirname ); | |
+ //handle->dh = _topendir( dirname ); | |
+ char *argv[] = {dirname, 0}; | |
+ handle->dh = (_TDIR*) fts_open(argv, 0, NULL); | |
if (handle->dh == NULL) { | |
c_free_multibyte(dirname); | |
SAFE_FREE(handle); | |
return NULL; | |
} | |
+ ftsent = fts_read((FTS *) handle->dh); | |
+ handle->nextChild = fts_children((FTS*) handle->dh, 0); | |
+ | |
handle->path = c_strdup(name); | |
c_free_multibyte(dirname); | |
@@ -193,7 +201,8 @@ int csync_vio_local_closedir(csync_vio_method_handle_t *dhandle) { | |
} | |
handle = (dhandle_t *) dhandle; | |
- rc = _tclosedir(handle->dh); | |
+ //rc = _tclosedir(handle->dh); | |
+ fts_close ((FTS *) handle->dh); | |
SAFE_FREE(handle->path); | |
SAFE_FREE(handle); | |
@@ -202,7 +211,8 @@ int csync_vio_local_closedir(csync_vio_method_handle_t *dhandle) { | |
} | |
csync_vio_file_stat_t *csync_vio_local_readdir(csync_vio_method_handle_t *dhandle) { | |
- struct _tdirent *dirent = NULL; | |
+ //struct _tdirent *dirent = NULL; | |
+ FTSENT *ftsent = NULL; | |
dhandle_t *handle = NULL; | |
csync_vio_file_stat_t *file_stat = NULL; | |
@@ -210,6 +220,41 @@ csync_vio_file_stat_t *csync_vio_local_readdir(csync_vio_method_handle_t *dhandl | |
handle = (dhandle_t *) dhandle; | |
errno = 0; | |
+ //ftsent = fts_read((FTS *) handle->dh); | |
+ if (handle->nextChild) { | |
+ ftsent = handle->nextChild; | |
+ file_stat = csync_vio_file_stat_new(); | |
+ file_stat->name = c_utf8(ftsent->fts_name); | |
+ file_stat->mtime = ftsent->fts_statp->st_mtime; | |
+ file_stat->size = ftsent->fts_statp->st_size; | |
+ file_stat->inode = ftsent->fts_statp->st_ino; | |
+ if (S_ISDIR(ftsent->fts_statp->st_mode)) | |
+ file_stat->type = CSYNC_VIO_FILE_TYPE_DIRECTORY; | |
+ else if (S_ISREG(ftsent->fts_statp->st_mode)) | |
+ file_stat->type = CSYNC_VIO_FILE_TYPE_REGULAR; | |
+ else | |
+ file_stat->type = CSYNC_VIO_FILE_TYPE_UNKNOWN; | |
+ | |
+ file_stat->fields = CSYNC_VIO_FILE_STAT_FIELDS_MTIME | |
+ | CSYNC_VIO_FILE_STAT_FIELDS_SIZE | |
+ | CSYNC_VIO_FILE_STAT_FIELDS_INODE | |
+ | CSYNC_VIO_FILE_STAT_FIELDS_TYPE; | |
+ | |
+ handle->nextChild = ftsent->fts_link; | |
+ } else { | |
+ if (errno) { | |
+ goto err; | |
+ } else { | |
+ return NULL; | |
+ } | |
+ } | |
+ | |
+ | |
+ | |
+ | |
+ | |
+/* | |
+ errno = 0; | |
dirent = _treaddir(handle->dh); | |
if (dirent == NULL) { | |
if (errno) { | |
@@ -226,7 +271,8 @@ csync_vio_file_stat_t *csync_vio_local_readdir(csync_vio_method_handle_t *dhandl | |
file_stat->name = c_utf8(dirent->d_name); | |
file_stat->fields = CSYNC_VIO_FILE_STAT_FIELDS_NONE; | |
- | |
+*/ | |
+/* | |
#ifndef _WIN32 | |
switch (dirent->d_type) { | |
case DT_FIFO: | |
@@ -250,6 +296,7 @@ csync_vio_file_stat_t *csync_vio_local_readdir(csync_vio_method_handle_t *dhandl | |
break; | |
} | |
#endif | |
+*/ | |
return file_stat; | |
-- | |
1.8.0.2 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment