Skip to content

Commit

Permalink
Merge pull request #94 from ejoerns/v0/topic/fixes-and-rework
Browse files Browse the repository at this point in the history
install: Use GError in launch_and_wait_network_handler()
  • Loading branch information
jluebbe committed Jan 30, 2017
2 parents fe176eb + bc18c2e commit b89a231
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions src/install.c
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,7 @@ static gboolean reuse_existing_file_checksum(const RaucChecksum *checksum, const
res = copy_file(srcname, NULL, filename, NULL, &error);
if (!res) {
g_warning("Failed to copy file from %s to %s: %s", srcname, filename, error->message);
g_clear_error(&error);
goto next;
}

Expand All @@ -929,13 +930,17 @@ static gboolean reuse_existing_file_checksum(const RaucChecksum *checksum, const

static gboolean launch_and_wait_network_handler(const gchar* base_url,
RaucManifest *manifest,
GHashTable *target_group) {
GHashTable *target_group,
GError **error) {
gboolean res = FALSE, invalid = FALSE;
GError *ierror = NULL;
GHashTableIter iter;
RaucSlot *slot;

if (!verify_compatible(manifest)) {
res = FALSE;
g_set_error_literal(error, R_INSTALL_ERROR, R_INSTALL_ERROR_COMPAT_MISMATCH,
"Compatible mismatch");
goto out;
}

Expand All @@ -950,7 +955,8 @@ static gboolean launch_and_wait_network_handler(const gchar* base_url,
res = r_boot_set_state(slot, FALSE);

if (!res) {
g_warning("Failed marking slot %s non-bootable", slot->name);
g_set_error(error, R_INSTALL_ERROR, R_INSTALL_ERROR_MARK_NONBOOTABLE,
"Failed marking slot %s non-bootable", slot->name);
goto out;
}
}
Expand All @@ -961,18 +967,22 @@ static gboolean launch_and_wait_network_handler(const gchar* base_url,
gchar *slotstatuspath = NULL;
RaucSlotStatus *slot_state = NULL;

res = r_mount_slot(slot, NULL);
res = r_mount_slot(slot, &ierror);
if (!res) {
g_warning("Mounting failed");
g_message("Mounting failed: %s", ierror->message);
g_clear_error(&ierror);

goto slot_out;
}
g_print(G_STRLOC " Mounted %s to %s\n", slot->device, slot->mount_point);

// read status
slotstatuspath = g_build_filename(slot->mount_point, "slot.raucs", NULL);
res = load_slot_status(slotstatuspath, &slot_state, NULL);
res = load_slot_status(slotstatuspath, &slot_state, &ierror);
if (!res) {
g_print("Failed to load status file\n");
g_message("Failed to load slot status file: %s", ierror->message);
g_clear_error(&ierror);

slot_state = g_new0(RaucSlotStatus, 1);
slot_state->status = g_strdup("update");
}
Expand Down Expand Up @@ -1018,19 +1028,25 @@ static gboolean launch_and_wait_network_handler(const gchar* base_url,

// write status
slot_state->status = g_strdup("ok");
res = save_slot_status(slotstatuspath, slot_state, NULL);
res = save_slot_status(slotstatuspath, slot_state, &ierror);
if (!res) {
g_warning("Failed to save status file");
g_warning("Failed writing status file: %s", ierror->message);
g_clear_error(&ierror);

invalid = TRUE;
goto slot_out;
}

slot_out:
g_clear_pointer(&slotstatuspath, g_free);
g_clear_pointer(&slot_state, free_slot_status);
res = r_umount_slot(slot, NULL);
res = r_umount_slot(slot, &ierror);
if (!res) {
g_warning("Unounting failed");
g_propagate_prefixed_error(
error,
ierror,
"Unmounting failed: ");

goto out;
}
g_print(G_STRLOC " Unmounted %s from %s\n", slot->device, slot->mount_point);
Expand Down Expand Up @@ -1249,7 +1265,7 @@ gboolean do_install_network(const gchar *url, GError **error) {


g_print("Using network handler for %s\n", base_url);
res = launch_and_wait_network_handler(base_url, manifest, target_group);
res = launch_and_wait_network_handler(base_url, manifest, target_group, NULL);
if (!res) {
g_set_error_literal(error, R_INSTALL_ERROR, R_INSTALL_ERROR_HANDLER,
"Handler error");
Expand Down

0 comments on commit b89a231

Please sign in to comment.