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 a979cbd..bebcd1f 100644
10 --- a/src/temporary.cpp
11 +++ b/src/temporary.cpp
13 #include "temporary.h"
14 #include "constants.h"
16 -static QList<QString> paths;
17 +static QList<QTemporaryFile*> tempfiles;
19 static QString userName;
21 @@ -10,41 +10,21 @@ Temporary::Temporary() { }
23 QString Temporary::filename() {
25 - static const QString tempDir = QDesktopServices::storageLocation(QDesktopServices::TempLocation);
26 + QTemporaryFile *tempfile = new QTemporaryFile(QDir::tempPath() + "/" + Constants::UNIX_NAME + "-XXXXXX");
28 - QString tempFile = tempDir + "/" + Constants::UNIX_NAME + "-" + QString::number(qrand());
29 + tempfiles << tempfile;
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 - if (QFile::exists(tempFile) && !QFile::remove(tempFile)) {
42 - qDebug() << "Cannot remove temp file" << tempFile;
43 + if (tempfiles.size() > 1) {
44 + QTemporaryFile *removedFile = tempfiles.takeFirst();
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;
60 + return tempfile->fileName();
63 void Temporary::deleteAll() {
64 - foreach(QString path, paths) {
65 - if (QFile::exists(path) && !QFile::remove(path)) {
66 - qDebug() << "Cannot remove temp file" << path;
68 + foreach(QTemporaryFile *tempfile, tempfiles) {
72 diff --git a/src/temporary.h b/src/temporary.h
73 index 50b9633..0453572 100644
79 #include <QDesktopServices>
80 +#include <QTemporaryFile>