[Pkg-owncloud-commits] [owncloud-client] 23/175: Propagator: Limit length of temporary file name #2789

Sandro Knauß hefee-guest at moszumanska.debian.org
Sat Aug 8 10:36:22 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 22c35c4d15d31ab6fca3dfe4949ae807182bc481
Author: Markus Goetz <markus at woboq.com>
Date:   Fri May 8 16:41:41 2015 +0200

    Propagator: Limit length of temporary file name #2789
---
 src/libsync/propagatedownload.cpp | 23 +++++++++++++++++------
 test/testowncloudpropagator.h     | 18 ++++++++++++++++++
 2 files changed, 35 insertions(+), 6 deletions(-)

diff --git a/src/libsync/propagatedownload.cpp b/src/libsync/propagatedownload.cpp
index 9e2f5fe..98a966e 100644
--- a/src/libsync/propagatedownload.cpp
+++ b/src/libsync/propagatedownload.cpp
@@ -30,6 +30,22 @@
 
 namespace OCC {
 
+
+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);
+    }
+
+    return tmpFileName;
+}
+
 // DOES NOT take owncership of the device.
 GETFileJob::GETFileJob(AccountPtr account, const QString& path, QFile *device,
                     const QMap<QByteArray, QByteArray> &headers, const QByteArray &expectedEtagForResume,
@@ -307,12 +323,7 @@ void PropagateDownloadFileQNAM::start()
     }
 
     if (tmpFileName.isEmpty()) {
-        tmpFileName = _item._file;
-        //add a dot at the begining of the filename to hide the file.
-        int slashPos = tmpFileName.lastIndexOf('/');
-        tmpFileName.insert(slashPos+1, '.');
-        //add the suffix
-        tmpFileName += ".~" + QString::number(uint(qrand()), 16);
+        tmpFileName = createDownloadTmpFileName(_item._file);
     }
 
     _tmpFile.setFileName(_propagator->getFilePath(tmpFileName));
diff --git a/test/testowncloudpropagator.h b/test/testowncloudpropagator.h
index bbbd263..71e3a0d 100644
--- a/test/testowncloudpropagator.h
+++ b/test/testowncloudpropagator.h
@@ -8,7 +8,14 @@
 #define MIRALL_TESTOWNCLOUDPROPAGATOR_H
 
 #include <QtTest>
+#include <QDebug>
 
+#include "propagatedownload.h"
+
+using namespace OCC;
+namespace OCC {
+QString createDownloadTmpFileName(const QString &previous);
+}
 
 class TestOwncloudPropagator : public QObject
 {
@@ -20,6 +27,17 @@ private slots:
 //        OwncloudPropagator propagator( NULL, QLatin1String("test1"), QLatin1String("test2"), new ProgressDatabase);
         QVERIFY( true );
     }
+
+    void testTmpDownloadFileNameGeneration()
+    {
+        QString fn;
+        for (int i = 1; i < 1000; i++) {
+            fn+="F";
+            QString tmpFileName = createDownloadTmpFileName(fn);
+            QVERIFY( tmpFileName.length() > 0);
+            QVERIFY( tmpFileName.length() <= 254);
+        }
+    }
 };
 
 #endif

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