From ffda896308d22525bb504129aba2dd6da7b19e38 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Fri, 3 Feb 2023 14:09:53 +0000 Subject: [PATCH] Finish import. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4167 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- src/ssb.import.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/ssb.import.c b/src/ssb.import.c index a2702a87..8d8fcd39 100644 --- a/src/ssb.import.c +++ b/src/ssb.import.c @@ -154,6 +154,24 @@ static void _tf_ssb_import_recursive_add_files(tf_ssb_t* ssb, uv_loop_t* loop, J uv_fs_req_cleanup(&req); } +static bool _tf_ssb_register_app(tf_ssb_t* ssb, const char* user, const char* app, const char* id) +{ + bool result = false; + sqlite3_stmt* statement; + if (sqlite3_prepare(tf_ssb_get_db(ssb), "INSERT OR REPLACE INTO properties (id, key, value) VALUES ($1, 'path:' || $2, $3)", -1, &statement, NULL) == SQLITE_OK) + { + if (sqlite3_bind_text(statement, 1, user, -1, NULL) == SQLITE_OK && + sqlite3_bind_text(statement, 2, app, -1, NULL) == SQLITE_OK && + sqlite3_bind_text(statement, 3, id, -1, NULL) == SQLITE_OK && + sqlite3_step(statement) == SQLITE_DONE) + { + result = sqlite3_changes(tf_ssb_get_db(ssb)) != 0; + } + sqlite3_finalize(statement); + } + return result; +} + static void _tf_ssb_import_app_json(tf_ssb_t* ssb, uv_loop_t* loop, JSContext* context, const char* user, const char* path) { uv_fs_t req = { 0 }; @@ -182,7 +200,12 @@ static void _tf_ssb_import_app_json(tf_ssb_t* ssb, uv_loop_t* loop, JSContext* c const char* app = dir; char* slash = strrchr(dir, '/'); app = slash ? slash + 1 : app; - _tf_ssb_import_add_app(ssb, user, app); + + if (_tf_ssb_register_app(ssb, user, app, id)) + { + printf("Registered %s path:%s as %s.\n", user, app, id); + _tf_ssb_import_add_app(ssb, user, app); + } } JS_FreeCString(context, blob); JS_FreeValue(context, json);