From cf78e4cb206d1053800c29fd4f147b048510beb3 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Mon, 2 Aug 2021 11:55:53 -0400 Subject: export: use unique temporary file for divelogs.de upload On multi-user systems with a shared directory for temporary files, using a static file name can lead to permissions problems and subsequent errors due to collisions. Use a random unique file name for each generated file to avoid these problems. Note: the temporary file generated from the divelogs.de upload is still left behind after the upload finishes. Signed-off-by: Richard Fuchs --- core/uploadDiveLogsDE.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/core/uploadDiveLogsDE.cpp b/core/uploadDiveLogsDE.cpp index fc8ead6c3..a9c39bf11 100644 --- a/core/uploadDiveLogsDE.cpp +++ b/core/uploadDiveLogsDE.cpp @@ -2,6 +2,7 @@ #include "uploadDiveLogsDE.h" #include #include +#include #include #include #include "core/display.h" @@ -34,21 +35,22 @@ uploadDiveLogsDE::uploadDiveLogsDE(): } -void uploadDiveLogsDE::doUpload(bool selected, const QString &userid, const QString &password) +static QString makeTempFileName() { - QString err; - + QTemporaryFile tmpfile; + tmpfile.setFileTemplate(QDir::tempPath() + "/divelogsde-upload.XXXXXXXX.dld"); + tmpfile.open(); + QString filename(tmpfile.fileName()); + tmpfile.close(); + return filename; +} - /* generate a temporary filename and create/open that file with zip_open */ - QString filename(QDir::tempPath() + "/divelogsde-upload.dld"); - // delete file if it exist +void uploadDiveLogsDE::doUpload(bool selected, const QString &userid, const QString &password) +{ + QString err; - QFile f(filename); - if (f.open(QIODevice::ReadOnly)) { - f.close(); - f.remove(); - } + QString filename = makeTempFileName(); // Make zip file, with all dives, in divelogs.de format if (!prepareDives(filename, selected)) { -- cgit v1.2.3-70-g09d2