Skip to content
16 changes: 11 additions & 5 deletions src/modules/content-sqlite/content-sqlite.c
Original file line number Diff line number Diff line change
Expand Up @@ -613,17 +613,21 @@ void stats_get_cb (flux_t *h,
json_decref (store_time);
}

static int content_sqlite_setup (struct content_sqlite *ctx, bool truncate)
{
if (truncate)
(void)unlink (ctx->dbfile);
return 0;
}

/* Open the database file ctx->dbfile and set up the database.
*/
static int content_sqlite_opendb (struct content_sqlite *ctx, bool truncate)
static int content_sqlite_opendb (struct content_sqlite *ctx)
{
int flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
char s[128];
int count;

if (truncate)
(void)unlink (ctx->dbfile);

if (sqlite3_open_v2 (ctx->dbfile, &ctx->db, flags, NULL) != SQLITE_OK) {
log_sqlite_error (ctx, "opening %s", ctx->dbfile);
goto error;
Expand Down Expand Up @@ -936,7 +940,9 @@ int mod_main (flux_t *h, int argc, char **argv)
goto done;
if (process_args (ctx, argc, argv, &truncate) < 0)
goto done;
if (content_sqlite_opendb (ctx, truncate) < 0)
if (content_sqlite_setup (ctx, truncate) < 0)
goto done;
Comment on lines +1126 to +1127
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function name is not very descriptive. Maybe just do the

if (truncate)
    (void)unlink (ctx->dbfile)

inline?

if (content_sqlite_opendb (ctx) < 0)
goto done;
if (content_register_service (h, "content-backing") < 0)
goto done;
Expand Down