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.
Commit
69145d9d992f12e713316cf8a17692985b7916dc2c9e51751c7826b9056111d7
Parent
491b986d0de38fb…
1 file changed
+4
-7
M
src/db.c
+4
-7
| --- src/db.c | ||
| +++ src/db.c | ||
| @@ -2140,13 +2140,13 @@ | ||
| 2140 | 2140 | int res = 0; |
| 2141 | 2141 | sqlite3_stmt *pStmt = 0; |
| 2142 | 2142 | |
| 2143 | 2143 | sz = file_size(zDbName, ExtFILE); |
| 2144 | 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; | |
| 2145 | + db = db_open(zDbName); | |
| 2146 | + if( !db ) return 0; | |
| 2147 | + if( !g.zVfsName && sz%512 ) return 0; | |
| 2148 | 2148 | rc = sqlite3_prepare_v2(db, |
| 2149 | 2149 | "SELECT count(*) FROM sqlite_schema" |
| 2150 | 2150 | " WHERE name COLLATE nocase IN" |
| 2151 | 2151 | "('blob','delta','rcvfrom','user','config','mlink','plink');", |
| 2152 | 2152 | -1, &pStmt, 0); |
| @@ -2188,14 +2188,11 @@ | ||
| 2188 | 2188 | } |
| 2189 | 2189 | if( zDbName==0 ){ |
| 2190 | 2190 | db_err("unable to find the name of a repository database"); |
| 2191 | 2191 | } |
| 2192 | 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 ){ | |
| 2193 | + if( !db_looks_like_a_repository(zDbName) ){ | |
| 2197 | 2194 | if( file_access(zDbName, F_OK) ){ |
| 2198 | 2195 | #ifdef FOSSIL_ENABLE_JSON |
| 2199 | 2196 | g.json.resultCode = FSL_JSON_E_DB_NOT_FOUND; |
| 2200 | 2197 | #endif |
| 2201 | 2198 | fossil_fatal("repository does not exist or" |
| 2202 | 2199 |
| --- 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 |