1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-05 15:55:57 +03:00

When creating a new journal file, open a (read-only) file descriptor on the

directory containing the journal and sync that directory once to make sure
that the journal filename entry gets into the directory.  Ticket #410. (CVS 1066)

FossilOrigin-Name: 09c10fe3c99cffc64ed02c2929f206d99c8e3309
This commit is contained in:
drh
2003-07-27 18:59:42 +00:00
parent 98e3e60012
commit a76c82eb0d
5 changed files with 78 additions and 13 deletions

View File

@@ -18,7 +18,7 @@
** file simultaneously, or one process from reading the database while
** another is writing.
**
** @(#) $Id: pager.c,v 1.86 2003/07/07 10:47:10 drh Exp $
** @(#) $Id: pager.c,v 1.87 2003/07/27 18:59:43 drh Exp $
*/
#include "os.h" /* Must be first to enable large file support */
#include "sqliteInt.h"
@@ -129,6 +129,7 @@ struct PgHdr {
struct Pager {
char *zFilename; /* Name of the database file */
char *zJournal; /* Name of the journal file */
char *zDirectory; /* Directory hold database and journal files */
OsFile fd, jfd; /* File descriptors for database and journal */
OsFile cpfd; /* File descriptor for the checkpoint journal */
int dbSize; /* Number of pages in the file */
@@ -828,7 +829,7 @@ int sqlitepager_open(
char *zFullPathname;
int nameLen;
OsFile fd;
int rc;
int rc, i;
int tempFile;
int readOnly = 0;
char zTemp[SQLITE_TEMPNAME_SIZE];
@@ -855,7 +856,7 @@ int sqlitepager_open(
return SQLITE_CANTOPEN;
}
nameLen = strlen(zFullPathname);
pPager = sqliteMalloc( sizeof(*pPager) + nameLen*2 + 30 );
pPager = sqliteMalloc( sizeof(*pPager) + nameLen*3 + 30 );
if( pPager==0 ){
sqliteOsClose(&fd);
sqliteFree(zFullPathname);
@@ -863,8 +864,12 @@ int sqlitepager_open(
}
SET_PAGER(pPager);
pPager->zFilename = (char*)&pPager[1];
pPager->zJournal = &pPager->zFilename[nameLen+1];
pPager->zDirectory = &pPager->zFilename[nameLen+1];
pPager->zJournal = &pPager->zDirectory[nameLen+1];
strcpy(pPager->zFilename, zFullPathname);
strcpy(pPager->zDirectory, zFullPathname);
for(i=nameLen; i>0 && pPager->zDirectory[i-1]!='/'; i--){}
if( i>0 ) pPager->zDirectory[i-1] = 0;
strcpy(pPager->zJournal, zFullPathname);
sqliteFree(zFullPathname);
strcpy(&pPager->zJournal[nameLen], "-journal");
@@ -995,8 +1000,10 @@ int sqlitepager_close(Pager *pPager){
*/
CLR_PAGER(pPager);
if( pPager->zFilename!=(char*)&pPager[1] ){
assert( 0 ); /* Cannot happen */
sqliteFree(pPager->zFilename);
sqliteFree(pPager->zJournal);
sqliteFree(pPager->zDirectory);
}
sqliteFree(pPager);
return SQLITE_OK;
@@ -1535,6 +1542,7 @@ static int pager_open_journal(Pager *pPager){
pPager->state = SQLITE_READLOCK;
return SQLITE_CANTOPEN;
}
sqliteOsOpenDirectory(pPager->zDirectory, &pPager->jfd);
pPager->journalOpen = 1;
pPager->journalStarted = 0;
pPager->needSync = 0;