From 16286e82e6cb8a16cd66d432d6da0d4be7b9a71b Mon Sep 17 00:00:00 2001 From: Sandrine Avakian Date: Fri, 13 May 2016 11:44:46 +0200 Subject: [PATCH] Adding Sync function in sqlite3_bctbx_vfs. Fixing read functions error cases in lpconfig and vfs . --- coreapi/lpconfig.c | 4 ++-- coreapi/sqlite3_bctbx_vfs.c | 36 ++++++++++++++++++++++++++---------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/coreapi/lpconfig.c b/coreapi/lpconfig.c index 4155951c0..cb9fffa01 100644 --- a/coreapi/lpconfig.c +++ b/coreapi/lpconfig.c @@ -365,7 +365,7 @@ void lp_config_parse(LpConfig *lpconfig, bctbx_vfs_file* pFile){ LpSection* current_section = NULL; int size =0; if (pFile==NULL) return; - while(( size = bctbx_file_get_nxtline(lpconfig->pFile, tmp, MAX_LEN)) > 0){ + while(( size = bctbx_file_get_nxtline(pFile, tmp, MAX_LEN)) > 0){ tmp[size] = '\0'; current_section = lp_config_parse_line(lpconfig, tmp, current_section); } @@ -462,7 +462,7 @@ int lp_config_read_file(LpConfig *lpconfig, const char *filename){ int fd=-1; bctbx_vfs_file* pFile = bctbx_file_open(lpconfig->g_bctbx_vfs, path, "r"); fd = pFile->fd; - if (fd < 0){ + if (fd > 0){ ms_message("Reading config information from %s", path); lp_config_parse(lpconfig, pFile); bctbx_file_close(pFile); diff --git a/coreapi/sqlite3_bctbx_vfs.c b/coreapi/sqlite3_bctbx_vfs.c index a89dd044a..06435c300 100644 --- a/coreapi/sqlite3_bctbx_vfs.c +++ b/coreapi/sqlite3_bctbx_vfs.c @@ -187,6 +187,20 @@ static int sqlite3bctbx_nolockUnlock(sqlite3_file *pUnused, int unused){ } +/** + * Simple sync the file contents to the persistent media. + * @param pFile [description] + * @param flags [description] + * @return [description] + */ +static int sqlite3bctbx_Sync(sqlite3_file *p, int flags){ + sqlite3_bctbx_file *pFile = (sqlite3_bctbx_file*)p; + int rc; + + rc = fsync(pFile->bctbx_file.fd); + return (rc==0 ? SQLITE_OK : SQLITE_IOERR_FSYNC); +} + /** * [sqlite3bctbx_Open description] @@ -202,7 +216,7 @@ static int sqlite3bctbx_Open(sqlite3_vfs *pVfs, const char *fName, sqlite3_file sqlite3bctbx_Read, /* xRead */ sqlite3bctbx_Write, /* xWrite */ 0, - 0, + sqlite3bctbx_Sync, sqlite3bctbx_FileSize, /* xFileSize */ sqlite3bctbx_nolockLock, sqlite3bctbx_nolockUnlock, @@ -211,22 +225,24 @@ static int sqlite3bctbx_Open(sqlite3_vfs *pVfs, const char *fName, sqlite3_file 0, sqlite3bctbx_DeviceCharacteristics, }; - int oflags = 0; + sqlite3_bctbx_file * pFile = (sqlite3_bctbx_file*)p; + + int openFlags = 0; + + if (pFile == NULL || fName == NULL){ return SQLITE_IOERR; } - if( flags&SQLITE_OPEN_EXCLUSIVE ) oflags |= O_EXCL; - if( flags&SQLITE_OPEN_CREATE ) oflags |= O_CREAT; - if( flags&SQLITE_OPEN_READONLY ) oflags |= O_RDONLY; - if( flags&SQLITE_OPEN_READWRITE ) oflags |= O_RDWR; + if( flags&SQLITE_OPEN_EXCLUSIVE ) openFlags |= (O_EXCL|O_NOFOLLOW); + if( flags&SQLITE_OPEN_CREATE ) openFlags |= O_CREAT; + if( flags&SQLITE_OPEN_READONLY ) openFlags |= O_RDONLY; + if( flags&SQLITE_OPEN_READWRITE ) openFlags |= O_RDWR; - - - pFile->bctbx_file.fd = open(fName, flags, S_IRUSR | S_IWUSR); + pFile->bctbx_file.fd = open(fName, openFlags, S_IRUSR | S_IWUSR); if( pFile->bctbx_file.fd < 0 ){ return SQLITE_CANTOPEN; } @@ -235,7 +251,7 @@ static int sqlite3bctbx_Open(sqlite3_vfs *pVfs, const char *fName, sqlite3_file // return SQLITE_CANTOPEN; // } if( pOutFlags ){ - *pOutFlags = oflags; + *pOutFlags = flags; } pFile->base.pMethods = &sqlite3_bctbx_io; pFile->bctbx_file.pMethods = get_bcio();