]> git.sur5r.net Git - minitube/blob - debian/patches/proper-tempfiles
Imported Debian patch 1.6-1
[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 a979cbd..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,41 +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 -    if (QFile::exists(tempFile) && !QFile::remove(tempFile)) {
42 -        qDebug() << "Cannot remove temp file" << tempFile;
43 +    if (tempfiles.size() > 1) {
44 +        QTemporaryFile *removedFile = tempfiles.takeFirst();
45 +        delete removedFile;
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 -    }
56 -
57 -    return tempFile;
58 -
59 +    tempfile->open();
60 +    return tempfile->fileName();
61  }
62  
63  void Temporary::deleteAll() {
64 -    foreach(QString path, paths) {
65 -        if (QFile::exists(path) && !QFile::remove(path)) {
66 -            qDebug() << "Cannot remove temp file" << path;
67 -        }
68 +    foreach(QTemporaryFile *tempfile, tempfiles) {
69 +        delete tempfile;
70      }
71  }
72 diff --git a/src/temporary.h b/src/temporary.h
73 index 50b9633..0453572 100644
74 --- a/src/temporary.h
75 +++ b/src/temporary.h
76 @@ -3,6 +3,7 @@
77  
78  #include <QtCore>
79  #include <QDesktopServices>
80 +#include <QTemporaryFile>
81  
82  class Temporary {
83