1 From edfff157e1d9292bfcce6553b76ee913b53b1aa1 Mon Sep 17 00:00:00 2001
2 From: mrossetti <mrossetti@chromium.org>
3 Date: Tue, 31 May 2011 23:12:11 +0000
4 Subject: [PATCH 04/16] Exclude journal file from Time Machine if database is
9 Original review URL: http://codereview.chromium.org/6990066
11 TODO(shess): The fts3_porter.c change is due to a conflict with an included
12 Apple library. Perhaps move the operative code to a .c file, and firewall
13 SQLite from that include.
15 TODO(shess): Revisit this for -wal mode. http://crbug.com/78507
17 third_party/sqlite/src/Makefile.linux-gcc | 4 ++++
18 third_party/sqlite/src/ext/fts3/fts3_porter.c | 6 ++---
19 third_party/sqlite/src/main.mk | 2 +-
20 third_party/sqlite/src/src/pager.c | 32 +++++++++++++++++++++++++++
21 third_party/sqlite/src/src/sqliteInt.h | 10 +++++++++
22 5 files changed, 50 insertions(+), 4 deletions(-)
24 diff --git a/third_party/sqlite/src/Makefile.linux-gcc b/third_party/sqlite/src/Makefile.linux-gcc
25 index 6d67ba7..554bf56 100644
26 --- a/third_party/sqlite/src/Makefile.linux-gcc
27 +++ b/third_party/sqlite/src/Makefile.linux-gcc
28 @@ -44,7 +44,11 @@ THREADLIB = -lpthread
29 #### Specify any extra libraries needed to access required functions.
31 #TLIBS = -lrt # fdatasync on Solaris 8
32 +ifeq ($(shell uname -s),Darwin)
33 +TLIBS = -framework CoreServices
38 #### Leave SQLITE_DEBUG undefined for maximum speed. Use SQLITE_DEBUG=1
39 # to check for memory leaks. Use SQLITE_DEBUG=2 to print a log of all
40 diff --git a/third_party/sqlite/src/ext/fts3/fts3_porter.c b/third_party/sqlite/src/ext/fts3/fts3_porter.c
41 index db175ac..933602a 100644
42 --- a/third_party/sqlite/src/ext/fts3/fts3_porter.c
43 +++ b/third_party/sqlite/src/ext/fts3/fts3_porter.c
44 @@ -128,7 +128,7 @@ static int porterClose(sqlite3_tokenizer_cursor *pCursor){
48 -static const char cType[] = {
49 +static const char vOrCType[] = {
50 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0,
53 @@ -152,7 +152,7 @@ static int isConsonant(const char *z){
56 assert( x>='a' && x<='z' );
58 + j = vOrCType[x-'a'];
60 return z[1]==0 || isVowel(z + 1);
62 @@ -161,7 +161,7 @@ static int isVowel(const char *z){
65 assert( x>='a' && x<='z' );
67 + j = vOrCType[x-'a'];
69 return isConsonant(z + 1);
71 diff --git a/third_party/sqlite/src/main.mk b/third_party/sqlite/src/main.mk
72 index 4a7ac02..dc56b0d 100644
73 --- a/third_party/sqlite/src/main.mk
74 +++ b/third_party/sqlite/src/main.mk
75 @@ -591,7 +591,7 @@ TESTFIXTURE_FLAGS += -DSQLITE_SERVER=1 -DSQLITE_PRIVATE="" -DSQLITE_CORE
76 testfixture$(EXE): $(TESTSRC2) libsqlite3.a $(TESTSRC) $(TOP)/src/tclsqlite.c
77 $(TCCX) $(TCL_FLAGS) -DTCLSH=1 $(TESTFIXTURE_FLAGS) \
78 $(TESTSRC) $(TESTSRC2) $(TOP)/src/tclsqlite.c \
79 - -o testfixture$(EXE) $(LIBTCL) libsqlite3.a $(THREADLIB)
80 + -o testfixture$(EXE) $(LIBTCL) libsqlite3.a $(THREADLIB) $(TLIBS)
82 amalgamation-testfixture$(EXE): sqlite3.c $(TESTSRC) $(TOP)/src/tclsqlite.c
83 $(TCCX) $(TCL_FLAGS) -DTCLSH=1 $(TESTFIXTURE_FLAGS) \
84 diff --git a/third_party/sqlite/src/src/pager.c b/third_party/sqlite/src/src/pager.c
85 index d840a39..34fa50f 100644
86 --- a/third_party/sqlite/src/src/pager.c
87 +++ b/third_party/sqlite/src/src/pager.c
88 @@ -5467,6 +5467,20 @@ void sqlite3PagerUnref(DbPage *pPg){
89 if( pPg ) sqlite3PagerUnrefNotNull(pPg);
92 +#if defined(__APPLE__)
94 +** Create and return a CFURLRef given a cstring containing the path to a file.
96 +static CFURLRef create_cfurl_from_cstring(const char* filePath){
97 + CFStringRef urlString = CFStringCreateWithFileSystemRepresentation(
98 + kCFAllocatorDefault, filePath);
99 + CFURLRef urlRef = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
100 + urlString, kCFURLPOSIXPathStyle, FALSE);
101 + CFRelease(urlString);
107 ** This function is called at the start of every write transaction.
108 ** There must already be a RESERVED or EXCLUSIVE lock on the database
109 @@ -5531,6 +5545,24 @@ static int pager_open_journal(Pager *pPager){
111 rc = sqlite3OsOpen(pVfs, pPager->zJournal, pPager->jfd, flags, 0);
113 +#if defined(__APPLE__)
114 + /* Set the TimeMachine exclusion metadata for the journal if it has
115 + ** been set for the database. Only do this for unix-type vfs
116 + ** implementations. */
117 + if( rc==SQLITE_OK && pPager->zFilename!=NULL
118 + && strlen(pPager->zFilename)>0
119 + && strncmp(pVfs->zName, "unix", 4)==0
120 + && ( pVfs->zName[4]=='-' || pVfs->zName[4]=='\0' ) ){
121 + CFURLRef database = create_cfurl_from_cstring(pPager->zFilename);
122 + if( CSBackupIsItemExcluded(database, NULL) ){
123 + CFURLRef journal = create_cfurl_from_cstring(pPager->zJournal);
124 + /* Ignore errors from the following exclusion call. */
125 + CSBackupSetItemExcluded(journal, TRUE, FALSE);
126 + CFRelease(journal);
128 + CFRelease(database);
133 assert( rc!=SQLITE_OK || isOpen(pPager->jfd) );
134 diff --git a/third_party/sqlite/src/src/sqliteInt.h b/third_party/sqlite/src/src/sqliteInt.h
135 index 63036c5..9d6a7d8 100644
136 --- a/third_party/sqlite/src/src/sqliteInt.h
137 +++ b/third_party/sqlite/src/src/sqliteInt.h
138 @@ -2985,6 +2985,16 @@ int sqlite3CantopenError(int);
142 +** The CoreServices.h and CoreFoundation.h headers are needed for excluding a
143 +** -journal file from Time Machine backups when its associated database has
144 +** previously been excluded by the client code.
146 +#if defined(__APPLE__)
147 +#include <CoreServices/CoreServices.h>
148 +#include <CoreFoundation/CoreFoundation.h>
152 ** The following macros mimic the standard library functions toupper(),
153 ** isspace(), isalnum(), isdigit() and isxdigit(), respectively. The
154 ** sqlite versions only work for ASCII characters, regardless of locale.