[Pkg-owncloud-commits] [owncloud-client] 28/175: Propagator: Limit length of temporary file name #2789 (fixup)

Sandro Knauß hefee-guest at moszumanska.debian.org
Sat Aug 8 10:36:23 UTC 2015


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 625e61516f37219410dc035a7db56e05be0deba1
Author: Markus Goetz <markus at woboq.com>
Date:   Mon May 11 15:41:56 2015 +0200

    Propagator: Limit length of temporary file name #2789 (fixup)
    
    Fix 22c35c4d15d31ab6fca3dfe4949ae807182bc481
---
 csync/src/csync_exclude.c         |  1 +
 src/libsync/propagatedownload.cpp | 31 ++++++++++++++++++++-----------
 test/testowncloudpropagator.h     | 26 ++++++++++++++++++++++++++
 3 files changed, 47 insertions(+), 11 deletions(-)

diff --git a/csync/src/csync_exclude.c b/csync/src/csync_exclude.c
index f17e097..484ad80 100644
--- a/csync/src/csync_exclude.c
+++ b/csync/src/csync_exclude.c
@@ -233,6 +233,7 @@ CSYNC_EXCLUDE_TYPE csync_excluded_no_ctx(c_strlist_t *excludes, const char *path
   }
 
   // check the strlen and ignore the file if its name is longer than 254 chars.
+  // whenever changing this also check createDownloadTmpFileName
   if (strlen(bname) > 254) {
       match = CSYNC_FILE_EXCLUDE_LONG_FILENAME;
       SAFE_FREE(bname);
diff --git a/src/libsync/propagatedownload.cpp b/src/libsync/propagatedownload.cpp
index 98a966e..a033748 100644
--- a/src/libsync/propagatedownload.cpp
+++ b/src/libsync/propagatedownload.cpp
@@ -31,19 +31,28 @@
 namespace OCC {
 
 
+// Always coming in with forward slashes.
+// In csync_excluded_no_ctx we ignore all files with longer than 254 chars
+// This function also adds a dot at the begining of the filename to hide the file on OS X and Linux
 QString createDownloadTmpFileName(const QString &previous) {
-    QString tmpFileName = previous;
-    //add a dot at the begining of the filename to hide the file on OS X and Linux
-    int slashPos = tmpFileName.lastIndexOf('/');
-    tmpFileName.insert(slashPos+1, '.');
-    //add the suffix
-    tmpFileName += ".~" + QString::number(uint(qrand()), 16);
-
-    if (tmpFileName.length() > 254) { // https://github.com/owncloud/client/issues/2789
-        tmpFileName = tmpFileName.left(100) + "_" + tmpFileName.right(153);
+    QString tmpFileName;
+    QString tmpPath;
+    int slashPos = previous.lastIndexOf('/');
+    // work with both pathed filenames and only filenames
+    if (slashPos == -1) {
+        tmpFileName = previous;
+        tmpPath = QString();
+    } else {
+        tmpFileName = previous.mid(slashPos+1);
+        tmpPath = previous.left(slashPos);
+    }
+    int overhead =  1 + 1 + 2 + 8; // slash dot dot-tilde ffffffff"
+    int spaceForFileName = qMin(254, tmpFileName.length() + overhead) - overhead;
+    if (tmpPath.length() > 0) {
+        return tmpPath + '/' + '.' + tmpFileName.left(spaceForFileName) + ".~" + (QString::number(uint(qrand() % 0xFFFFFFFF), 16));
+    } else {
+        return '.' + tmpFileName.left(spaceForFileName) + ".~" + (QString::number(uint(qrand() % 0xFFFFFFFF), 16));
     }
-
-    return tmpFileName;
 }
 
 // DOES NOT take owncership of the device.
diff --git a/test/testowncloudpropagator.h b/test/testowncloudpropagator.h
index 71e3a0d..1ffa66a 100644
--- a/test/testowncloudpropagator.h
+++ b/test/testowncloudpropagator.h
@@ -31,9 +31,35 @@ private slots:
     void testTmpDownloadFileNameGeneration()
     {
         QString fn;
+        // without dir
+        for (int i = 1; i <= 1000; i++) {
+            fn+="F";
+            QString tmpFileName = createDownloadTmpFileName(fn);
+            if (tmpFileName.contains('/')) {
+                tmpFileName = tmpFileName.mid(tmpFileName.lastIndexOf('/')+1);
+            }
+            QVERIFY( tmpFileName.length() > 0);
+            QVERIFY( tmpFileName.length() <= 254);
+        }
+        // with absolute dir
+        fn = "/Users/guruz/ownCloud/rocks/GPL";
+        for (int i = 1; i < 1000; i++) {
+            fn+="F";
+            QString tmpFileName = createDownloadTmpFileName(fn);
+            if (tmpFileName.contains('/')) {
+                tmpFileName = tmpFileName.mid(tmpFileName.lastIndexOf('/')+1);
+            }
+            QVERIFY( tmpFileName.length() > 0);
+            QVERIFY( tmpFileName.length() <= 254);
+        }
+        // with relative dir
+        fn = "rocks/GPL";
         for (int i = 1; i < 1000; i++) {
             fn+="F";
             QString tmpFileName = createDownloadTmpFileName(fn);
+            if (tmpFileName.contains('/')) {
+                tmpFileName = tmpFileName.mid(tmpFileName.lastIndexOf('/')+1);
+            }
             QVERIFY( tmpFileName.length() > 0);
             QVERIFY( tmpFileName.length() <= 254);
         }

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