[Pkg-owncloud-commits] [owncloud-client] 05/333: Optimize restoring of the remote tree from database.

Sandro Knauß hefee-guest at moszumanska.debian.org
Thu Apr 17 23:16:26 UTC 2014


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit 3649869650270bc1138919cae4c75d39bfff101d
Author: Klaas Freitag <freitag at owncloud.com>
Date:   Fri Feb 7 11:52:37 2014 +0100

    Optimize restoring of the remote tree from database.
    
    If the etag of a directory hasn't changed, the content for the csync
    tree can be restored from database. The code doing that is now optimized
    so that this does not take so long any more.
---
 csync/src/CMakeLists.txt  |   1 -
 csync/src/csync_dbtree.c  | 235 ----------------------------------------------
 csync/src/csync_dbtree.h  |  60 ------------
 csync/src/csync_statedb.c | 188 ++++++++++++++++++++++++-------------
 csync/src/csync_statedb.h |   2 +-
 csync/src/csync_update.c  |  70 ++++++++------
 csync/src/vio/csync_vio.c |  27 +++---
 7 files changed, 175 insertions(+), 408 deletions(-)

diff --git a/csync/src/CMakeLists.txt b/csync/src/CMakeLists.txt
index db69899..2cb754f 100644
--- a/csync/src/CMakeLists.txt
+++ b/csync/src/CMakeLists.txt
@@ -57,7 +57,6 @@ set(csync_SRCS
   csync_exclude.c
   csync_log.c
   csync_statedb.c
-  csync_dbtree.c
   csync_time.c
   csync_util.c
   csync_misc.c
diff --git a/csync/src/csync_dbtree.c b/csync/src/csync_dbtree.c
deleted file mode 100644
index 06277b1..0000000
--- a/csync/src/csync_dbtree.c
+++ /dev/null
@@ -1,235 +0,0 @@
-/*
- * libcsync -- a library to sync a directory with another
- *
- * Copyright (c) 2012      by Klaas Freitag <freitag at owncloud.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include "config_csync.h"
-
-#ifndef _GNU_SOURCE
-#define _GNU_SOURCE
-#endif
-
-#include <stdio.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-
-#include "csync_dbtree.h"
-#include "c_lib.h"
-#include "csync_private.h"
-#include "csync_statedb.h"
-#include "csync_util.h"
-#include "c_macro.h"
-
-
-#define CSYNC_LOG_CATEGORY_NAME "csync.dbtree"
-#include "csync_log.h"
-
-struct dir_listing {
-    c_list_t *list;
-    unsigned int cnt;
-    c_list_t *entry;
-    char *dir;
-};
-
-csync_vio_method_handle_t *csync_dbtree_opendir(CSYNC *ctx, const char *name)
-{
-
-    char *column = NULL;
-    const char *path = NULL;
-    csync_vio_file_stat_t *fs = NULL;
-    unsigned int c = 0;
-    c_strlist_t *list = NULL;
-    struct dir_listing *listing = NULL;
-
-     /* "phash INTEGER(8),"
-       "pathlen INTEGER,"
-       "path VARCHAR(4096),"
-       "inode INTEGER,"
-       "uid INTEGER,"
-       "gid INTEGER,"
-       "mode INTEGER,"
-       "modtime INTEGER(8),"
-       "type INTEGER,"
-       "md5 VARCHAR(32),"  // That's the etag
-     */
-
-    int col_count = 10;
-    if( strlen(name) < strlen(ctx->remote.uri)+1) {
-        CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, "name does not contain remote uri!");
-        return NULL;
-    }
-
-    path = name + strlen(ctx->remote.uri)+1;
-
-    list = csync_statedb_get_below_path(ctx, path);
-
-    if( ! list ) {
-        CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, "Query result list is NULL!");
-        return NULL;
-    }
-    /* list count must be a multiple of col_count */
-    if( list->count % col_count != 0 ) {
-        CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, "Wrong size of query result list");
-        c_strlist_destroy( list );
-        return NULL;
-    }
-
-    listing = c_malloc(sizeof(struct dir_listing));
-    ZERO_STRUCTP(listing);
-    if( listing == NULL ) {
-        c_strlist_destroy( list );
-        errno = ENOMEM;
-        return NULL;
-    }
-
-    listing->dir = c_strdup(path);
-
-    for( c = 0; c < (list->count / col_count); c++) {
-        int base = c*col_count;
-        int cnt = 0;
-        int tpath_len = 0;
-        int type = 0;
-
-        char *tpath = list->vector[base+1];
-        /* check if the result points to a file directly below the search path
-         * by checking if there is another / in the result.
-         * If yes, skip it.
-         * FIXME: Find a better filter solution here.
-         */
-        tpath += strlen(path)+1; /* jump over the search path */
-        tpath_len = strlen( tpath );
-        while( cnt < tpath_len ) {
-            if(*(tpath+cnt) == '/') {
-                /* CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "Skipping entry: %s", list->vector[base+1]); */
-                break;
-            }
-            cnt++;
-        }
-        if( cnt < tpath_len ) continue;
-
-        if (!list->vector[base+8][0])
-            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;
-
-        column = list->vector[base+0]; /* phash    */
-
-        column = list->vector[base+1]; /* path     */
-        fs->name = c_strdup(column+strlen(path)+1);
-
-        column = list->vector[base+2]; /* inode    */
-        fs->inode = atoll(column);
-        fs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_INODE;
-
-        column = list->vector[base+3]; /* uid      */
-        fs->uid = atoi(column);
-        fs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_UID;
-
-        column = list->vector[base+4]; /* gid      */
-        fs->gid = atoi(column);
-        fs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_GID;
-
-        column = list->vector[base+5]; /* mode     */
-        fs->mode = atoi(column);
-        // fs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_M;
-
-        column = list->vector[base+6]; /* modtime  */
-        fs->mtime = strtoul(column, NULL, 10);
-        fs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_MTIME;
-
-        column = list->vector[base+7]; /* type     */
-        type = atoi(column);
-        /* Attention: the type of csync_ftw_type_e which is the source for
-         * the database entry is different from csync_vio_file_type_e which
-         * is the target file type here. Mapping is needed!
-         */
-        switch( type ) {
-        case CSYNC_FTW_TYPE_DIR:
-            fs->type = CSYNC_VIO_FILE_TYPE_DIRECTORY;
-            break;
-        case CSYNC_FTW_TYPE_FILE:
-            fs->type = CSYNC_VIO_FILE_TYPE_REGULAR;
-            break;
-        case CSYNC_FTW_TYPE_SLINK:
-            fs->type = CSYNC_VIO_FILE_TYPE_SYMBOLIC_LINK;
-            break;
-        default:
-            fs->type = CSYNC_VIO_FILE_TYPE_UNKNOWN;
-        }
-        fs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_TYPE;
-
-        column = list->vector[base+8]; /* etag */
-        fs->etag = c_strdup(column);
-        fs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_ETAG;
-
-        column = list->vector[base+9]; /* file id */
-        csync_vio_file_stat_set_file_id(fs, column);
-
-        /* store into result list. */
-        listing->list = c_list_append( listing->list, fs );
-        listing->cnt++;
-    }
-
-    if(listing->cnt)
-        listing->entry = c_list_first( listing->list );
-
-    c_strlist_destroy( list );
-
-    return listing;
-}
-
-int csync_dbtree_closedir(CSYNC *ctx, csync_vio_method_handle_t *dhandle)
-{
-    struct dir_listing *dl = NULL;
-    int rc = 0;
-    (void) ctx;
-
-    if( dhandle != NULL ) {
-        dl = (struct dir_listing*) dhandle;
-
-        c_list_free(dl->list);
-        SAFE_FREE(dl->dir);
-        SAFE_FREE(dl);
-    }
-
-    return rc;
-}
-
-csync_vio_file_stat_t *csync_dbtree_readdir(CSYNC *ctx, csync_vio_method_handle_t *dhandle)
-{
-    csync_vio_file_stat_t *fs = NULL;
-    struct dir_listing *dl = NULL;
-    (void) ctx;
-
-    if( dhandle != NULL ) {
-        dl = (struct dir_listing*) dhandle;
-        if( dl->entry != NULL ) {
-            fs = (csync_vio_file_stat_t*) dl->entry->data;
-
-            dl->entry = c_list_next( dl->entry);
-        }
-    }
-
-    return fs;
-}
-
-/* vim: set ts=8 sw=2 et cindent: */
diff --git a/csync/src/csync_dbtree.h b/csync/src/csync_dbtree.h
deleted file mode 100644
index a39138f..0000000
--- a/csync/src/csync_dbtree.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * libcsync -- a library to sync a directory with another
- *
- * Copyright (c) 2012      by Klaas Freitag <freitag at owncloud.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/**
- * @file csync_dbtree.h
- *
- * @brief Private interface of csync
- *
- * @defgroup csyncdbtreeInternals csync statedb internals
- * @ingroup csyncInternalAPI
- *
- * @{
- */
-
-#ifndef _CSYNC_DBTREE_H
-#define _CSYNC_DBTREE_H
-
-#include "c_lib.h"
-#include "csync_private.h"
-#include "vio/csync_vio_handle.h"
-
-/**
- * @brief Open a directory based on the statedb.
- *
- * This function reads the list of files within a directory from statedb and
- * builds up a list in memory.
- *
- * @param ctx      The csync context.
- * @param name     The directory name.
- *
- * @return 0 on success, less than 0 if an error occured with errno set.
- */
-csync_vio_method_handle_t *csync_dbtree_opendir(CSYNC *ctx, const char *name);
-
-int csync_dbtree_closedir(CSYNC *ctx, csync_vio_method_handle_t *dhandle);
-
-csync_vio_file_stat_t *csync_dbtree_readdir(CSYNC *ctx, csync_vio_method_handle_t *dhandle);
-
-/**
- * }@
- */
-#endif /* _CSYNC_DBTREE_H */
-/* vim: set ft=c.doxygen ts=8 sw=2 et cindent: */
diff --git a/csync/src/csync_statedb.c b/csync/src/csync_statedb.c
index d095353..cff867a 100644
--- a/csync/src/csync_statedb.c
+++ b/csync/src/csync_statedb.c
@@ -190,6 +190,16 @@ static int _csync_statedb_is_empty(sqlite3 *db) {
   return rc;
 }
 
+#ifndef NDEBUG
+static void sqlite_profile( void *x, const char* sql, sqlite3_uint64 time)
+{
+    (void)x;
+    CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG,
+              "_SQL_ %s: %llu", sql, time);
+
+}
+#endif
+
 int csync_statedb_load(CSYNC *ctx, const char *statedb, sqlite3 **pdb) {
   int rc = -1;
   int check_rc = -1;
@@ -255,6 +265,9 @@ int csync_statedb_load(CSYNC *ctx, const char *statedb, sqlite3 **pdb) {
   result = csync_statedb_query(db, "PRAGMA case_sensitive_like = ON;");
   c_strlist_destroy(result);
 
+#ifndef NDEBUG
+  sqlite3_profile(db, sqlite_profile, 0 );
+#endif
   *pdb = db;
 
   return 0;
@@ -329,13 +342,67 @@ int csync_statedb_close(const char *statedb, sqlite3 *db, int jwritten) {
   return rc;
 }
 
+// This funciton parses a line from the metadata table into the given csync_file_stat
+// structure which it is also allocating.
+// Note that this function calls laso sqlite3_step to actually get the info from db and
+// returns the sqlite return type.
+static int _csync_file_stat_from_metadata_table( csync_file_stat_t **st, sqlite3_stmt *stmt )
+{
+    int rc = SQLITE_ERROR;
+    int column_count;
+    int len;
+
+    if( ! stmt ) return -1;
+
+    column_count = sqlite3_column_count(stmt);
+
+    rc = sqlite3_step(stmt);
+
+    if( rc == SQLITE_ROW ) {
+        if(column_count > 7) {
+            const char *name;
+
+            /* phash, pathlen, path, inode, uid, gid, mode, modtime */
+            len = sqlite3_column_int(stmt, 1);
+            *st = c_malloc(sizeof(csync_file_stat_t) + len + 1);
+            if (*st == NULL) {
+                return -1;
+            }
+            /* clear the whole structure */
+            ZERO_STRUCTP(*st);
+
+            /* The query suceeded so use the phash we pass to the function. */
+            (*st)->phash = sqlite3_column_int64(stmt, 0);
+
+            (*st)->pathlen = sqlite3_column_int(stmt, 1);
+            name = (const char*) sqlite3_column_text(stmt, 2);
+            memcpy((*st)->path, (len ? name : ""), len + 1);
+            (*st)->inode = sqlite3_column_int64(stmt,3);
+            (*st)->uid = sqlite3_column_int(stmt, 4);
+            (*st)->gid = sqlite3_column_int(stmt, 5);
+            (*st)->mode = sqlite3_column_int(stmt, 6);
+            (*st)->modtime = strtoul((char*)sqlite3_column_text(stmt, 7), NULL, 10);
+
+            if(*st && column_count > 8 ) {
+                (*st)->type = sqlite3_column_int(stmt, 8);
+            }
+
+            if(column_count > 9 && sqlite3_column_text(stmt, 9)) {
+                (*st)->etag = c_strdup( (char*) sqlite3_column_text(stmt, 9) );
+            }
+            if(column_count > 10 && sqlite3_column_text(stmt,10)) {
+                csync_vio_set_file_id((*st)->file_id, (char*) sqlite3_column_text(stmt, 10));
+            }
+        }
+    }
+    return rc;
+}
+
 /* caller must free the memory */
 csync_file_stat_t *csync_statedb_get_stat_by_hash(sqlite3 *db,
                                                   uint64_t phash)
 {
   csync_file_stat_t *st = NULL;
-  size_t len = 0;
-  int column_count = 0;
   int rc;
 
   if( _by_hash_stmt == NULL ) {
@@ -350,64 +417,11 @@ csync_file_stat_t *csync_statedb_get_stat_by_hash(sqlite3 *db,
     return NULL;
   }
 
-  column_count = sqlite3_column_count(_by_hash_stmt);
-
   sqlite3_bind_int64(_by_hash_stmt, 1, (long long signed int)phash);
-  rc = sqlite3_step(_by_hash_stmt);
-
-  if( rc == SQLITE_ROW ) {
-    if(column_count > 7) {
-      /* phash, pathlen, path, inode, uid, gid, mode, modtime */
-      len = sqlite3_column_int(_by_hash_stmt, 1);
-      st = c_malloc(sizeof(csync_file_stat_t) + len + 1);
-      if (st == NULL) {
-        return NULL;
-      }
-      /* clear the whole structure */
-      ZERO_STRUCTP(st);
-
-      /*
-       * FIXME:
-       * We use an INTEGER(8) which is signed to the phash in the sqlite3 db,
-       * but the phash is an uint64_t. So for some values we get a string like
-       * "1.66514565505016e+19". For such a string strtoull() returns 1.
-       * phash = 1
-       *
-       * st->phash = strtoull(result->vector[0], NULL, 10);
-       */
-
-      /* The query suceeded so use the phash we pass to the function. */
-      st->phash = phash;
 
-      st->pathlen = sqlite3_column_int(_by_hash_stmt, 1);
-      memcpy(st->path, (len ? (char*) sqlite3_column_text(_by_hash_stmt, 2) : ""), len + 1);
-      st->inode = sqlite3_column_int64(_by_hash_stmt,3);
-      st->uid = sqlite3_column_int(_by_hash_stmt, 4);
-      st->gid = sqlite3_column_int(_by_hash_stmt, 5);
-      st->mode = sqlite3_column_int(_by_hash_stmt, 6);
-      st->modtime = strtoul((char*)sqlite3_column_text(_by_hash_stmt, 7), NULL, 10);
-
-      if(st && column_count > 8 ) {
-        st->type = sqlite3_column_int(_by_hash_stmt, 8);
-      }
-
-      if(column_count > 9 && sqlite3_column_text(_by_hash_stmt, 9)) {
-        st->etag = c_strdup( (char*) sqlite3_column_text(_by_hash_stmt, 9) );
-      }
-      if(column_count > 10 && sqlite3_column_text(_by_hash_stmt,10)) {
-          csync_vio_set_file_id(st->file_id, (char*) sqlite3_column_text(_by_hash_stmt, 10));
-      }
-    }
-  } else {
-    /* SQLITE_DONE says there is no further row. That's not an error. */
-    if (rc != SQLITE_DONE) {
-      CSYNC_LOG(CSYNC_LOG_PRIORITY_WARN, "sqlite hash query fail: %s", sqlite3_errmsg(db));
-    }
-    CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE, "No result record found for phash = %llu",
-              (long long unsigned int) phash);
-    SAFE_FREE(st);
+  if( _csync_file_stat_from_metadata_table(&st, _by_hash_stmt) < 0 ) {
+      CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, "WRN: Could not get line from metadata!");
   }
-
   sqlite3_reset(_by_hash_stmt);
 
   return st;
@@ -559,23 +573,63 @@ char *csync_statedb_get_uniqId( CSYNC *ctx, uint64_t jHash, csync_vio_file_stat_
     return ret;
 }
 
-c_strlist_t *csync_statedb_get_below_path( CSYNC *ctx, const char *path ) {
-    c_strlist_t *list = NULL;
-    char *stmt = NULL;
+#define BELOW_PATH_QUERY "SELECT phash, pathlen, path, inode, uid, gid, mode, modtime, type, md5, fileid FROM metadata WHERE path LIKE(?)"
+
+int csync_statedb_get_below_path( CSYNC *ctx, const char *path ) {
+    int rc;
+    sqlite3_stmt *stmt = NULL;
+    int64_t cnt = 0;
+    char *likepath;
+    int asp;
+
+    if( !path ) {
+        return -1;
+    }
+
+    rc = sqlite3_prepare_v2(ctx->statedb.db, BELOW_PATH_QUERY, -1, &stmt, NULL);
+    if( rc != SQLITE_OK ) {
+      CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, "WRN: Unable to create stmt for hash query.");
+      return -1;
+    }
 
-    stmt = sqlite3_mprintf("SELECT phash, path, inode, uid, gid, mode, modtime, type, md5, fileid "
-                           "FROM metadata WHERE path LIKE('%q/%%')", path);
     if (stmt == NULL) {
-      return NULL;
+      return -1;
     }
 
-    CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "SQL: %s", stmt);
+    asp = asprintf( &likepath, "%s/%%%%", path);
+    if (asp < 0) {
+        CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, "asprintf failed!");
+        return -1;
+    }
 
-    list = csync_statedb_query( ctx->statedb.db, stmt );
+    sqlite3_bind_text(stmt, 1, likepath, -1, SQLITE_STATIC);
 
-    sqlite3_free(stmt);
+    cnt = 0;
+
+    do {
+        csync_file_stat_t *st = NULL;
+
+        rc = _csync_file_stat_from_metadata_table( &st, stmt);
+        if( st ) {
+            /* store into result list. */
+            if (c_rbtree_insert(ctx->remote.tree, (void *) st) < 0) {
+                SAFE_FREE(st);
+                ctx->status_code = CSYNC_STATUS_TREE_ERROR;
+                break;
+            }
+            cnt++;
+        }
+    } while( rc == SQLITE_ROW );
+
+    if( rc != SQLITE_DONE ) {
+        ctx->status_code = CSYNC_STATUS_TREE_ERROR;
+    } else {
+        CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "%ld entries read below path %s from db.", cnt, path);
+    }
+    sqlite3_finalize(stmt);
+    SAFE_FREE(likepath);
 
-    return list;
+    return 0;
 }
 
 /* query the statedb, caller must free the memory */
diff --git a/csync/src/csync_statedb.h b/csync/src/csync_statedb.h
index feef102..c618a6a 100644
--- a/csync/src/csync_statedb.h
+++ b/csync/src/csync_statedb.h
@@ -82,7 +82,7 @@ char *csync_statedb_get_uniqId(CSYNC *ctx, uint64_t jHash, csync_vio_file_stat_t
  *
  * @return   A stringlist containing a multiple of 9 entries.
  */
-c_strlist_t *csync_statedb_get_below_path(CSYNC *ctx, const char *path);
+int csync_statedb_get_below_path(CSYNC *ctx, const char *path);
 
 /**
  * @brief A generic statedb query.
diff --git a/csync/src/csync_update.c b/csync/src/csync_update.c
index c903371..e4dc88e 100644
--- a/csync/src/csync_update.c
+++ b/csync/src/csync_update.c
@@ -423,6 +423,22 @@ int csync_walker(CSYNC *ctx, const char *file, const csync_vio_file_stat_t *fs,
   return rc;
 }
 
+static void fill_tree_from_db(CSYNC *ctx, const char *uri)
+{
+    const char *path = NULL;
+
+    if( strlen(uri) < strlen(ctx->remote.uri)+1) {
+        CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, "name does not contain remote uri!");
+        return;
+    }
+
+    path = uri + strlen(ctx->remote.uri)+1;
+
+    if( csync_statedb_get_below_path(ctx, path) < 0 ) {
+        CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, "StateDB could not be read!");
+    }
+}
+
 /* File tree walker */
 int csync_ftw(CSYNC *ctx, const char *uri, csync_walker_fn fn,
     unsigned int depth) {
@@ -447,24 +463,31 @@ int csync_ftw(CSYNC *ctx, const char *uri, csync_walker_fn fn,
 
   read_from_db = ctx->remote.read_from_db;
 
+  // if the etag of this dir is still the same, its content is restored from the
+  // database.
+  if( do_read_from_db ) {
+      fill_tree_from_db(ctx, uri);
+      goto done;
+  }
+
   if ((dh = csync_vio_opendir(ctx, uri)) == NULL) {
-    int asp = 0;
-    /* permission denied */
-    ctx->status_code = csync_errno_to_status(errno, CSYNC_STATUS_OPENDIR_ERROR);
-    if (errno == EACCES) {
-       return 0;
-    } else if(errno == ENOENT) {
-      asp = asprintf( &ctx->error_string, "%s", uri);
-      if (asp < 0) {
-	CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, "asprintf failed!");
+      int asp = 0;
+      /* permission denied */
+      ctx->status_code = csync_errno_to_status(errno, CSYNC_STATUS_OPENDIR_ERROR);
+      if (errno == EACCES) {
+          return 0;
+      } else if(errno == ENOENT) {
+          asp = asprintf( &ctx->error_string, "%s", uri);
+          if (asp < 0) {
+              CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, "asprintf failed!");
+          }
+      } else {
+          C_STRERROR(errno, errbuf, sizeof(errbuf));
+          CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR,
+                    "opendir failed for %s - %s (errno %d)",
+                    uri, errbuf, errno);
       }
-    } else {
-      C_STRERROR(errno, errbuf, sizeof(errbuf));
-      CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR,
-          "opendir failed for %s - %s (errno %d)",
-          uri, errbuf, errno);
-    }
-    goto error;
+      goto error;
   }
 
   while ((dirent = csync_vio_readdir(ctx, dh))) {
@@ -528,13 +551,8 @@ int csync_ftw(CSYNC *ctx, const char *uri, csync_walker_fn fn,
     }
 
     /* == see if really stat has to be called. */
-    if( do_read_from_db ) {
-        fs = dirent;
-        res = 0;
-    } else {
-        fs = csync_vio_file_stat_new();
-        res = csync_vio_stat(ctx, filename, fs);
-    }
+    fs = csync_vio_file_stat_new();
+    res = csync_vio_stat(ctx, filename, fs);
 
     if( res == 0) {
       switch (fs->type) {
@@ -587,11 +605,7 @@ int csync_ftw(CSYNC *ctx, const char *uri, csync_walker_fn fn,
         previous_fs->child_modified = ctx->current_fs->child_modified;
     }
 
-    if( ! do_read_from_db ) {
-        csync_vio_file_stat_destroy(fs);
-    } else {
-        SAFE_FREE(fs->etag);
-    }
+    csync_vio_file_stat_destroy(fs);
 
     if (rc < 0) {
       if (CSYNC_STATUS_IS_OK(ctx->status_code)) {
diff --git a/csync/src/vio/csync_vio.c b/csync/src/vio/csync_vio.c
index 73bf630..9265bac 100644
--- a/csync/src/vio/csync_vio.c
+++ b/csync/src/vio/csync_vio.c
@@ -26,7 +26,6 @@
 #include <stdio.h>
 
 #include "csync_private.h"
-#include "csync_dbtree.h"
 #include "csync_util.h"
 #include "vio/csync_vio.h"
 #include "vio/csync_vio_handle_private.h"
@@ -364,11 +363,9 @@ csync_vio_handle_t *csync_vio_opendir(CSYNC *ctx, const char *name) {
   switch(ctx->replica) {
     case REMOTE_REPLICA:
       if(ctx->remote.read_from_db) {
-          CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "Reading directory %s from database", name);
-          mh = csync_dbtree_opendir(ctx, name);
-      } else {
-          mh = ctx->module.method->opendir(name);
+          CSYNC_LOG(CSYNC_LOG_PRIORITY_WARN, "Read from db flag is true, should not!" );
       }
+      mh = ctx->module.method->opendir(name);
       break;
     case LOCAL_REPLICA:
       mh = csync_vio_local_opendir(name);
@@ -395,17 +392,16 @@ int csync_vio_closedir(CSYNC *ctx, csync_vio_handle_t *dhandle) {
   }
 
   switch(ctx->replica) {
-    case REMOTE_REPLICA:
-      if(ctx->remote.read_from_db) {
-          rc = csync_dbtree_closedir(ctx, dhandle->method_handle);
-      } else {
-          rc = ctx->module.method->closedir(dhandle->method_handle);
+  case REMOTE_REPLICA:
+      if( ctx->remote.read_from_db ) {
+          CSYNC_LOG(CSYNC_LOG_PRIORITY_WARN, "Remote ReadFromDb is true, should not!");
       }
+      rc = ctx->module.method->closedir(dhandle->method_handle);
       break;
-    case LOCAL_REPLICA:
+  case LOCAL_REPLICA:
       rc = csync_vio_local_closedir(dhandle->method_handle);
       break;
-    default:
+  default:
       CSYNC_LOG(CSYNC_LOG_PRIORITY_ALERT, "Invalid replica (%d)", (int)ctx->replica);
       break;
   }
@@ -421,11 +417,10 @@ csync_vio_file_stat_t *csync_vio_readdir(CSYNC *ctx, csync_vio_handle_t *dhandle
 
   switch(ctx->replica) {
     case REMOTE_REPLICA:
-      if(ctx->remote.read_from_db) {
-          fs = csync_dbtree_readdir(ctx, dhandle->method_handle);
-      } else {
-          fs = ctx->module.method->readdir(dhandle->method_handle);
+      if( ctx->remote.read_from_db ) {
+          CSYNC_LOG(CSYNC_LOG_PRIORITY_WARN, "Remote readfromdb is true, should not!");
       }
+      fs = ctx->module.method->readdir(dhandle->method_handle);
       break;
     case LOCAL_REPLICA:
       fs = csync_vio_local_readdir(dhandle->method_handle);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list