Adding Sync function in sqlite3_bctbx_vfs.

Fixing read functions error cases in lpconfig  and vfs .
This commit is contained in:
Sandrine Avakian 2016-05-13 11:44:46 +02:00
parent fea70fc4ce
commit 16286e82e6
2 changed files with 28 additions and 12 deletions

View file

@ -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);

View file

@ -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();