aqhome-react: peridocally write vars.
This commit is contained in:
@@ -13,14 +13,17 @@
|
||||
|
||||
|
||||
#include "./vars_p.h"
|
||||
#include "./vars_dbread.h"
|
||||
#include "./vars_dbwrite.h"
|
||||
#include "aqhome/data/path.h"
|
||||
|
||||
#include <gwenhywfar/misc.h>
|
||||
#include <gwenhywfar/text.h>
|
||||
#include <gwenhywfar/syncio.h>
|
||||
#include <gwenhywfar/debug.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
|
||||
@@ -52,6 +55,48 @@ static void _appendEscapedString(const char *s, GWEN_BUFFER *dbuf);
|
||||
|
||||
|
||||
|
||||
int AQH_Vars_WriteDbFile(const AQH_VARS *vt, const char *filename)
|
||||
{
|
||||
int rv;
|
||||
GWEN_BUFFER *fbuf;
|
||||
GWEN_BUFFER *dbuf;
|
||||
|
||||
fbuf=GWEN_Buffer_new(0, 256, 0, 1);
|
||||
GWEN_Buffer_AppendString(fbuf, filename);
|
||||
GWEN_Buffer_AppendString(fbuf, ".tmp");
|
||||
|
||||
dbuf=GWEN_Buffer_new(0, 256, 0, 1);
|
||||
rv=AQH_Vars_WriteDbFormat(vt, dbuf);
|
||||
if (rv<0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
|
||||
GWEN_Buffer_free(dbuf);
|
||||
GWEN_Buffer_free(fbuf);
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv=GWEN_SyncIo_Helper_WriteFile(GWEN_Buffer_GetStart(fbuf),
|
||||
(const uint8_t*) GWEN_Buffer_GetStart(dbuf),
|
||||
GWEN_Buffer_GetUsedBytes(dbuf));
|
||||
if (rv<0) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
|
||||
GWEN_Buffer_free(dbuf);
|
||||
GWEN_Buffer_free(fbuf);
|
||||
return rv;
|
||||
}
|
||||
GWEN_Buffer_free(dbuf);
|
||||
|
||||
if (rename(GWEN_Buffer_GetStart(fbuf), filename)) {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "here (%d: %s)", errno, strerror(errno));
|
||||
GWEN_Buffer_free(fbuf);
|
||||
return GWEN_ERROR_IO;
|
||||
}
|
||||
GWEN_Buffer_free(fbuf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int AQH_Vars_WriteDbFormat(const AQH_VARS *vt, GWEN_BUFFER *dbuf)
|
||||
{
|
||||
if (vt && dbuf) {
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <aqhome/data/vars.h>
|
||||
|
||||
|
||||
AQHOME_API int AQH_Vars_WriteDbFile(const AQH_VARS *vt, const char *filename);
|
||||
AQHOME_API int AQH_Vars_WriteDbFormat(const AQH_VARS *vt, GWEN_BUFFER *dbuf);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user