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
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"
16 -static QList<QString> paths;
18 -static QString userName;
20 +static QList<QTemporaryFile*> tempfiles;
22 Temporary::Temporary() { }
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;
29 - QString tempFile = tempDir + "/" + Constants::UNIX_NAME + "-" + QString::number(qrand());
32 - if (userName.isNull()) {
33 - userName = QString(getenv("USERNAME"));
34 - if (userName.isEmpty())
35 - userName = QString(getenv("USER"));
37 - if (!userName.isEmpty())
38 - tempFile += "-" + userName;
41 - // tempFile += ".mp4";
43 - if (QFile::exists(tempFile) && !QFile::remove(tempFile)) {
44 - qDebug() << "Cannot remove temp file" << tempFile;
45 + if (tempfiles.size() > 1)
47 + QTemporaryFile *removedFile = tempfiles.takeFirst();
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;
63 + return tempfile->fileName();
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;
71 + foreach(QTemporaryFile *tempfile, tempfiles) {
76 diff --git a/src/temporary.h b/src/temporary.h
77 index de5e24d..b8fbba9 100644
80 @@ -23,6 +23,7 @@ $END_LICENSE */
83 #include <QDesktopServices>
84 +#include <QTemporaryFile>