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>
This commit is contained in:
Richard Fuchs 2021-08-02 11:55:53 -04:00 committed by Dirk Hohndel
parent 55bc1938ad
commit cf78e4cb20

View file

@ -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():
}
static QString makeTempFileName()
{
QTemporaryFile tmpfile;
tmpfile.setFileTemplate(QDir::tempPath() + "/divelogsde-upload.XXXXXXXX.dld");
tmpfile.open();
QString filename(tmpfile.fileName());
tmpfile.close();
return filename;
}
void uploadDiveLogsDE::doUpload(bool selected, const QString &userid, const QString &password)
{
QString err;
/* generate a temporary filename and create/open that file with zip_open */
QString filename(QDir::tempPath() + "/divelogsde-upload.dld");
// delete file if it exist
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)) {