diff options
author | mistachkin <mistachkin@noemail.net> | 2018-07-22 06:25:35 +0000 |
---|---|---|
committer | mistachkin <mistachkin@noemail.net> | 2018-07-22 06:25:35 +0000 |
commit | 1e8487db29c940d07e2826a0663d72047a0104ea (patch) | |
tree | 7dfa2e4f7213c052885168e284f1d7dc9e118946 /src | |
parent | 9676e611b647dc0d871aa3b5632e228c7d9e4679 (diff) | |
download | sqlite-1e8487db29c940d07e2826a0663d72047a0104ea.tar.gz sqlite-1e8487db29c940d07e2826a0663d72047a0104ea.zip |
In the Win32 VFS, when truncating a file, unmap it first.
FossilOrigin-Name: 21510a66dce4d0843ccfe20f092a01f5a52563ef244a94f1d5d2563305cab925
Diffstat (limited to 'src')
-rw-r--r-- | src/os_win.c | 24 | ||||
-rw-r--r-- | src/shell.c.in | 20 | ||||
-rw-r--r-- | src/tclsqlite.c | 21 |
3 files changed, 54 insertions, 11 deletions
diff --git a/src/os_win.c b/src/os_win.c index 3eb2f3c61..2a4b613ff 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -2904,6 +2904,9 @@ static int winTruncate(sqlite3_file *id, sqlite3_int64 nByte){ winFile *pFile = (winFile*)id; /* File handle object */ int rc = SQLITE_OK; /* Return code for this function */ DWORD lastErrno; +#if SQLITE_MAX_MMAP_SIZE>0 + sqlite3_int64 oldMmapSize; +#endif assert( pFile ); SimulateIOError(return SQLITE_IOERR_TRUNCATE); @@ -2919,6 +2922,15 @@ static int winTruncate(sqlite3_file *id, sqlite3_int64 nByte){ nByte = ((nByte + pFile->szChunk - 1)/pFile->szChunk) * pFile->szChunk; } +#if SQLITE_MAX_MMAP_SIZE>0 + if( pFile->pMapRegion ){ + oldMmapSize = pFile->mmapSize; + }else{ + oldMmapSize = 0; + } + winUnmapfile(pFile); +#endif + /* SetEndOfFile() returns non-zero when successful, or zero when it fails. */ if( winSeekFile(pFile, nByte) ){ rc = winLogError(SQLITE_IOERR_TRUNCATE, pFile->lastErrno, @@ -2931,12 +2943,12 @@ static int winTruncate(sqlite3_file *id, sqlite3_int64 nByte){ } #if SQLITE_MAX_MMAP_SIZE>0 - /* If the file was truncated to a size smaller than the currently - ** mapped region, reduce the effective mapping size as well. SQLite will - ** use read() and write() to access data beyond this point from now on. - */ - if( pFile->pMapRegion && nByte<pFile->mmapSize ){ - pFile->mmapSize = nByte; + if( rc==SQLITE_OK && oldMmapSize>0 ){ + if( oldMmapSize>nByte ){ + winMapfile(pFile, -1); + }else{ + winMapfile(pFile, oldMmapSize); + } } #endif diff --git a/src/shell.c.in b/src/shell.c.in index ab1ec6af7..59ea6aac0 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -79,12 +79,15 @@ typedef unsigned char u8; #if (!defined(_WIN32) && !defined(WIN32)) || defined(__MINGW32__) # include <unistd.h> # include <dirent.h> +# define GETPID getpid # if defined(__MINGW32__) # define DIRENT dirent # ifndef S_ISLNK # define S_ISLNK(mode) (0) # endif # endif +#else +# define GETPID (int)GetCurrentProcessId #endif #include <sys/types.h> #include <sys/stat.h> @@ -8348,6 +8351,23 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ stdin_is_interactive = isatty(0); stdout_is_console = isatty(1); +#if !defined(_WIN32_WCE) + if( getenv("SQLITE_DEBUG_BREAK") ){ + if( isatty(0) && isatty(2) ){ + fprintf(stderr, + "attach debugger to process %d and press any key to continue.\n", + GETPID()); + fgetc(stdin); + }else{ +#if defined(_WIN32) || defined(WIN32) + DebugBreak(); +#elif defined(SIGTRAP) + raise(SIGTRAP); +#endif + } + } +#endif + #if USE_SYSTEM_SQLITE+0!=1 if( strncmp(sqlite3_sourceid(),SQLITE_SOURCE_ID,60)!=0 ){ utf8_printf(stderr, "SQLite header and source version mismatch\n%s\n%s\n", diff --git a/src/tclsqlite.c b/src/tclsqlite.c index e5984ec80..d0b4634d4 100644 --- a/src/tclsqlite.c +++ b/src/tclsqlite.c @@ -60,6 +60,7 @@ /* Used to get the current process ID */ #if !defined(_WIN32) +# include <signal.h> # include <unistd.h> # define GETPID getpid #elif !defined(_WIN32_WCE) @@ -69,6 +70,8 @@ # endif # include <windows.h> # endif +# include <io.h> +# define isatty(h) _isatty(h) # define GETPID (int)GetCurrentProcessId #endif @@ -3733,11 +3736,19 @@ int SQLITE_CDECL TCLSH_MAIN(int argc, char **argv){ #endif #if !defined(_WIN32_WCE) - if( getenv("BREAK") ){ - fprintf(stderr, - "attach debugger to process %d and press any key to continue.\n", - GETPID()); - fgetc(stdin); + if( getenv("SQLITE_DEBUG_BREAK") ){ + if( isatty(0) && isatty(2) ){ + fprintf(stderr, + "attach debugger to process %d and press any key to continue.\n", + GETPID()); + fgetc(stdin); + }else{ +#if defined(_WIN32) || defined(WIN32) + DebugBreak(); +#elif defined(SIGTRAP) + raise(SIGTRAP); +#endif + } } #endif |