Added fsync for unix/windows in file utils

This commit is contained in:
Jordan Sherer 2020-06-05 11:09:00 -04:00
parent 263d9ccaf6
commit 3bc1fa944c
7 changed files with 34 additions and 2 deletions

View File

@ -215,6 +215,7 @@ set (wsjtx_CXXSRCS
logbook/countrydat.cpp logbook/countrydat.cpp
logbook/countriesworked.cpp logbook/countriesworked.cpp
logbook/logbook.cpp logbook/logbook.cpp
fileutils.cpp
psk_reporter.cpp psk_reporter.cpp
Modulator.cpp Modulator.cpp
Detector.cpp Detector.cpp

11
fileutils.cpp Normal file
View File

@ -0,0 +1,11 @@
#include "fileutils.h"
void flushFileBuffer(const QFile &f){
#ifdef Q_OS_WIN
FlushFileBuffers(reinterpret_cast<HANDLE>(f.handle()));
#elif _POSIX_SYNCHRONIZED_IO > 0
fdatasync(f.handle());
#else
fsync(f.handle());
#endif
}

14
fileutils.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef FILEUTILS_H
#define FILEUTILS_H
#include <QFile>
#ifdef Q_OS_WIN
# include <windows.h>
#else
# include <unistd.h>
# include <sys/stat.h>
#endif
void flushFileBuffer(const QFile &f);
#endif // FILEUTILS_H

View File

@ -93,7 +93,8 @@ SOURCES += \
DecoderThread.cpp \ DecoderThread.cpp \
Decoder.cpp \ Decoder.cpp \
APRSISClient.cpp \ APRSISClient.cpp \
MessageServer.cpp MessageServer.cpp \
fileutils.cpp
HEADERS += qt_helpers.hpp \ HEADERS += qt_helpers.hpp \
pimpl_h.hpp pimpl_impl.hpp \ pimpl_h.hpp pimpl_impl.hpp \
@ -137,7 +138,8 @@ HEADERS += qt_helpers.hpp \
DecoderThread.h \ DecoderThread.h \
Decoder.h \ Decoder.h \
APRSISClient.h \ APRSISClient.h \
MessageServer.h MessageServer.h \
fileutils.h
INCLUDEPATH += qmake_only INCLUDEPATH += qmake_only

View File

@ -394,6 +394,7 @@ bool ADIF::addQSOToFile(QByteArray const& ADIF_record)
out << ADIF_record << " <eor>" << endl; out << ADIF_record << " <eor>" << endl;
out.flush(); out.flush();
flushFileBuffer(f2);
f2.close(); f2.close();
} }
return true; return true;

View File

@ -18,6 +18,8 @@
#include <QtGui> #include <QtGui>
#endif #endif
#include "fileutils.h"
class QDateTime; class QDateTime;
extern const QStringList ADIF_FIELDS; extern const QStringList ADIF_FIELDS;

View File

@ -318,6 +318,7 @@ void LogQSO::accept()
QTextStream out(&f); QTextStream out(&f);
out << logEntryItems.join(",") << endl; out << logEntryItems.join(",") << endl;
out.flush(); out.flush();
flushFileBuffer(f);
f.close(); f.close();
} }