[Pkg-owncloud-commits] [owncloud-client] 55/70: Revert "csync file util: Remove compare file function, not needed anymore."

Sandro Knauß hefee-guest at moszumanska.debian.org
Tue Jul 1 10:21:23 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 b29a757b18e86eeb3b5ebfe676d2e8bb150a10c4
Author: Olivier Goffart <ogoffart at woboq.com>
Date:   Fri Jun 20 14:29:43 2014 +0200

    Revert "csync file util: Remove compare file function, not needed anymore."
    
    This break the test.
    And the function is aleady gone in master anyway
    
    This reverts commit 407b3bebfeb8f9f0493382c9f9cd2216e134107e.
---
 csync/src/std/c_file.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++
 csync/src/std/c_file.h | 10 ++++++
 2 files changed, 94 insertions(+)

diff --git a/csync/src/std/c_file.c b/csync/src/std/c_file.c
index 7745a34..61984b3 100644
--- a/csync/src/std/c_file.c
+++ b/csync/src/std/c_file.c
@@ -260,3 +260,87 @@ int c_rename( const char *src, const char *dst ) {
 
     return rc;
 }
+
+int c_compare_file( const char *f1, const char *f2 ) {
+  mbchar_t *wf1, *wf2;
+  int fd1 = -1, fd2 = -1;
+  size_t size1, size2;
+  char buffer1[BUFFER_SIZE];
+  char buffer2[BUFFER_SIZE];
+  csync_stat_t stat1;
+  csync_stat_t stat2;
+
+  int rc = -1;
+
+  if(f1 == NULL || f2 == NULL) return -1;
+
+  wf1 = c_utf8_to_locale(f1);
+  if(wf1 == NULL) {
+    return -1;
+  }
+
+  wf2 = c_utf8_to_locale(f2);
+  if(wf2 == NULL) {
+    c_free_locale_string(wf1);
+    return -1;
+  }
+
+#ifdef _WIN32
+  _fmode = _O_BINARY;
+#endif
+
+  fd1 = _topen(wf1, O_RDONLY);
+  if(fd1 < 0) {
+    rc = -1;
+    goto out;
+  }
+
+  fd2 = _topen(wf2, O_RDONLY);
+  if(fd2 < 0) {
+    rc = -1;
+    goto out;
+  }
+
+  /* compare size first. */
+  rc = _tfstat(fd1, &stat1);
+  if (rc < 0) {
+    goto out;
+  }
+
+  rc = _tfstat(fd2, &stat2);
+  if (rc < 0) {
+    goto out;
+  }
+
+  /* if sizes are different, the files can not be equal. */
+  if (stat1.st_size != stat2.st_size) {
+    rc = 0;
+    goto out;
+  }
+
+  while( (size1 = read(fd1, buffer1, BUFFER_SIZE)) > 0 ) {
+    size2 = read( fd2, buffer2, BUFFER_SIZE );
+
+    if( size1 != size2 ) {
+      rc = 0;
+      goto out;
+    }
+    if(memcmp(buffer1, buffer2, size1) != 0) {
+      /* buffers are different */
+      rc = 0;
+      goto out;
+    }
+  }
+
+  rc = 1;
+
+out:
+
+  if(fd1 > -1) close(fd1);
+  if(fd2 > -1) close(fd2);
+
+  c_free_locale_string( wf1 );
+  c_free_locale_string( wf2 );
+  return rc;
+
+}
diff --git a/csync/src/std/c_file.h b/csync/src/std/c_file.h
index 1a32249..d952b39 100644
--- a/csync/src/std/c_file.h
+++ b/csync/src/std/c_file.h
@@ -76,6 +76,16 @@ int c_isfile(const char *path);
 int c_copy(const char *src, const char *dst, mode_t mode);
 
 /**
+ * @brief Compare the content of two files byte by byte.
+ * @param f1     Path of file 1
+ * @param f2     Path of file 2
+ *
+ * @return       0 if the files differ, 1 if the files are equal or -1 on
+ *               error with errno set.
+ */
+int c_compare_file( const char *f1, const char *f2 );
+
+/**
  * @brief move a file from source to destination.
  *
  * @param src    Path to the source file

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