OLD | NEW |
| (Empty) |
1 From 74d49159b2d2e227095872b96aacc0f40edc4a20 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 05/23] Exclude journal file from Time Machine if database is | |
5 excluded. | |
6 | |
7 BUG=74053 | |
8 | |
9 Original review URL: http://codereview.chromium.org/6990066 | |
10 | |
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. | |
14 --- | |
15 third_party/sqlite/src/Makefile.linux-gcc | 4 ++++ | |
16 third_party/sqlite/src/ext/fts3/fts3_porter.c | 6 ++--- | |
17 third_party/sqlite/src/main.mk | 2 +- | |
18 third_party/sqlite/src/src/pager.c | 32 +++++++++++++++++++++++++++ | |
19 third_party/sqlite/src/src/sqliteInt.h | 10 +++++++++ | |
20 5 files changed, 50 insertions(+), 4 deletions(-) | |
21 | |
22 diff --git a/third_party/sqlite/src/Makefile.linux-gcc b/third_party/sqlite/src/
Makefile.linux-gcc | |
23 index 6d67ba7..554bf56 100644 | |
24 --- a/third_party/sqlite/src/Makefile.linux-gcc | |
25 +++ b/third_party/sqlite/src/Makefile.linux-gcc | |
26 @@ -44,7 +44,11 @@ THREADLIB = -lpthread | |
27 #### Specify any extra libraries needed to access required functions. | |
28 # | |
29 #TLIBS = -lrt # fdatasync on Solaris 8 | |
30 +ifeq ($(shell uname -s),Darwin) | |
31 +TLIBS = -framework CoreServices | |
32 +else | |
33 TLIBS = -ldl | |
34 +endif | |
35 | |
36 #### Leave SQLITE_DEBUG undefined for maximum speed. Use SQLITE_DEBUG=1 | |
37 # to check for memory leaks. Use SQLITE_DEBUG=2 to print a log of all | |
38 diff --git a/third_party/sqlite/src/ext/fts3/fts3_porter.c b/third_party/sqlite/
src/ext/fts3/fts3_porter.c | |
39 index 27f9cf3..f7f047c 100644 | |
40 --- a/third_party/sqlite/src/ext/fts3/fts3_porter.c | |
41 +++ b/third_party/sqlite/src/ext/fts3/fts3_porter.c | |
42 @@ -129,7 +129,7 @@ static int porterClose(sqlite3_tokenizer_cursor *pCursor){ | |
43 /* | |
44 ** Vowel or consonant | |
45 */ | |
46 -static const char cType[] = { | |
47 +static const char vOrCType[] = { | |
48 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, | |
49 1, 1, 1, 2, 1 | |
50 }; | |
51 @@ -153,7 +153,7 @@ static int isConsonant(const char *z){ | |
52 char x = *z; | |
53 if( x==0 ) return 0; | |
54 assert( x>='a' && x<='z' ); | |
55 - j = cType[x-'a']; | |
56 + j = vOrCType[x-'a']; | |
57 if( j<2 ) return j; | |
58 return z[1]==0 || isVowel(z + 1); | |
59 } | |
60 @@ -162,7 +162,7 @@ static int isVowel(const char *z){ | |
61 char x = *z; | |
62 if( x==0 ) return 0; | |
63 assert( x>='a' && x<='z' ); | |
64 - j = cType[x-'a']; | |
65 + j = vOrCType[x-'a']; | |
66 if( j<2 ) return 1-j; | |
67 return isConsonant(z + 1); | |
68 } | |
69 diff --git a/third_party/sqlite/src/main.mk b/third_party/sqlite/src/main.mk | |
70 index e1df7a7..b0aa4b2 100644 | |
71 --- a/third_party/sqlite/src/main.mk | |
72 +++ b/third_party/sqlite/src/main.mk | |
73 @@ -513,7 +513,7 @@ TESTFIXTURE_FLAGS += -DSQLITE_SERVER=1 -DSQLITE_PRIVATE="" -
DSQLITE_CORE | |
74 testfixture$(EXE): $(TESTSRC2) libsqlite3.a $(TESTSRC) $(TOP)/src/tclsqlite.c | |
75 $(TCCX) $(TCL_FLAGS) -DTCLSH=1 $(TESTFIXTURE_FLAGS) \ | |
76 $(TESTSRC) $(TESTSRC2) $(TOP)/src/tclsqlite.c \ | |
77 - -o testfixture$(EXE) $(LIBTCL) $(THREADLIB) libsqlite3.a | |
78 + -o testfixture$(EXE) $(LIBTCL) $(THREADLIB) libsqlite3.a $(TLIBS
) | |
79 | |
80 amalgamation-testfixture$(EXE): sqlite3.c $(TESTSRC) $(TOP)/src/tclsqlite.c | |
81 $(TCCX) $(TCL_FLAGS) -DTCLSH=1 $(TESTFIXTURE_FLAGS) \ | |
82 diff --git a/third_party/sqlite/src/src/pager.c b/third_party/sqlite/src/src/pag
er.c | |
83 index e6d1cde..a4fe318 100644 | |
84 --- a/third_party/sqlite/src/src/pager.c | |
85 +++ b/third_party/sqlite/src/src/pager.c | |
86 @@ -5093,6 +5093,20 @@ void sqlite3PagerUnref(DbPage *pPg){ | |
87 } | |
88 } | |
89 | |
90 +#if defined(__APPLE__) | |
91 +/* | |
92 +** Create and return a CFURLRef given a cstring containing the path to a file. | |
93 +*/ | |
94 +static CFURLRef create_cfurl_from_cstring(const char* filePath){ | |
95 + CFStringRef urlString = CFStringCreateWithFileSystemRepresentation( | |
96 + kCFAllocatorDefault, filePath); | |
97 + CFURLRef urlRef = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, | |
98 + urlString, kCFURLPOSIXPathStyle, FALSE); | |
99 + CFRelease(urlString); | |
100 + return urlRef; | |
101 +} | |
102 +#endif | |
103 + | |
104 /* | |
105 ** This function is called at the start of every write transaction. | |
106 ** There must already be a RESERVED or EXCLUSIVE lock on the database | |
107 @@ -5152,6 +5166,24 @@ static int pager_open_journal(Pager *pPager){ | |
108 #else | |
109 rc = sqlite3OsOpen(pVfs, pPager->zJournal, pPager->jfd, flags, 0); | |
110 #endif | |
111 +#if defined(__APPLE__) | |
112 + /* Set the TimeMachine exclusion metadata for the journal if it has | |
113 + ** been set for the database. Only do this for unix-type vfs | |
114 + ** implementations. */ | |
115 + if( rc==SQLITE_OK && pPager->zFilename!=NULL | |
116 + && strlen(pPager->zFilename)>0 | |
117 + && strncmp(pVfs->zName, "unix", 4)==0 | |
118 + && ( pVfs->zName[4]=='-' || pVfs->zName[4]=='\0' ) ){ | |
119 + CFURLRef database = create_cfurl_from_cstring(pPager->zFilename); | |
120 + if( CSBackupIsItemExcluded(database, NULL) ){ | |
121 + CFURLRef journal = create_cfurl_from_cstring(pPager->zJournal); | |
122 + /* Ignore errors from the following exclusion call. */ | |
123 + CSBackupSetItemExcluded(journal, TRUE, FALSE); | |
124 + CFRelease(journal); | |
125 + } | |
126 + CFRelease(database); | |
127 + } | |
128 +#endif | |
129 } | |
130 assert( rc!=SQLITE_OK || isOpen(pPager->jfd) ); | |
131 } | |
132 diff --git a/third_party/sqlite/src/src/sqliteInt.h b/third_party/sqlite/src/src
/sqliteInt.h | |
133 index ea0925e..684fa57 100644 | |
134 --- a/third_party/sqlite/src/src/sqliteInt.h | |
135 +++ b/third_party/sqlite/src/src/sqliteInt.h | |
136 @@ -2522,6 +2522,16 @@ int sqlite3CantopenError(int); | |
137 #endif | |
138 | |
139 /* | |
140 +** The CoreServices.h and CoreFoundation.h headers are needed for excluding a | |
141 +** -journal file from Time Machine backups when its associated database has | |
142 +** previously been excluded by the client code. | |
143 +*/ | |
144 +#if defined(__APPLE__) | |
145 +#include <CoreServices/CoreServices.h> | |
146 +#include <CoreFoundation/CoreFoundation.h> | |
147 +#endif | |
148 + | |
149 +/* | |
150 ** The following macros mimic the standard library functions toupper(), | |
151 ** isspace(), isalnum(), isdigit() and isxdigit(), respectively. The | |
152 ** sqlite versions only work for ASCII characters, regardless of locale. | |
153 -- | |
154 2.2.1 | |
155 | |
OLD | NEW |