]> git.sur5r.net Git - minitube/blob - debian/patches/proper-tempfiles
f36b48b645f2b3b41bb1ed80584fa6e4e6616a0f
[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 913d244..3e5e89f 100644
10 --- a/src/temporary.cpp
11 +++ b/src/temporary.cpp
12 @@ -22,51 +22,26 @@ $END_LICENSE */
13  #include "constants.h"
14  #include "compatibility/pathsservice.h"
15  
16 -static QList<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 = Paths::getTempLocation();
26 +    QTemporaryFile *tempfile = new QTemporaryFile(QDir::tempPath() + "/" + Constants::UNIX_NAME + "-XXXXXX");
27 +    tempfiles += tempfile;
28  
29 -    QString tempFile = tempDir + "/" + Constants::UNIX_NAME + "-" + QString::number(qrand());
30 -
31 -#ifdef APP_LINUX
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 +    {
47 +        QTemporaryFile *removedFile = tempfiles.takeFirst();
48 +        delete removedFile;
49      }
50  
51 -    paths << tempFile;
52 -
53 -    if (paths.size() > 1) {
54 -        QString removedFile = paths.takeFirst();
55 -        if (QFile::exists(removedFile) && !QFile::remove(removedFile)) {
56 -            qDebug() << "Cannot remove temp file" << removedFile;
57 -        }
58 -    }
59 -
60 -    return tempFile;
61 -
62 +    tempfile->open();
63 +    return tempfile->fileName();
64  }
65  
66  void Temporary::deleteAll() {
67 -    foreach(const QString &path, paths) {
68 -        if (QFile::exists(path) && !QFile::remove(path)) {
69 -            qDebug() << "Cannot remove temp file" << path;
70 -        }
71 +    foreach(QTemporaryFile *tempfile, tempfiles) {
72 +        delete tempfile;
73      }
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