]> git.sur5r.net Git - minitube/blob - debian/patches/proper-tempfiles
Upload 3.9.3-2 to unstable
[minitube] / debian / patches / proper-tempfiles
1 Description: Do proper temporary file creation
2  Upstream is using predictable temporary file names. Fix this in Debian
3  for now by using QTemporaryFile. This additionally ensures removal of
4  temporary files upon exit.
5 Author: Jakob Haufe <sur5r@sur5r.net>
6 Bug-Debian: http://bugs.debian.org/644935
7
8 diff --git a/src/temporary.cpp b/src/temporary.cpp
9 index 2bf7fcd..0561ecb 100644
10 --- a/src/temporary.cpp
11 +++ b/src/temporary.cpp
12 @@ -21,52 +21,27 @@ $END_LICENSE */
13  #include "temporary.h"
14  #include "constants.h"
15  
16 -static QVector<QString> paths;
17 -#ifdef APP_LINUX
18 -static QString userName;
19 -#endif
20 +static QList<QTemporaryFile*> tempfiles;
21  
22  Temporary::Temporary() { }
23  
24  QString Temporary::filename() {
25 -    static const QString tempDir = QStandardPaths::writableLocation(QStandardPaths::TempLocation);
26 +    QTemporaryFile *tempfile = new QTemporaryFile(QDir::tempPath() + "/" + QString::number(qrand()));
27 +    tempfiles += tempfile;
28  
29 -    QString tempFile = tempDir + "/" + Constants::UNIX_NAME + "-" +
30 -                       QString::number(QRandomGenerator::global()->generate());
31 -
32 -#ifdef APP_LINUX
33 -    if (userName.isNull()) {
34 -        userName = QString(getenv("USERNAME"));
35 -        if (userName.isEmpty())
36 -            userName = QString(getenv("USER"));
37 -    }
38 -    if (!userName.isEmpty())
39 -        tempFile += "-" + userName;
40 -#endif
41 -
42 -    // tempFile += ".mp4";
43 -
44 -    if (QFile::exists(tempFile) && !QFile::remove(tempFile)) {
45 -        qDebug() << "Cannot remove temp file" << tempFile;
46 -    }
47 -
48 -    paths << tempFile;
49 -
50 -    if (paths.size() > 1) {
51 -        QString removedFile = paths.takeFirst();
52 -        if (QFile::exists(removedFile) && !QFile::remove(removedFile)) {
53 -            qDebug() << "Cannot remove temp file" << removedFile;
54 -        }
55 +    if(tempfiles.size() > 1)
56 +    {
57 +        QTemporaryFile *removedFile = tempfiles.takeFirst();
58 +        delete removedFile;
59      }
60  
61 -    return tempFile;
62 +    tempfile->open();
63 +    return tempfile->fileName();
64  
65  }
66  
67  void Temporary::deleteAll() {
68 -    foreach(const QString &path, paths) {
69 -        if (QFile::exists(path) && !QFile::remove(path)) {
70 -            qDebug() << "Cannot remove temp file" << path;
71 -        }
72 +    foreach(QTemporaryFile *tempfile, tempfiles) {
73 +        delete tempfile;
74      }
75  }
76 diff --git a/src/temporary.h b/src/temporary.h
77 index de5e24d..b8fbba9 100644
78 --- a/src/temporary.h
79 +++ b/src/temporary.h
80 @@ -23,6 +23,7 @@ $END_LICENSE */
81  
82  #include <QtCore>
83  #include <QDesktopServices>
84 +#include <QTemporaryFile>
85  
86  class Temporary {
87