Call OS functions to really flush the database to disk

git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@283 b624d157-de02-0410-bad0-e51aec6abb33
master
sniperbeamer 16 years ago
parent c6fbc412be
commit a2efb4f3b0
  1. 3
      src/Kdb3Database.cpp
  2. 14
      src/lib/tools.cpp
  3. 5
      src/lib/tools.h

@ -1464,7 +1464,8 @@ bool Kdb3Database::save(){
error=decodeFileError(File->error());
return false;
}
File->flush();
if (!syncFile(File))
qWarning("Unable to flush file to disk");
delete [] buffer;
//if(SearchGroupID!=-1)Groups.push_back(SearchGroup);

@ -24,8 +24,10 @@
#if defined(Q_WS_X11) || defined(Q_WS_MAC)
#include <sys/mman.h>
#include <unistd.h>
#elif defined(Q_WS_WIN)
#include <windows.h>
#include <io.h>
#endif
void createBanner(QPixmap* Pixmap,const QPixmap* IconAlpha,const QString& Text,int Width){
@ -236,6 +238,18 @@ bool unlockPage(void* addr, int len){
#endif
}
bool syncFile(QFile* file) {
if (!file->flush())
return false;
#if defined(Q_WS_X11) || defined(Q_WS_MAC)
return (fsync(file->handle())==0);
#elif defined(Q_WS_WIN)
return (_commit(file->handle())==0);
#else
return false;
#endif
}
QTranslator* translator = new QTranslator();
QTranslator* qtTranslator = new QTranslator();
bool translatorActive = false;

@ -30,9 +30,7 @@ struct Translation {
};
bool operator<(const Translation& t1, const Translation& t2);
inline const char* CSTR(const QString& str) {
return QTextCodec::codecForLocale()->fromUnicode(str).constData();
}
#define CSTR(x)(QTextCodec::codecForLocale()->fromUnicode(x).constData())
const QIcon& getIcon(const QString& name);
const QPixmap* getPixmap(const QString& name);
@ -48,6 +46,7 @@ QString getImageFile(const QString& name);
bool createKeyFile(const QString& filename,QString* err, int length=32, bool Hex=true);
bool lockPage(void* addr, int len);
bool unlockPage(void* addr, int len);
bool syncFile(QFile* file);
void installTranslator();
bool isTranslationActive();
QList<Translation> getAllTranslations();