aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Richard Fuchs <dfx@dfx.at>2021-08-02 11:55:53 -0400
committerGravatar Dirk Hohndel <dirk@hohndel.org>2021-08-03 08:34:18 -0700
commitcf78e4cb206d1053800c29fd4f147b048510beb3 (patch)
tree55f8f366ef8df9c90a3301aef07cb1c2f5ebc90f
parent55bc1938adade6488c2deacf6d88b66d0780299e (diff)
downloadsubsurface-cf78e4cb206d1053800c29fd4f147b048510beb3.tar.gz
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 <dfx@dfx.at>
-rw-r--r--core/uploadDiveLogsDE.cpp24
1 files 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 <QDir>
#include <QDebug>
+#include <QTemporaryFile>
#include <zip.h>
#include <errno.h>
#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)) {