app-manager/update.c
author J. Ali Harlow <ali@juiblex.co.uk>
Thu Jul 16 23:02:31 2020 +0100 (2020-07-16)
changeset 101 abdfa0410032
parent 98 71127797ca73
permissions -rw-r--r--
Prepare to release 0.5.8
ali@24
     1
/*
ali@61
     2
 * Copyright (C) 2014, 2016  J. Ali Harlow <ali@juiblex.co.uk>
ali@24
     3
 *
ali@24
     4
 * This program is free software; you can redistribute it and/or modify
ali@24
     5
 * it under the terms of the GNU General Public License as published by
ali@24
     6
 * the Free Software Foundation; either version 2 of the License, or
ali@24
     7
 * (at your option) any later version.
ali@24
     8
 *
ali@24
     9
 * This program is distributed in the hope that it will be useful,
ali@24
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ali@24
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ali@24
    12
 * GNU General Public License for more details.
ali@24
    13
 *
ali@24
    14
 * You should have received a copy of the GNU General Public License along
ali@24
    15
 * with this program; if not, write to the Free Software Foundation, Inc.,
ali@24
    16
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
ali@24
    17
 */
ali@24
    18
ali@24
    19
#include "config.h"
ali@24
    20
#include <stdlib.h>
ali@24
    21
#include <string.h>
ali@24
    22
#include <errno.h>
ali@24
    23
#include <glib.h>
ali@24
    24
#include <gio/gio.h>
ali@24
    25
#include <gtk/gtk.h>
ali@24
    26
#include <plover/plover.h>
ali@24
    27
#include <plover/transaction.h>
ali@24
    28
#include <plover/packageset.h>
ali@24
    29
#include <plover-gtk/transactionhelper.h>
ali@24
    30
#include "app-manager.h"
ali@24
    31
ali@61
    32
ali@61
    33
gboolean update(const char *base)
ali@24
    34
{
ali@99
    35
    gchar *s;
ali@24
    36
    const char *prefix;
ali@24
    37
    GError *error=NULL;
ali@24
    38
    static PloverTransactionHelper *helper=NULL;
ali@24
    39
    if (!helper)
ali@24
    40
    {
ali@24
    41
	helper=plover_transaction_helper_new(ui);
ali@98
    42
	plover_transaction_helper_set_base_uri(helper,base);
ali@24
    43
	prefix=plover_transaction_helper_get_prefix(helper,&error);
ali@24
    44
	if (error)
ali@24
    45
	    g_clear_error(&error);
ali@24
    46
	else
ali@24
    47
	{
ali@24
    48
	    s=g_strconcat(prefix?prefix:"","/var/log/update",NULL);
ali@24
    49
	    plover_log_open(s);
ali@24
    50
	    g_free(s);
ali@24
    51
	}
ali@24
    52
	plover_transaction_helper_set_check_vendor(helper,TRUE);
ali@24
    53
	g_signal_connect(helper,"close",G_CALLBACK(gtk_main_quit),NULL);
ali@24
    54
    }
ali@24
    55
    if (!plover_transaction_helper_get_visible(helper))
ali@24
    56
    {
ali@24
    57
	if (!plover_transaction_helper_update(helper,&error))
ali@24
    58
	{
ali@24
    59
	    if (g_error_matches(error,PLOVER_GENERAL_ERROR,
ali@24
    60
	      PLOVER_GENERAL_ERROR_NO_WORK))
ali@24
    61
	    {
ali@24
    62
		g_error_free(error);
ali@24
    63
		error=g_error_new_literal(PLOVER_GENERAL_ERROR,
ali@24
    64
		  PLOVER_GENERAL_ERROR_NO_WORK,
ali@24
    65
		  "All relevant updates already applied");
ali@24
    66
		plover_transaction_helper_set_error(helper,error,
ali@24
    67
		  "Software update");
ali@24
    68
	    }
ali@24
    69
	    else if (g_error_matches(error,PLOVER_GENERAL_ERROR,
ali@24
    70
	      PLOVER_GENERAL_ERROR_REQUIREMENTS_NOT_MET))
ali@24
    71
	    {
ali@24
    72
		g_error_free(error);
ali@24
    73
		error=g_error_new_literal(PLOVER_GENERAL_ERROR,
ali@24
    74
		  PLOVER_GENERAL_ERROR_REQUIREMENTS_NOT_MET,
ali@24
    75
		  "Updates cannot be applied because some earlier updates are "
ali@24
    76
		  "missing. Installing updates in sequence should resolve this "
ali@24
    77
		  "problem");
ali@24
    78
		plover_transaction_helper_set_error(helper,error,
ali@24
    79
		  "Software update failed");
ali@24
    80
	    }
ali@24
    81
	    else
ali@24
    82
		plover_transaction_helper_set_error(helper,error,
ali@24
    83
		  "Software update failed");
ali@24
    84
	    g_error_free(error);
ali@24
    85
	}
ali@24
    86
    }
ali@24
    87
    plover_transaction_helper_present(helper);
ali@24
    88
    return TRUE;
ali@24
    89
}