1.1 --- a/update/update.c Fri Jul 08 08:26:29 2016 +0100
1.2 +++ b/update/update.c Fri Mar 08 12:05:41 2019 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /*
1.5 - * Copyright (C) 2009, 2011 J. Ali Harlow <ali@juiblex.co.uk>
1.6 + * Copyright (C) 2009, 2011, 2016 J. Ali Harlow <ali@juiblex.co.uk>
1.7 *
1.8 * This program is free software; you can redistribute it and/or modify
1.9 * it under the terms of the GNU General Public License as published by
1.10 @@ -18,6 +18,7 @@
1.11
1.12 #include <stdlib.h>
1.13 #include <stdio.h>
1.14 +#include <errno.h>
1.15 #include <lua.h>
1.16 #include "config.h"
1.17 #include "plover/plover.h"
1.18 @@ -27,22 +28,85 @@
1.19
1.20 void update(const char *argv0)
1.21 {
1.22 - char *path;
1.23 - gchar *s,*prefix;
1.24 + char *yum_uri,*local_database,*active_database,*alternate_database;
1.25 + gchar *s,*prefix,*distribution,*vendor_prefix;
1.26 int ch;
1.27 struct comps *comps;
1.28 GError *error=NULL;
1.29 - path=plover_get_program_directory(argv0);
1.30 - s=g_strconcat(path,"/repodata/comps.xml",NULL);
1.31 - comps=plover_comps_new_from_file(s);
1.32 + s=plover_get_program(argv0);
1.33 + yum_uri=razor_path_to_uri(s);
1.34 + g_free(s);
1.35 + s=g_strconcat(yum_uri,"/repodata/comps.xml",NULL);
1.36 + comps=plover_comps_new_from_uri(s,&error);
1.37 + g_free(s);
1.38 + if (g_error_matches(error,PLOVER_RAZOR_ERROR,
1.39 + RAZOR_GENERAL_ERROR_UNSUPPORTED_ARCHIVE))
1.40 + {
1.41 + g_clear_error(&error);
1.42 + free(yum_uri);
1.43 + s=plover_get_program_directory(argv0);
1.44 + yum_uri=razor_path_to_uri(s);
1.45 + g_free(s);
1.46 + s=g_strconcat(yum_uri,"/repodata/comps.xml",NULL);
1.47 + comps=plover_comps_new_from_uri(s,&error);
1.48 + }
1.49 if (!comps)
1.50 {
1.51 - perror(s);
1.52 + fprintf(stderr,"%s\n",error->message);
1.53 + g_error_free(error);
1.54 exit(1);
1.55 }
1.56 - g_free(s);
1.57 - prefix=plover_default_prefix_for_vendor(comps->vendor);
1.58 - if (!plover_installed_files_match_prefix(prefix))
1.59 + prefix=plover_comps_get_default_prefix(comps);
1.60 + if (prefix)
1.61 + {
1.62 + s=g_strconcat(prefix,"/var/lib/razor",NULL);
1.63 + local_database=razor_path_to_uri(s);
1.64 + g_free(s);
1.65 + }
1.66 + else
1.67 + local_database=NULL;
1.68 + switch(comps->database)
1.69 + {
1.70 + case COMPS_DATABASE_DISTRIBUTION_LOCAL:
1.71 + active_database=local_database;
1.72 + alternate_database=NULL;
1.73 + break;
1.74 + case COMPS_DATABASE_GLOBAL:
1.75 + active_database=NULL;
1.76 + alternate_database=local_database;
1.77 + break;
1.78 + }
1.79 + if (prefix)
1.80 + {
1.81 + distribution=g_strdup(comps->distribution);
1.82 + plover_comps_set_distribution(comps,NULL);
1.83 + vendor_prefix=plover_comps_get_default_prefix(comps);
1.84 + plover_comps_set_distribution(comps,distribution);
1.85 + g_free(distribution);
1.86 + razor_set_database_uri(alternate_database);
1.87 + if (plover_installed_files_match_prefix(vendor_prefix)==1)
1.88 + {
1.89 + printf("There is an existing installation under %s\n"
1.90 + "which is not compatible with this distribution. In order\n"
1.91 + "to continue, the existing installation must be uninstalled.\n"
1.92 + "Do you want to remove all packages in the existing installion? ",
1.93 + prefix);
1.94 + ch=getchar();
1.95 + if (ch!='y' && ch!='Y' && ch!=EOF && ch!='\n')
1.96 + exit(1);
1.97 + while(ch!='\n' && ch!=EOF)
1.98 + ch=getchar();
1.99 + if (plover_remove(NULL,&error))
1.100 + {
1.101 + fprintf(stderr,"%s\n",error->message);
1.102 + g_error_free(error);
1.103 + exit(1);
1.104 + }
1.105 + }
1.106 + g_free(vendor_prefix);
1.107 + }
1.108 + razor_set_database_uri(active_database);
1.109 + if (prefix && !plover_installed_files_match_prefix(prefix))
1.110 {
1.111 printf("The existing installation is not under %s\n"
1.112 "In order to continue, all the existing packages must be removed.\n"
1.113 @@ -59,15 +123,16 @@
1.114 exit(1);
1.115 }
1.116 }
1.117 + free(local_database);
1.118 plover_comps_free(comps);
1.119 - if (!plover_update(path,prefix,NULL,&error))
1.120 + if (!plover_update_uri(yum_uri,prefix,NULL,&error))
1.121 {
1.122 fprintf(stderr,"%s\n",error->message);
1.123 g_error_free(error);
1.124 exit(1);
1.125 }
1.126 g_free(prefix);
1.127 - free(path);
1.128 + free(yum_uri);
1.129 }
1.130
1.131 int main(int argc,char **argv)