mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 14:25:27 +00:00
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:
parent
55bc1938ad
commit
cf78e4cb20
1 changed files with 13 additions and 11 deletions
|
@ -2,6 +2,7 @@
|
||||||
#include "uploadDiveLogsDE.h"
|
#include "uploadDiveLogsDE.h"
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QTemporaryFile>
|
||||||
#include <zip.h>
|
#include <zip.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include "core/display.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)
|
void uploadDiveLogsDE::doUpload(bool selected, const QString &userid, const QString &password)
|
||||||
{
|
{
|
||||||
QString err;
|
QString err;
|
||||||
|
|
||||||
|
QString filename = makeTempFileName();
|
||||||
/* 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();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make zip file, with all dives, in divelogs.de format
|
// Make zip file, with all dives, in divelogs.de format
|
||||||
if (!prepareDives(filename, selected)) {
|
if (!prepareDives(filename, selected)) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue