[Pkg-owncloud-commits] [owncloud-client] 15/470: Update: Check checksum for renamed files #2983

Sandro Knauß hefee-guest at moszumanska.debian.org
Thu May 12 16:24:39 UTC 2016


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 62ded39416885ae28e625e6a94e06f0a57afab83
Author: Christian Kamm <mail at ckamm.de>
Date:   Wed Jan 20 10:47:01 2016 +0100

    Update: Check checksum for renamed files #2983
    
    This currently doesn't do much because we only compute content
    checksums for .eml files.
---
 csync/src/csync_update.c | 31 ++++++++++++++++++++++++-------
 1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/csync/src/csync_update.c b/csync/src/csync_update.c
index 44c9703..a7a76c5 100644
--- a/csync/src/csync_update.c
+++ b/csync/src/csync_update.c
@@ -351,24 +351,41 @@ static int _csync_detect_update(CSYNC *ctx, const char *file,
                 tmp_vio_type = CSYNC_VIO_FILE_TYPE_UNKNOWN;
             }
 
-            if (tmp && tmp->inode == fs->inode && tmp_vio_type == fs->type
+            // Default to NEW unless we're sure it's a rename.
+            st->instruction = CSYNC_INSTRUCTION_NEW;
+
+            bool isRename =
+                tmp && tmp->inode == fs->inode && tmp_vio_type == fs->type
                     && (tmp->modtime == fs->mtime || fs->type == CSYNC_VIO_FILE_TYPE_DIRECTORY)
 #ifdef NO_RENAME_EXTENSION
                     && _csync_sameextension(tmp->path, path)
 #endif
-               ) {
+                ;
+
+
+            // Verify the checksum where possible
+            if (isRename && tmp->checksumTypeId && ctx->callbacks.checksum_hook
+                    && fs->type == CSYNC_VIO_FILE_TYPE_REGULAR) {
+                st->checksum = ctx->callbacks.checksum_hook(
+                            file, tmp->checksumTypeId,
+                            ctx->callbacks.checksum_userdata);
+                if (st->checksum) {
+                    CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE, "checking checksum of potential rename %s %s <-> %s", path, st->checksum, tmp->checksum);
+                    st->checksumTypeId = tmp->checksumTypeId;
+                    isRename = strncmp(st->checksum, tmp->checksum, 1000) == 0;
+                }
+            }
+
+            if (isRename) {
                 CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE, "pot rename detected based on inode # %" PRId64 "", (uint64_t) fs->inode);
                 /* inode found so the file has been renamed */
                 st->instruction = CSYNC_INSTRUCTION_EVAL_RENAME;
                 if (fs->type == CSYNC_VIO_FILE_TYPE_DIRECTORY) {
                     csync_rename_record(ctx, tmp->path, path);
                 }
-                goto out;
-            } else {
-                /* file not found in statedb */
-                st->instruction = CSYNC_INSTRUCTION_NEW;
-                goto out;
             }
+            goto out;
+
         } else {
             /* Remote Replica Rename check */
             tmp = csync_statedb_get_stat_by_file_id(ctx, fs->file_id);

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