| 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 = -1; | 146 int fd = Platform::current()->databaseOpenFile(String(fileName), desiredFlag
s); |
| 147 int result = chromium_sqlite3_get_reusable_file_handle(id, fileName, desired
Flags, &fd); | 147 if ((fd < 0) && (desiredFlags & SQLITE_OPEN_READWRITE)) { |
| 148 if (result != SQLITE_OK) | 148 int newFlags = (desiredFlags & ~(SQLITE_OPEN_READWRITE | SQLITE_OPEN_CRE
ATE)) | SQLITE_OPEN_READONLY; |
| 149 return result; | 149 fd = Platform::current()->databaseOpenFile(String(fileName), newFlags); |
| 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 } | |
| 157 } | 150 } |
| 158 if (fd < 0) { | 151 if (fd < 0) { |
| 159 chromium_sqlite3_destroy_reusable_file_handle(id); | 152 chromium_sqlite3_destroy_reusable_file_handle(id); |
| 160 return SQLITE_CANTOPEN; | 153 return SQLITE_CANTOPEN; |
| 161 } | 154 } |
| 162 | 155 |
| 163 if (usedFlags) | 156 if (usedFlags) |
| 164 *usedFlags = desiredFlags; | 157 *usedFlags = desiredFlags; |
| 165 chromium_sqlite3_update_reusable_file_handle(id, fd, desiredFlags); | 158 chromium_sqlite3_update_reusable_file_handle(id, fd, desiredFlags); |
| 166 | 159 |
| 167 fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC); | 160 fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC); |
| 168 | 161 |
| 169 // The mask 0x00007F00 gives us the 7 bits that determine the type of the fi
le SQLite is trying to open. | 162 // The mask 0x00007F00 gives us the 7 bits that determine the type of the fi
le SQLite is trying to open. |
| 170 int fileType = desiredFlags & 0x00007F00; | 163 int fileType = desiredFlags & 0x00007F00; |
| 171 int noLock = (fileType != SQLITE_OPEN_MAIN_DB); | 164 int noLock = (fileType != SQLITE_OPEN_MAIN_DB); |
| 172 sqlite3_vfs* wrappedVfs = static_cast<sqlite3_vfs*>(vfs->pAppData); | 165 sqlite3_vfs* wrappedVfs = static_cast<sqlite3_vfs*>(vfs->pAppData); |
| 173 result = chromium_sqlite3_fill_in_unix_sqlite3_file(wrappedVfs, fd, -1, id,
fileName, noLock); | 166 int result = chromium_sqlite3_fill_in_unix_sqlite3_file(wrappedVfs, fd, -1,
id, fileName, noLock); |
| 174 if (result != SQLITE_OK) | 167 if (result != SQLITE_OK) |
| 175 chromium_sqlite3_destroy_reusable_file_handle(id); | 168 chromium_sqlite3_destroy_reusable_file_handle(id); |
| 176 return result; | 169 return result; |
| 177 } | 170 } |
| 178 | 171 |
| 179 int chromiumOpen(sqlite3_vfs* vfs, const char* fileName, sqlite3_file* id, int d
esiredFlags, int* usedFlags) | 172 int chromiumOpen(sqlite3_vfs* vfs, const char* fileName, sqlite3_file* id, int d
esiredFlags, int* usedFlags) |
| 180 { | 173 { |
| 181 sqlite3_vfs* wrappedVfs = static_cast<sqlite3_vfs*>(vfs->pAppData); | 174 sqlite3_vfs* wrappedVfs = static_cast<sqlite3_vfs*>(vfs->pAppData); |
| 182 sqlite3_file* wrappedFile = static_cast<sqlite3_file*>(sqlite3_malloc(wrappe
dVfs->szOsFile)); | 175 sqlite3_file* wrappedFile = static_cast<sqlite3_file*>(sqlite3_malloc(wrappe
dVfs->szOsFile)); |
| 183 if (!wrappedFile) | 176 if (!wrappedFile) |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 chromiumDlClose, | 337 chromiumDlClose, |
| 345 chromiumRandomness, | 338 chromiumRandomness, |
| 346 chromiumSleep, | 339 chromiumSleep, |
| 347 chromiumCurrentTime, | 340 chromiumCurrentTime, |
| 348 chromiumGetLastError | 341 chromiumGetLastError |
| 349 }; | 342 }; |
| 350 sqlite3_vfs_register(&chromium_vfs, 0); | 343 sqlite3_vfs_register(&chromium_vfs, 0); |
| 351 } | 344 } |
| 352 | 345 |
| 353 } // namespace blink | 346 } // namespace blink |
| OLD | NEW |