1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-07 02:42:48 +03:00

Save the full pathname of the database file so that journalling still works

even if the user changes working directories after opening the databae.
Ticket #200. (CVS 798)

FossilOrigin-Name: 1c58b4fc032c5975dcce9b8ae844c0e516254a17
This commit is contained in:
drh
2002-12-07 21:45:14 +00:00
parent 1a844c380b
commit 3e7a609667
6 changed files with 76 additions and 16 deletions

View File

@@ -1,5 +1,5 @@
C Fix\sa\sbug\sin\sthe\sreverse\sscan\slogic\sthat\scomes\sup\swhen\sthe\stable\sbeing\nscanned\sis\sempty.\s\sAdd\sadditional\stests\sfor\sthe\sreverse\sscan.\s(CVS\s797)
D 2002-12-04T22:29:28
C Save\sthe\sfull\spathname\sof\sthe\sdatabase\sfile\sso\sthat\sjournalling\sstill\sworks\neven\sif\sthe\suser\schanges\sworking\sdirectories\safter\sopening\sthe\sdatabae.\nTicket\s#200.\s(CVS\s798)
D 2002-12-07T21:45:14
F Makefile.in 868c17a1ae1c07603d491274cc8f86c04acf2a1e
F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
@@ -30,9 +30,9 @@ F src/hash.h cd0433998bc1a3759d244e1637fe5a3c13b53bf8
F src/insert.c 764300a0bd8074a2174946c0bf8a550bd833397a
F src/main.c cee05c2ba23b5e78f9671f319dbd68e2130e0f68
F src/md5.c fe4f9c9c6f71dfc26af8da63e4d04489b1430565
F src/os.c cb829aa53e0af81336876a905ce1064f22749277
F src/os.h b7b79563fc55c6d58b703c88ade9ab1504c48bba
F src/pager.c 76a6e5a1d02e3ca5f5b8b22798844436349c2620
F src/os.c 740022806209e44cab0abddfb1fee65c77702e21
F src/os.h 09fd96b4d733aae2f3b98b2ae9ceea40b8fd780d
F src/pager.c 0cbbde8bc4a16a6fc6b17fb7a08789391baa3d2d
F src/pager.h 540833e8cb826b80ce2e39aa917deee5e12db626
F src/parse.y 469c9636ff713e63c00234662209f11668671ae9
F src/printf.c 5c50fc1da75c8f5bf432b1ad17d91d6653acd167
@@ -82,7 +82,7 @@ F test/main.test c66b564554b770ee7fdbf6a66c0cd90329bc2c85
F test/malloc.test 7ba32a9ebd3aeed52ae4aaa6d42ca37e444536fd
F test/memleak.test b4f59aa44488793b00feff2011d77d0f05b22468
F test/minmax.test 29bc5727c3e4c792d5c4745833dd4b505905819e
F test/misc1.test 3c4672069c430d0f21c23385e78ea4e063183aa5
F test/misc1.test 828ea289e37d396432064ab23d2efc6ce660a0f9
F test/misuse.test a3aa2b18a97e4c409a1fcaff5151a4dd804a0162
F test/notnull.test b1f3e42fc475b0b5827b27b2e9b562081995ff30
F test/null.test 5c2b57307e4b6178aae825eb65ddbee01e76b0fd
@@ -152,7 +152,7 @@ F www/speed.tcl a20a792738475b68756ea7a19321600f23d1d803
F www/sqlite.tcl ae3dcfb077e53833b59d4fcc94d8a12c50a44098
F www/tclsqlite.tcl 1db15abeb446aad0caf0b95b8b9579720e4ea331
F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218
P bfb9a2aa939ecffc5dc2c7c23bddd57d357bdf13
R e8e5bb54da6e21aac3b570ab92f52726
P 0051c87d5e8d07fae09da2eb7b0d8cbd1bbd3c8e
R 1755863d930db2fe172862e1ab561a27
U drh
Z ef156328459f096ede699892581cbeef
Z 6749b35c841c31daf6e1b7e300d04efa

View File

@@ -1 +1 @@
0051c87d5e8d07fae09da2eb7b0d8cbd1bbd3c8e
1c58b4fc032c5975dcce9b8ae844c0e516254a17

View File

@@ -20,6 +20,7 @@
#if OS_UNIX
# include <time.h>
# include <errno.h>
# include <unistd.h>
# ifndef O_LARGEFILE
# define O_LARGEFILE 0
# endif
@@ -970,3 +971,32 @@ void sqliteOsLeaveMutex(){
LeaveCriticalSection(&cs);
#endif
}
/*
** Turn a relative pathname into a full pathname. Return a pointer
** to the full pathname stored in space obtained from sqliteMalloc().
** The calling function is responsible for freeing this space once it
** is no longer needed.
*/
char *sqliteOsFullPathname(const char *zRelative){
#if OS_UNIX
char *zFull = 0;
if( zRelative[0]=='/' ){
sqliteSetString(&zFull, zRelative, 0);
}else{
char zBuf[5000];
sqliteSetString(&zFull, getcwd(zBuf, sizeof(zBuf)), "/", zRelative, 0);
}
return zFull;
#endif
#if OS_WIN
char *zNotUsed;
char *zFull;
int nByte;
nByte = GetFullPathName(zRelative, 0, 0, &zNotUsed);
zFull = sqliteMalloc( nByte );
if( zFull==0 ) return 0;
GetFullPathName(zRelative, nByte, zFull, &zNotUsed);
return zFull;
#endif
}

View File

@@ -115,6 +115,7 @@ int sqliteOsRandomSeed(char*);
int sqliteOsSleep(int ms);
void sqliteOsEnterMutex(void);
void sqliteOsLeaveMutex(void);
char *sqliteOsFullPathname(const char*);

View File

@@ -18,7 +18,7 @@
** file simultaneously, or one process from reading the database while
** another is writing.
**
** @(#) $Id: pager.c,v 1.60 2002/12/02 04:25:21 drh Exp $
** @(#) $Id: pager.c,v 1.61 2002/12/07 21:45:14 drh Exp $
*/
#include "os.h" /* Must be first to enable large file support */
#include "sqliteInt.h"
@@ -626,6 +626,7 @@ int sqlitepager_open(
int useJournal /* TRUE to use a rollback journal on this file */
){
Pager *pPager;
char *zFullPathname;
int nameLen;
OsFile fd;
int rc;
@@ -638,26 +639,34 @@ int sqlitepager_open(
return SQLITE_NOMEM;
}
if( zFilename ){
rc = sqliteOsOpenReadWrite(zFilename, &fd, &readOnly);
zFullPathname = sqliteOsFullPathname(zFilename);
rc = sqliteOsOpenReadWrite(zFullPathname, &fd, &readOnly);
tempFile = 0;
}else{
rc = sqlitepager_opentemp(zTemp, &fd);
zFilename = zTemp;
zFullPathname = sqliteOsFullPathname(zFilename);
tempFile = 1;
}
if( sqlite_malloc_failed ){
return SQLITE_NOMEM;
}
if( rc!=SQLITE_OK ){
sqliteFree(zFullPathname);
return SQLITE_CANTOPEN;
}
nameLen = strlen(zFilename);
nameLen = strlen(zFullPathname);
pPager = sqliteMalloc( sizeof(*pPager) + nameLen*2 + 30 );
if( pPager==0 ){
sqliteOsClose(&fd);
sqliteFree(zFullPathname);
return SQLITE_NOMEM;
}
pPager->zFilename = (char*)&pPager[1];
pPager->zJournal = &pPager->zFilename[nameLen+1];
strcpy(pPager->zFilename, zFilename);
strcpy(pPager->zJournal, zFilename);
strcpy(pPager->zFilename, zFullPathname);
strcpy(pPager->zJournal, zFullPathname);
sqliteFree(zFullPathname);
strcpy(&pPager->zJournal[nameLen], "-journal");
pPager->fd = fd;
pPager->journalOpen = 0;

View File

@@ -13,7 +13,7 @@
# This file implements tests for miscellanous features that were
# left out of other test files.
#
# $Id: misc1.test,v 1.16 2002/10/22 23:38:04 drh Exp $
# $Id: misc1.test,v 1.17 2002/12/07 21:45:14 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -440,4 +440,24 @@ do_test misc1-13.1 {
}
} {1 2 3 4 5 6 7 8 9 10 11}
# Make sure a database connection still works after changing the
# working directory.
#
do_test misc1-14.1 {
file mkdir tempdir
cd tempdir
execsql {BEGIN}
file exists ./test.db-journal
} {0}
do_test misc1-14.2 {
file exists ../test.db-journal
} {1}
do_test misc1-14.3 {
cd ..
file delete tempdir
execsql {COMMIT}
file exists ./test.db-journal
} {0}
finish_test