Index: third_party/sqlite/amalgamation/sqlite3.c |
diff --git a/third_party/sqlite/amalgamation/sqlite3.c b/third_party/sqlite/amalgamation/sqlite3.c |
index ac1bb39298160340e4806f33d5ff0b73e2b1de66..80d4c2232eaa10111ff79ad79f7952b11e74e106 100644 |
--- a/third_party/sqlite/amalgamation/sqlite3.c |
+++ b/third_party/sqlite/amalgamation/sqlite3.c |
@@ -7575,6 +7575,11 @@ int chromium_sqlite3_fill_in_unix_sqlite3_file(sqlite3_vfs* vfs, |
const char* fileName, |
int noLock); |
CHROMIUM_SQLITE_API |
+int chromium_sqlite3_get_reusable_file_handle(sqlite3_file* file, |
+ const char* fileName, |
+ int flags, |
+ int* fd); |
+CHROMIUM_SQLITE_API |
void chromium_sqlite3_update_reusable_file_handle(sqlite3_file* file, |
int fd, |
int flags); |
@@ -30508,6 +30513,36 @@ int chromium_sqlite3_fill_in_unix_sqlite3_file(sqlite3_vfs* vfs, |
} |
/* |
+** Search for an unused file descriptor that was opened on the database file. |
+** If a suitable file descriptor if found, then it is stored in *fd; otherwise, |
+** *fd is not modified. |
+** |
+** If a reusable file descriptor is not found, and a new UnixUnusedFd cannot |
+** be allocated, SQLITE_NOMEM is returned. Otherwise, SQLITE_OK is returned. |
+*/ |
+CHROMIUM_SQLITE_API |
+int chromium_sqlite3_get_reusable_file_handle(sqlite3_file* file, |
+ const char* fileName, |
+ int flags, |
+ int* fd) { |
+ unixFile* unixSQLite3File = (unixFile*)file; |
+ int fileType = flags & 0xFFFFFF00; |
+ if (fileType == SQLITE_OPEN_MAIN_DB) { |
+ UnixUnusedFd *unusedFd = findReusableFd(fileName, flags); |
+ if (unusedFd) { |
+ *fd = unusedFd->fd; |
+ } else { |
+ unusedFd = sqlite3_malloc(sizeof(*unusedFd)); |
+ if (!unusedFd) { |
+ return SQLITE_NOMEM; |
+ } |
+ } |
+ unixSQLite3File->pUnused = unusedFd; |
+ } |
+ return SQLITE_OK; |
+} |
+ |
+/* |
** Marks 'fd' as the unused file descriptor for 'pFile'. |
*/ |
CHROMIUM_SQLITE_API |
@@ -30634,17 +30669,10 @@ static int unixOpen( |
chromium_sqlite3_initialize_unix_sqlite3_file(pFile); |
if( eType==SQLITE_OPEN_MAIN_DB ){ |
- UnixUnusedFd *pUnused; |
- pUnused = findReusableFd(zName, flags); |
- if( pUnused ){ |
- fd = pUnused->fd; |
- }else{ |
- pUnused = sqlite3_malloc(sizeof(*pUnused)); |
- if( !pUnused ){ |
- return SQLITE_NOMEM; |
- } |
+ rc = chromium_sqlite3_get_reusable_file_handle(pFile, zName, flags, &fd); |
+ if( rc!=SQLITE_OK ){ |
+ return rc; |
} |
- p->pUnused = pUnused; |
/* Database filenames are double-zero terminated if they are not |
** URIs with parameters. Hence, they can always be passed into |