| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 // Opens a file. | 136 // Opens a file. |
| 137 // | 137 // |
| 138 // vfs - pointer to the sqlite3_vfs object. | 138 // vfs - pointer to the sqlite3_vfs object. |
| 139 // fileName - the name of the file. | 139 // fileName - the name of the file. |
| 140 // id - the structure that will manipulate the newly opened file. | 140 // id - the structure that will manipulate the newly opened file. |
| 141 // desiredFlags - the desired open mode flags. | 141 // desiredFlags - the desired open mode flags. |
| 142 // usedFlags - the actual open mode flags that were used. | 142 // usedFlags - the actual open mode flags that were used. |
| 143 int chromiumOpenInternal(sqlite3_vfs* vfs, const char* fileName, sqlite3_file* i
d, int desiredFlags, int* usedFlags) | 143 int chromiumOpenInternal(sqlite3_vfs* vfs, const char* fileName, sqlite3_file* i
d, int desiredFlags, int* usedFlags) |
| 144 { | 144 { |
| 145 chromium_sqlite3_initialize_unix_sqlite3_file(id); | 145 chromium_sqlite3_initialize_unix_sqlite3_file(id); |
| 146 int fd = Platform::current()->databaseOpenFile(String(fileName), desiredFlag
s); | 146 int fd = -1; |
| 147 if ((fd < 0) && (desiredFlags & SQLITE_OPEN_READWRITE)) { | 147 int result = chromium_sqlite3_get_reusable_file_handle(id, fileName, desired
Flags, &fd); |
| 148 int newFlags = (desiredFlags & ~(SQLITE_OPEN_READWRITE | SQLITE_OPEN_CRE
ATE)) | SQLITE_OPEN_READONLY; | 148 if (result != SQLITE_OK) |
| 149 fd = Platform::current()->databaseOpenFile(String(fileName), newFlags); | 149 return result; |
| 150 |
| 151 if (fd < 0) { |
| 152 fd = Platform::current()->databaseOpenFile(String(fileName), desiredFlag
s); |
| 153 if ((fd < 0) && (desiredFlags & SQLITE_OPEN_READWRITE)) { |
| 154 int newFlags = (desiredFlags & ~(SQLITE_OPEN_READWRITE | SQLITE_OPEN
_CREATE)) | SQLITE_OPEN_READONLY; |
| 155 fd = Platform::current()->databaseOpenFile(String(fileName), newFlag
s); |
| 156 } |
| 150 } | 157 } |
| 151 if (fd < 0) { | 158 if (fd < 0) { |
| 152 chromium_sqlite3_destroy_reusable_file_handle(id); | 159 chromium_sqlite3_destroy_reusable_file_handle(id); |
| 153 return SQLITE_CANTOPEN; | 160 return SQLITE_CANTOPEN; |
| 154 } | 161 } |
| 155 | 162 |
| 156 if (usedFlags) | 163 if (usedFlags) |
| 157 *usedFlags = desiredFlags; | 164 *usedFlags = desiredFlags; |
| 158 chromium_sqlite3_update_reusable_file_handle(id, fd, desiredFlags); | 165 chromium_sqlite3_update_reusable_file_handle(id, fd, desiredFlags); |
| 159 | 166 |
| 160 fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC); | 167 fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC); |
| 161 | 168 |
| 162 // The mask 0x00007F00 gives us the 7 bits that determine the type of the fi
le SQLite is trying to open. | 169 // The mask 0x00007F00 gives us the 7 bits that determine the type of the fi
le SQLite is trying to open. |
| 163 int fileType = desiredFlags & 0x00007F00; | 170 int fileType = desiredFlags & 0x00007F00; |
| 164 int noLock = (fileType != SQLITE_OPEN_MAIN_DB); | 171 int noLock = (fileType != SQLITE_OPEN_MAIN_DB); |
| 165 sqlite3_vfs* wrappedVfs = static_cast<sqlite3_vfs*>(vfs->pAppData); | 172 sqlite3_vfs* wrappedVfs = static_cast<sqlite3_vfs*>(vfs->pAppData); |
| 166 int result = chromium_sqlite3_fill_in_unix_sqlite3_file(wrappedVfs, fd, -1,
id, fileName, noLock); | 173 result = chromium_sqlite3_fill_in_unix_sqlite3_file(wrappedVfs, fd, -1, id,
fileName, noLock); |
| 167 if (result != SQLITE_OK) | 174 if (result != SQLITE_OK) |
| 168 chromium_sqlite3_destroy_reusable_file_handle(id); | 175 chromium_sqlite3_destroy_reusable_file_handle(id); |
| 169 return result; | 176 return result; |
| 170 } | 177 } |
| 171 | 178 |
| 172 int chromiumOpen(sqlite3_vfs* vfs, const char* fileName, sqlite3_file* id, int d
esiredFlags, int* usedFlags) | 179 int chromiumOpen(sqlite3_vfs* vfs, const char* fileName, sqlite3_file* id, int d
esiredFlags, int* usedFlags) |
| 173 { | 180 { |
| 174 sqlite3_vfs* wrappedVfs = static_cast<sqlite3_vfs*>(vfs->pAppData); | 181 sqlite3_vfs* wrappedVfs = static_cast<sqlite3_vfs*>(vfs->pAppData); |
| 175 sqlite3_file* wrappedFile = static_cast<sqlite3_file*>(sqlite3_malloc(wrappe
dVfs->szOsFile)); | 182 sqlite3_file* wrappedFile = static_cast<sqlite3_file*>(sqlite3_malloc(wrappe
dVfs->szOsFile)); |
| 176 if (!wrappedFile) | 183 if (!wrappedFile) |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 chromiumDlClose, | 344 chromiumDlClose, |
| 338 chromiumRandomness, | 345 chromiumRandomness, |
| 339 chromiumSleep, | 346 chromiumSleep, |
| 340 chromiumCurrentTime, | 347 chromiumCurrentTime, |
| 341 chromiumGetLastError | 348 chromiumGetLastError |
| 342 }; | 349 }; |
| 343 sqlite3_vfs_register(&chromium_vfs, 0); | 350 sqlite3_vfs_register(&chromium_vfs, 0); |
| 344 } | 351 } |
| 345 | 352 |
| 346 } // namespace blink | 353 } // namespace blink |
| OLD | NEW |