]> git.sur5r.net Git - minitube/blob - debian/patches/proper-tempfiles
bc4d1251a73549be10220872594e62400a6436a4
[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 362cbd8..bebcd1f 100644
10 --- a/src/temporary.cpp
11 +++ b/src/temporary.cpp
12 @@ -1,7 +1,7 @@
13  #include "temporary.h"
14  #include "constants.h"
15  
16 -static QList<QString> paths;
17 +static QList<QTemporaryFile*> tempfiles;
18  #ifdef Q_WS_X11
19  static QString userName;
20  #endif
21 @@ -10,43 +10,21 @@ Temporary::Temporary() { }
22  
23  QString Temporary::filename() {
24  
25 -    static const QString tempDir = QDesktopServices::storageLocation(QDesktopServices::TempLocation);
26 +    QTemporaryFile *tempfile = new QTemporaryFile(QDir::tempPath() + "/" + Constants::UNIX_NAME + "-XXXXXX");
27  
28 -    QString tempFile = tempDir + "/" + Constants::UNIX_NAME + "-" + QString::number(qrand());
29 +    tempfiles << tempfile;
30  
31 -#ifdef Q_WS_X11
32 -    if (userName.isNull()) {
33 -        userName = QString(getenv("USERNAME"));
34 -        if (userName.isEmpty())
35 -            userName = QString(getenv("USER"));
36 -    }
37 -    if (!userName.isEmpty())
38 -        tempFile += "-" + userName;
39 -#endif
40 -
41 -    // tempFile += ".mp4";
42 -
43 -    if (QFile::exists(tempFile) && !QFile::remove(tempFile)) {
44 -        qDebug() << "Cannot remove temp file" << tempFile;
45 +    if (tempfiles.size() > 1) {
46 +        QTemporaryFile *removedFile = tempfiles.takeFirst();
47 +        delete removedFile;
48      }
49  
50 -    paths << tempFile;
51 -
52 -    if (paths.size() > 1) {
53 -        QString removedFile = paths.takeFirst();
54 -        if (QFile::exists(removedFile) && !QFile::remove(removedFile)) {
55 -            qDebug() << "Cannot remove temp file" << removedFile;
56 -        }
57 -    }
58 -
59 -    return tempFile;
60 -
61 +    tempfile->open();
62 +    return tempfile->fileName();
63  }
64  
65  void Temporary::deleteAll() {
66 -    foreach(QString path, paths) {
67 -        if (QFile::exists(path) && !QFile::remove(path)) {
68 -            qDebug() << "Cannot remove temp file" << path;
69 -        }
70 +    foreach(QTemporaryFile *tempfile, tempfiles) {
71 +        delete tempfile;
72      }
73  }
74 diff --git a/src/temporary.h b/src/temporary.h
75 index 50b9633..0453572 100644
76 --- a/src/temporary.h
77 +++ b/src/temporary.h
78 @@ -3,6 +3,7 @@
79  
80  #include <QtCore>
81  #include <QDesktopServices>
82 +#include <QTemporaryFile>
83  
84  class Temporary {
85