Description: Do proper temporary file creation Upstream is using predictable temporary file names. Fix this in Debian for now by using QTemporaryFile. This additionally ensures removal of temporary files upon exit. Author: Jakob Haufe Bug-Debian: http://bugs.debian.org/644935 Index: minitube/src/temporary.cpp =================================================================== --- minitube.orig/src/temporary.cpp +++ minitube/src/temporary.cpp @@ -21,51 +21,26 @@ $END_LICENSE */ #include "temporary.h" #include "constants.h" -static QVector paths; -#ifdef APP_LINUX -static QString userName; -#endif +static QList tempfiles; Temporary::Temporary() { } QString Temporary::filename() { - static const QString tempDir = QStandardPaths::writableLocation(QStandardPaths::TempLocation); + QTemporaryFile *tempfile = new QTemporaryFile(QDir::tempPath() + "/" + Constants::UNIX_NAME + "-XXXXXX"); + tempfiles += tempfile; - QString tempFile = tempDir + "/" + Constants::UNIX_NAME + "-" + QString::number(qrand()); - -#ifdef APP_LINUX - if (userName.isNull()) { - userName = QString(getenv("USERNAME")); - if (userName.isEmpty()) - userName = QString(getenv("USER")); - } - if (!userName.isEmpty()) - tempFile += "-" + userName; -#endif - - // tempFile += ".mp4"; - - if (QFile::exists(tempFile) && !QFile::remove(tempFile)) { - qDebug() << "Cannot remove temp file" << tempFile; + if (tempfiles.size() > 1) + { + QTemporaryFile *removedFile = tempfiles.takeFirst(); + delete removedFile; } - paths << tempFile; - - if (paths.size() > 1) { - QString removedFile = paths.takeFirst(); - if (QFile::exists(removedFile) && !QFile::remove(removedFile)) { - qDebug() << "Cannot remove temp file" << removedFile; - } - } - - return tempFile; - + tempfile->open(); + return tempfile->fileName(); } void Temporary::deleteAll() { - foreach(const QString &path, paths) { - if (QFile::exists(path) && !QFile::remove(path)) { - qDebug() << "Cannot remove temp file" << path; - } + foreach(QTemporaryFile *tempfile, tempfiles) { + delete tempfile; } } Index: minitube/src/temporary.h =================================================================== --- minitube.orig/src/temporary.h +++ minitube/src/temporary.h @@ -23,6 +23,7 @@ $END_LICENSE */ #include #include +#include class Temporary {