[Pkg-owncloud-commits] [owncloud-client] 221/333: Don't create .ctmp of sync journal

Sandro Knauß hefee-guest at moszumanska.debian.org
Thu Apr 17 23:16:56 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 98d7ff511606999cb260b1a4628694bce812ed40
Author: Olivier Goffart <ogoffart at woboq.com>
Date:   Wed Mar 26 10:20:30 2014 +0100

    Don't create .ctmp of sync journal
    
    Fixes #1559
---
 csync/src/csync.c                                  |  4 +-
 csync/src/csync_statedb.c                          | 79 +---------------------
 csync/src/csync_statedb.h                          |  2 +-
 csync/tests/csync_tests/check_csync_statedb_load.c | 12 +---
 test/testcsyncsqlite.h                             |  4 +-
 5 files changed, 8 insertions(+), 93 deletions(-)

diff --git a/csync/src/csync.c b/csync/src/csync.c
index da5be71..6e85e51 100644
--- a/csync/src/csync.c
+++ b/csync/src/csync.c
@@ -563,7 +563,7 @@ int csync_commit(CSYNC *ctx) {
   ctx->status_code = CSYNC_STATUS_OK;
 
   if (ctx->statedb.db != NULL
-      && csync_statedb_close(ctx, 0) < 0) {
+      && csync_statedb_close(ctx) < 0) {
     CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "ERR: closing of statedb failed.");
     rc = -1;
   }
@@ -618,7 +618,7 @@ int csync_destroy(CSYNC *ctx) {
   ctx->status_code = CSYNC_STATUS_OK;
 
   if (ctx->statedb.db != NULL
-      && csync_statedb_close(ctx, 0) < 0) {
+      && csync_statedb_close(ctx) < 0) {
     CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "ERR: closing of statedb failed.");
     rc = -1;
   }
diff --git a/csync/src/csync_statedb.c b/csync/src/csync_statedb.c
index ed0483a..78372f6 100644
--- a/csync/src/csync_statedb.c
+++ b/csync/src/csync_statedb.c
@@ -201,7 +201,6 @@ int csync_statedb_load(CSYNC *ctx, const char *statedb, sqlite3 **pdb) {
   int rc = -1;
   int check_rc = -1;
   c_strlist_t *result = NULL;
-  char *statedb_tmp = NULL;
   sqlite3 *db = NULL;
 
   if( !ctx ) {
@@ -219,30 +218,8 @@ int csync_statedb_load(CSYNC *ctx, const char *statedb, sqlite3 **pdb) {
     goto out;
   }
 
-  /*
-   * We want a two phase commit for the jounal, so we create a temporary copy
-   * of the database.
-   * The intention is that if something goes wrong we will not loose the
-   * statedb.
-   */
-  rc = asprintf(&statedb_tmp, "%s.ctmp", statedb);
-  if (rc < 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 or create the temporary database */
-  if (sqlite3_open(statedb_tmp, &db) != SQLITE_OK) {
+  if (sqlite3_open(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>");
@@ -250,7 +227,6 @@ int csync_statedb_load(CSYNC *ctx, const char *statedb, sqlite3 **pdb) {
     rc = -1;
     goto out;
   }
-  SAFE_FREE(statedb_tmp);
 
   /* If check_rc == 1 the database is new and empty as a result. */
   if ((check_rc == 1) || _csync_statedb_is_empty(db)) {
@@ -274,15 +250,11 @@ int csync_statedb_load(CSYNC *ctx, const char *statedb, sqlite3 **pdb) {
   return 0;
 out:
   sqlite3_close(db);
-  SAFE_FREE(statedb_tmp);
   return rc;
 }
 
-int csync_statedb_close(CSYNC *ctx, int jwritten) {
-  char *statedb_tmp = NULL;
-  mbchar_t* wstatedb_tmp = NULL;
+int csync_statedb_close(CSYNC *ctx) {
   int rc = 0;
-  mbchar_t *mb_statedb = NULL;
 
   if (!ctx) {
       return -1;
@@ -304,55 +276,8 @@ int csync_statedb_close(CSYNC *ctx, int jwritten) {
       ctx->statedb.by_inode_stmt = NULL;
   }
 
-  /* close the temporary database */
   sqlite3_close(ctx->statedb.db);
 
-  /* If we successfully synchronized, overwrite the original statedb
-   *
-   * First check the integrity of the tmp db. If ok, overwrite the old
-   * database with the tmp db.
-   */
-  if (jwritten) {
-      if (!ctx->statedb.file || asprintf(&statedb_tmp, "%s.ctmp", ctx->statedb.file) < 0) {
-        return -1;
-      }
-      /* statedb check returns either
-       * 0  : database exists and is fine
-       * 1  : new database was set up
-       * -1 : error.
-       */
-      if (_csync_statedb_check(statedb_tmp) >= 0) {
-          /* New statedb is valid. */
-          mb_statedb = c_utf8_to_locale(ctx->statedb.file);
-
-          /* Move the tmp-db to the real one. */
-          if (c_rename(statedb_tmp, ctx->statedb.file) < 0) {
-              CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG,
-                        "Renaming tmp db to original db failed. (errno=%d)", errno);
-              rc = -1;
-          } else {
-              CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG,
-                        "Successfully moved tmp db to original db.");
-          }
-      } else {
-          mb_statedb = c_utf8_to_locale(statedb_tmp);
-          _tunlink(mb_statedb);
-
-          /* new statedb_tmp is not integer. */
-          CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, "  ## csync tmp statedb corrupt. Original one is not replaced. ");
-          rc = -1;
-      }
-      c_free_locale_string(mb_statedb);
-  }
-
-  wstatedb_tmp = c_utf8_to_locale(statedb_tmp);
-  if (wstatedb_tmp) {
-      _tunlink(wstatedb_tmp);
-      c_free_locale_string(wstatedb_tmp);
-  }
-
-  SAFE_FREE(statedb_tmp);
-
   return rc;
 }
 
diff --git a/csync/src/csync_statedb.h b/csync/src/csync_statedb.h
index ebf4f45..1064601 100644
--- a/csync/src/csync_statedb.h
+++ b/csync/src/csync_statedb.h
@@ -58,7 +58,7 @@ int csync_get_statedb_exists(CSYNC *ctx);
  */
 int csync_statedb_load(CSYNC *ctx, const char *statedb, sqlite3 **pdb);
 
-int csync_statedb_close(CSYNC *ctx, int jwritten);
+int csync_statedb_close(CSYNC *ctx);
 
 csync_file_stat_t *csync_statedb_get_stat_by_hash(CSYNC *ctx, uint64_t phash);
 
diff --git a/csync/tests/csync_tests/check_csync_statedb_load.c b/csync/tests/csync_tests/check_csync_statedb_load.c
index 3ef2f05..bfeac74 100644
--- a/csync/tests/csync_tests/check_csync_statedb_load.c
+++ b/csync/tests/csync_tests/check_csync_statedb_load.c
@@ -26,7 +26,6 @@
 #include "csync_statedb.c"
 
 #define TESTDB "/tmp/check_csync1/test.db"
-#define TESTDBTMP "/tmp/check_csync1/test.db.ctmp"
 
 static void setup(void **state) {
     CSYNC *csync;
@@ -96,17 +95,11 @@ static void check_csync_statedb_load(void **state)
     CSYNC *csync = *state;
     csync_stat_t sb;
     int rc;
-    mbchar_t *testdbtmp = c_utf8_to_locale(TESTDBTMP);
-    assert_non_null( testdbtmp );
 
     rc = csync_statedb_load(csync, TESTDB, &csync->statedb.db);
     assert_int_equal(rc, 0);
 
-    rc = _tstat(testdbtmp, &sb);
-    assert_int_equal(rc, 0);
-
     sqlite3_close(csync->statedb.db);
-    c_free_locale_string(testdbtmp);
 }
 
 static void check_csync_statedb_close(void **state)
@@ -124,7 +117,7 @@ static void check_csync_statedb_close(void **state)
     assert_int_equal(rc, 0);
     modtime = sb.st_mtime;
 
-    rc = csync_statedb_close(csync, 0);
+    rc = csync_statedb_close(csync);
     assert_int_equal(rc, 0);
 
     rc = _tstat(testdb, &sb);
@@ -141,12 +134,11 @@ static void check_csync_statedb_close(void **state)
     sleep(1);
 
     /* statedb written */
-    rc = csync_statedb_close(csync, 1);
+    rc = csync_statedb_close(csync);
     assert_int_equal(rc, 0);
 
     rc = _tstat(testdb, &sb);
     assert_int_equal(rc, 0);
-    assert_true(modtime < sb.st_mtime);
 
     c_free_locale_string(testdb);
 }
diff --git a/test/testcsyncsqlite.h b/test/testcsyncsqlite.h
index f4ae931..8f614ff 100644
--- a/test/testcsyncsqlite.h
+++ b/test/testcsyncsqlite.h
@@ -37,11 +37,9 @@ private:
     } MY_CSYNC;
 
     MY_CSYNC _ctx;
-    int      _written;
 private slots:
     void initTestCase() {
         int rc;
-        _written = 0;
 
         memset(&_ctx, 0, sizeof(MY_CSYNC));
 
@@ -116,7 +114,7 @@ private slots:
 
     void cleanupTestCase() {
         SAFE_FREE(_ctx.statedb.file);
-        csync_statedb_close((CSYNC*)(&_ctx), _written);
+        csync_statedb_close((CSYNC*)(&_ctx));
     }
 
 };

-- 
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