Fossil SCM

Calling db_open() to determine if a given repository is valid rather than a hand-rolled sqlite3_open() call. This then allows us to call db_looks_like_a_repository() to determine if the DB is a valid repo rather than duplicate the checks it already has in another nearby context. This is part of the apndvfs vs normal-case stuff done in prior commits, consolidating the notion of "valid" to a single spot in the code.

wyoung 2022-02-28 23:32 trunk
Commit 69145d9d992f12e713316cf8a17692985b7916dc2c9e51751c7826b9056111d7
1 file changed +4 -7
+4 -7
--- src/db.c
+++ src/db.c
@@ -2140,13 +2140,13 @@
21402140
int res = 0;
21412141
sqlite3_stmt *pStmt = 0;
21422142
21432143
sz = file_size(zDbName, ExtFILE);
21442144
if( sz<16834 ) return 0;
2145
- if( sz%512 ) return 0;
2146
- rc = sqlite3_open(zDbName, &db);
2147
- if( rc ) goto is_repo_end;
2145
+ db = db_open(zDbName);
2146
+ if( !db ) return 0;
2147
+ if( !g.zVfsName && sz%512 ) return 0;
21482148
rc = sqlite3_prepare_v2(db,
21492149
"SELECT count(*) FROM sqlite_schema"
21502150
" WHERE name COLLATE nocase IN"
21512151
"('blob','delta','rcvfrom','user','config','mlink','plink');",
21522152
-1, &pStmt, 0);
@@ -2188,14 +2188,11 @@
21882188
}
21892189
if( zDbName==0 ){
21902190
db_err("unable to find the name of a repository database");
21912191
}
21922192
}
2193
- /* Don't change the file size test to call db_looks_like_a_repository()
2194
- * or copy code from it. The sz%512 bit in particular is wrong for the
2195
- * apndvfs case in db_open() above. */
2196
- if( file_access(zDbName, R_OK) || file_size(zDbName, ExtFILE)<1024 ){
2193
+ if( !db_looks_like_a_repository(zDbName) ){
21972194
if( file_access(zDbName, F_OK) ){
21982195
#ifdef FOSSIL_ENABLE_JSON
21992196
g.json.resultCode = FSL_JSON_E_DB_NOT_FOUND;
22002197
#endif
22012198
fossil_fatal("repository does not exist or"
22022199
--- src/db.c
+++ src/db.c
@@ -2140,13 +2140,13 @@
2140 int res = 0;
2141 sqlite3_stmt *pStmt = 0;
2142
2143 sz = file_size(zDbName, ExtFILE);
2144 if( sz<16834 ) return 0;
2145 if( sz%512 ) return 0;
2146 rc = sqlite3_open(zDbName, &db);
2147 if( rc ) goto is_repo_end;
2148 rc = sqlite3_prepare_v2(db,
2149 "SELECT count(*) FROM sqlite_schema"
2150 " WHERE name COLLATE nocase IN"
2151 "('blob','delta','rcvfrom','user','config','mlink','plink');",
2152 -1, &pStmt, 0);
@@ -2188,14 +2188,11 @@
2188 }
2189 if( zDbName==0 ){
2190 db_err("unable to find the name of a repository database");
2191 }
2192 }
2193 /* Don't change the file size test to call db_looks_like_a_repository()
2194 * or copy code from it. The sz%512 bit in particular is wrong for the
2195 * apndvfs case in db_open() above. */
2196 if( file_access(zDbName, R_OK) || file_size(zDbName, ExtFILE)<1024 ){
2197 if( file_access(zDbName, F_OK) ){
2198 #ifdef FOSSIL_ENABLE_JSON
2199 g.json.resultCode = FSL_JSON_E_DB_NOT_FOUND;
2200 #endif
2201 fossil_fatal("repository does not exist or"
2202
--- src/db.c
+++ src/db.c
@@ -2140,13 +2140,13 @@
2140 int res = 0;
2141 sqlite3_stmt *pStmt = 0;
2142
2143 sz = file_size(zDbName, ExtFILE);
2144 if( sz<16834 ) return 0;
2145 db = db_open(zDbName);
2146 if( !db ) return 0;
2147 if( !g.zVfsName && sz%512 ) return 0;
2148 rc = sqlite3_prepare_v2(db,
2149 "SELECT count(*) FROM sqlite_schema"
2150 " WHERE name COLLATE nocase IN"
2151 "('blob','delta','rcvfrom','user','config','mlink','plink');",
2152 -1, &pStmt, 0);
@@ -2188,14 +2188,11 @@
2188 }
2189 if( zDbName==0 ){
2190 db_err("unable to find the name of a repository database");
2191 }
2192 }
2193 if( !db_looks_like_a_repository(zDbName) ){
 
 
 
2194 if( file_access(zDbName, F_OK) ){
2195 #ifdef FOSSIL_ENABLE_JSON
2196 g.json.resultCode = FSL_JSON_E_DB_NOT_FOUND;
2197 #endif
2198 fossil_fatal("repository does not exist or"
2199

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button