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 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"
16 -static QVector<QString> paths;
18 -static QString userName;
20 +static QList<QTemporaryFile*> tempfiles;
22 Temporary::Temporary() { }
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;
29 - QString tempFile = tempDir + "/" + Constants::UNIX_NAME + "-" +
30 - QString::number(QRandomGenerator::global()->generate());
33 - if (userName.isNull()) {
34 - userName = QString(getenv("USERNAME"));
35 - if (userName.isEmpty())
36 - userName = QString(getenv("USER"));
38 - if (!userName.isEmpty())
39 - tempFile += "-" + userName;
42 - // tempFile += ".mp4";
44 - if (QFile::exists(tempFile) && !QFile::remove(tempFile)) {
45 - qDebug() << "Cannot remove temp file" << tempFile;
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;
55 + if(tempfiles.size() > 1)
57 + QTemporaryFile *removedFile = tempfiles.takeFirst();
63 + return tempfile->fileName();
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;
72 + 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>