[Pkg-owncloud-commits] [owncloud-client] 66/103: Add a compile option to disable renaming when the extension changes

Sandro Knauß hefee-guest at moszumanska.debian.org
Wed Apr 30 18:09:00 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 cc7826e0870b2c8b6a1373c774380901df83b4fe
Author: Olivier Goffart <ogoffart at woboq.com>
Date:   Thu Apr 24 11:51:48 2014 +0200

    Add a compile option to disable renaming when the extension changes
    
    This is only used for a very specific server that do not support
    changing the extension of files without re-uploading the file.
    
    Since the change is small and self contained, it is guarded by a #ifdef
    
    (Removed old BLACKLIST_ON_ERROR option that is no longer in use)
---
 csync/src/CMakeLists.txt |  9 ++++-----
 csync/src/csync_update.c | 26 +++++++++++++++++++++++++-
 2 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/csync/src/CMakeLists.txt b/csync/src/CMakeLists.txt
index d28f9e2..26ec238 100644
--- a/csync/src/CMakeLists.txt
+++ b/csync/src/CMakeLists.txt
@@ -44,11 +44,10 @@ if(HAVE_ICONV AND WITH_ICONV)
     list(APPEND CSYNC_LINK_LIBRARIES ${ICONV_LIBRARIES})
 endif()
 
-set(BLACKLIST_ON_ERROR 0 CACHE BOOL
-  "If an errors occurs three times on the same file, do not attempt to process that file any further.")
-
-if(BLACKLIST_ON_ERROR)
-    add_definitions(-DBLACKLIST_ON_ERROR)
+# Specific option for builds tied to servers that do not support renaming extensions
+set(NO_RENAME_EXTENSION 0 CACHE BOOL "Do not issue rename if the extension changes")
+if(NO_RENAME_EXTENSION)
+    add_definitions(-DNO_RENAME_EXTENSION)
 endif()
 
 set(csync_SRCS
diff --git a/csync/src/csync_update.c b/csync/src/csync_update.c
index 0387f19..654b46a 100644
--- a/csync/src/csync_update.c
+++ b/csync/src/csync_update.c
@@ -79,6 +79,26 @@ static uint64_t _hash_of_file(CSYNC *ctx, const char *file) {
   return h;
 }
 
+#ifdef NO_RENAME_EXTENSION
+/* Return true if the two path have the same extension. false otherwise. */
+static bool _csync_sameextension(const char *p1, const char *p2) {
+    /* Find pointer to the extensions */
+    const char *e1 = strrchr(p1, '.');
+    const char *e2 = strrchr(p2, '.');
+
+    /* If the found extension contains a '/', it is because the . was in the folder name
+     *            => no extensions */
+    if (e1 && strchr(e1, '/')) e1 = NULL;
+    if (e2 && strchr(e2, '/')) e2 = NULL;
+
+    /* If none have extension, it is the same extension */
+    if (!e1 && !e2)
+        return true;
+
+    /* c_streq takes care of the rest */
+    return c_streq(e1, e2);
+}
+#endif
 
 static int _csync_detect_update(CSYNC *ctx, const char *file,
     const csync_vio_file_stat_t *fs, const int type) {
@@ -268,7 +288,11 @@ static int _csync_detect_update(CSYNC *ctx, const char *file,
             }
 
             if (tmp && tmp->inode == fs->inode && tmp_vio_type == fs->type
-                    && (tmp->modtime == fs->mtime || fs->type == CSYNC_VIO_FILE_TYPE_DIRECTORY)) {
+                    && (tmp->modtime == fs->mtime || fs->type == CSYNC_VIO_FILE_TYPE_DIRECTORY)
+#ifdef NO_RENAME_EXTENSION
+                    && _csync_sameextension(tmp->path, path)
+#endif
+               ) {
                 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;

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