Skip to content

Commit

Permalink
[Service] clear flag to delete old model
Browse files Browse the repository at this point in the history
Parse clear field from json, to delete old model or resource from database.

Signed-off-by: Jaeyun Jung <[email protected]>
  • Loading branch information
jaeyun-jung committed Dec 12, 2023
1 parent 4d55c42 commit 33a8d51
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions daemon/pkg-mgr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ _parse_json (const gchar *json_path, mlsvc_json_type_e json_type, const gchar *a
const gchar *model = json_object_get_string_member (object, "model");
const gchar *desc = json_object_get_string_member (object, "description");
const gchar *activate = json_object_get_string_member (object, "activate");
const gchar *clear = json_object_get_string_member (object, "clear");

if (!name || !model) {
_E ("Failed to get name or model from json file '%s'.", json_file);
Expand All @@ -143,6 +144,17 @@ _parse_json (const gchar *json_path, mlsvc_json_type_e json_type, const gchar *a

guint version;
bool active = (activate && g_ascii_strcasecmp (activate, "true") == 0);
bool clear_old = (clear && g_ascii_strcasecmp (clear, "true") == 0);

/* Remove old model from database. */
if (clear_old) {
try {
db.delete_model (name, 0U);
} catch (const std::exception &e) {
/* Ignore error case. */
_W ("%s", e.what ());
}
}

db.set_model (name, model, active, desc ? desc : "",
app_info ? app_info : "", &version);
Expand Down Expand Up @@ -170,12 +182,25 @@ _parse_json (const gchar *json_path, mlsvc_json_type_e json_type, const gchar *a
const gchar *name = json_object_get_string_member (object, "name");
const gchar *path = json_object_get_string_member (object, "path");
const gchar *desc = json_object_get_string_member (object, "description");
const gchar *clear = json_object_get_string_member (object, "clear");

if (!name || !path) {
_E ("Failed to get name or path from json file '%s'.", json_file);
continue;
}

bool clear_old = (clear && g_ascii_strcasecmp (clear, "true") == 0);

/* Remove old resource from database. */
if (clear_old) {
try {
db.delete_resource (name);
} catch (const std::exception &e) {
/* Ignore error case. */
_W ("%s", e.what ());
}
}

db.set_resource (name, path, desc ? desc : "", app_info ? app_info : "");

_I ("The resource with name '%s' is registered.", name);
Expand Down

0 comments on commit 33a8d51

Please sign in to comment.