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