Skip to content

Commit

Permalink
let RA open db readonly
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeOsborn authored Aug 10, 2023
1 parent 857d601 commit 2d2fb0b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 14 deletions.
2 changes: 1 addition & 1 deletion database_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ static int database_cursor_open(libretrodb_t *db,
const char *error = NULL;
libretrodb_query_t *q = NULL;

if ((libretrodb_open(path, db)) != 0)
if ((libretrodb_open(path, db, false)) != 0)
return -1;

if (query)
Expand Down
14 changes: 3 additions & 11 deletions libretro-db/libretrodb.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,22 +181,14 @@ void libretrodb_close(libretrodb_t *db)
db->fd = NULL;
}

int libretrodb_open(const char *path, libretrodb_t *db)
int libretrodb_open(const char *path, libretrodb_t *db, bool write)
{
libretrodb_header_t header;
libretrodb_metadata_t md;
RFILE *fd = filestream_open(path,
RETRO_VFS_FILE_ACCESS_READ_WRITE | RETRO_VFS_FILE_ACCESS_UPDATE_EXISTING,
write ? RETRO_VFS_FILE_ACCESS_READ_WRITE | RETRO_VFS_FILE_ACCESS_UPDATE_EXISTING : RETRO_VFS_FILE_ACCESS_READ,
RETRO_VFS_FILE_ACCESS_HINT_NONE);
db->can_write = true;
if (!fd)
{
/* Try to reopen in readonly mode */
fd = filestream_open(path,
RETRO_VFS_FILE_ACCESS_READ,
RETRO_VFS_FILE_ACCESS_HINT_NONE);
db->can_write = false;
}
db->can_write = write;
if (!fd)
return -1;

Expand Down
2 changes: 1 addition & 1 deletion libretro-db/libretrodb.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ int libretrodb_create(RFILE *fd, libretrodb_value_provider value_provider, void

void libretrodb_close(libretrodb_t *db);

int libretrodb_open(const char *path, libretrodb_t *db);
int libretrodb_open(const char *path, libretrodb_t *db, bool write);

int libretrodb_create_index(libretrodb_t *db, const char *name,
const char *field_name);
Expand Down
2 changes: 1 addition & 1 deletion libretro-db/libretrodb_tool.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ int main(int argc, char ** argv)
if (!db || !cur)
goto error;

if ((rv = libretrodb_open(path, db)) != 0)
if ((rv = libretrodb_open(path, db, true)) != 0)
{
printf("Could not open db file '%s'\n", path);
goto error;
Expand Down

0 comments on commit 2d2fb0b

Please sign in to comment.