plover/razor.c
changeset 18 cb43820f94ce
parent 6 e8c9cc792c5d
child 19 5cafc65a6183
     1.1 --- a/plover/razor.c	Thu Oct 01 20:38:39 2009 +0100
     1.2 +++ b/plover/razor.c	Mon Jan 30 13:35:28 2012 +0000
     1.3 @@ -1,7 +1,7 @@
     1.4  /*
     1.5   * Copyright (C) 2008  Kristian Høgsberg <krh@redhat.com>
     1.6   * Copyright (C) 2008  Red Hat, Inc
     1.7 - * Copyright (C) 2009  J. Ali Harlow <ali@juiblex.co.uk>
     1.8 + * Copyright (C) 2009, 2011  J. Ali Harlow <ali@juiblex.co.uk>
     1.9   *
    1.10   * This program is free software; you can redistribute it and/or modify
    1.11   * it under the terms of the GNU General Public License as published by
    1.12 @@ -39,7 +39,8 @@
    1.13  }
    1.14  
    1.15  struct razor_set *plover_relocate_packages(struct razor_set *set,
    1.16 -  const char *base,struct razor_relocations *relocations)
    1.17 +  struct razor_atomic *atomic,const char *base,
    1.18 +  struct razor_relocations *relocations)
    1.19  {
    1.20      struct razor_importer *importer;
    1.21      struct razor_property_iterator *prop_iter;
    1.22 @@ -48,6 +49,7 @@
    1.23      struct razor_package *package;
    1.24      struct razor_property *property;
    1.25      struct razor_rpm *rpm;
    1.26 +    struct razor_set *new;
    1.27      const char *name,*version,*arch,*summary,*desc,*url,*license;
    1.28      char *s,*file;
    1.29      uint32_t flags;
    1.30 @@ -61,16 +63,14 @@
    1.31  	s=rpm_filename(name,version,arch);
    1.32  	file=plover_strconcat(base,"/rpms/",s,NULL);
    1.33  	free(s);
    1.34 -	rpm=razor_rpm_open(file);
    1.35 +	rpm=razor_rpm_open(file,atomic);
    1.36 +	free(file);
    1.37  	if (!rpm)
    1.38  	{
    1.39 -	    fprintf(stderr,"failed to open rpm %s\n",file);
    1.40  	    razor_package_iterator_destroy(pkg_iter);
    1.41  	    razor_importer_destroy(importer);
    1.42 -	    free(file);
    1.43  	    return NULL;
    1.44  	}
    1.45 -	free(file);
    1.46  	razor_relocations_set_rpm(relocations,rpm);
    1.47  	razor_rpm_close(rpm);
    1.48  	razor_importer_begin_package(importer,name,version,arch);
    1.49 @@ -90,70 +90,113 @@
    1.50  	razor_importer_finish_package(importer);
    1.51      }
    1.52      razor_package_iterator_destroy(pkg_iter);
    1.53 -    return razor_importer_finish(importer);
    1.54 +    new=razor_importer_finish(importer);
    1.55 +    if (new)
    1.56 +	razor_set_set_header_version(new,razor_set_get_header_version(set));
    1.57 +    return new;
    1.58  }
    1.59  
    1.60 -int plover_run_transaction(struct razor_transaction *trans,const char *base,
    1.61 -  const char *install_root,struct razor_set *system,struct razor_set *next,
    1.62 -  struct razor_relocations *relocations)
    1.63 +int plover_run_transaction(struct razor_transaction *trans,
    1.64 +  struct razor_install_iterator *ii,const char *base,const char *install_root,
    1.65 +  struct razor_set *system,struct razor_set *next,struct razor_atomic *atomic,
    1.66 +  struct razor_relocations *relocations,enum razor_stage_type stage)
    1.67  {
    1.68 -    struct razor_install_iterator *ii;
    1.69      struct razor_package *package;
    1.70      enum razor_install_action action;
    1.71      struct razor_rpm *rpm;
    1.72      const char *name,*version,*arch;
    1.73      char *s,*file;
    1.74      int count;
    1.75 -    ii=razor_set_create_install_iterator(system,next);
    1.76 -    printf("Running Transaction\n");
    1.77 +    razor_install_iterator_rewind(ii);
    1.78 +    switch(stage)
    1.79 +    {
    1.80 +	case RAZOR_STAGE_SCRIPTS_PRE:
    1.81 +	    printf("Running pre-transaction scripts\n");
    1.82 +	    break;
    1.83 +	case RAZOR_STAGE_FILES:
    1.84 +	    printf("Running Transaction\n");
    1.85 +	    break;
    1.86 +	case RAZOR_STAGE_SCRIPTS_POST:
    1.87 +	    printf("Running post-transaction scripts\n");
    1.88 +	    break;
    1.89 +	default:
    1.90 +	    /* Keep the compiler happy */
    1.91 +	    break;
    1.92 +    }
    1.93      while (razor_install_iterator_next(ii,&package,&action,&count))
    1.94      {
    1.95  	if (action==RAZOR_INSTALL_ACTION_REMOVE)
    1.96  	{
    1.97  	    razor_package_get_details(system,package,RAZOR_DETAIL_NAME,&name,
    1.98  	      RAZOR_DETAIL_LAST);
    1.99 -	    printf("  Removing : %s ",name);
   1.100 -	    if (razor_package_remove(system,next,package,install_root,count)<0)
   1.101 -		printf(
   1.102 -		  "\nWarning: one or more errors occurred while removing %s",
   1.103 -		  name);
   1.104 -	    printf("\n");
   1.105 +	    if (stage==RAZOR_STAGE_FILES)
   1.106 +		printf("  Removing : %s ",name);
   1.107 +	    razor_package_remove(system,next,atomic,package,install_root,
   1.108 +	      count,stage);
   1.109 +	    if (stage==RAZOR_STAGE_FILES)
   1.110 +		printf("\n");
   1.111  	}
   1.112  	else
   1.113  	{
   1.114  	    razor_package_get_details(next,package,RAZOR_DETAIL_NAME,&name,
   1.115  	      RAZOR_DETAIL_VERSION,&version,RAZOR_DETAIL_ARCH,&arch,
   1.116  	      RAZOR_DETAIL_LAST);
   1.117 -	    printf("  Installing : %s ",name);
   1.118  	    s=rpm_filename(name,version,arch);
   1.119  	    file=plover_strconcat(base,"/rpms/",s,NULL);
   1.120  	    free(s);
   1.121 -	    rpm=razor_rpm_open(file);
   1.122 +	    rpm=razor_rpm_open(file,atomic);
   1.123 +	    free(file);
   1.124  	    if (!rpm)
   1.125 -	    {
   1.126 -		fprintf(stderr,"failed to open rpm %s\n",file);
   1.127 -		free(file);
   1.128 -		razor_install_iterator_destroy(ii);
   1.129  		return -1;
   1.130 -	    }
   1.131 +	    if (stage==RAZOR_STAGE_FILES)
   1.132 +		printf("  Installing : %s ",name);
   1.133  	    if (relocations)
   1.134  		razor_rpm_set_relocations(rpm,relocations);
   1.135  	    razor_transaction_fixup_package(trans,package,rpm);
   1.136 -	    if (razor_rpm_install(rpm,install_root,1)<0)
   1.137 -	    {
   1.138 -		fprintf(stderr,"failed to install rpm %s\n",file);
   1.139 -		razor_rpm_close(rpm);
   1.140 -		free(file);
   1.141 -		razor_install_iterator_destroy(ii);
   1.142 -		return -1;
   1.143 -	    }
   1.144 +	    razor_rpm_install(rpm,atomic,install_root,1,stage);
   1.145  	    razor_rpm_close(rpm);
   1.146 -	    free(file);
   1.147 -	    printf("\n");
   1.148 +	    if (stage==RAZOR_STAGE_FILES)
   1.149 +		printf("\n");
   1.150  	}
   1.151 +	if (razor_atomic_in_error_state(atomic))
   1.152 +	    return -1;
   1.153      }
   1.154 +    return 0;
   1.155 +}
   1.156 +
   1.157 +/*
   1.158 + * Note: plover_commit_transaction() takes ownership of root which should
   1.159 + * not be used after it returns.
   1.160 + */
   1.161 +int plover_commit_transaction(struct razor_transaction *trans,const char *base,
   1.162 +  const char *install_root,struct razor_root *root,struct razor_atomic *atomic,
   1.163 +  struct razor_relocations *relocations)
   1.164 +{
   1.165 +    int retval;
   1.166 +    struct razor_set *next,*system;
   1.167 +    struct razor_install_iterator *ii;
   1.168 +    razor_transaction_resolve(trans);
   1.169 +    if (razor_transaction_describe(trans)>0)
   1.170 +    {
   1.171 +	razor_root_close(root);
   1.172 +	return -1;
   1.173 +    }
   1.174 +    next=razor_transaction_commit(trans);
   1.175 +    system=razor_root_get_system_set(root);
   1.176 +    ii=razor_set_create_install_iterator(system,next);
   1.177 +    plover_run_transaction(trans,ii,base,install_root,system,next,atomic,
   1.178 +      relocations,RAZOR_STAGE_SCRIPTS_PRE);
   1.179 +    plover_run_transaction(trans,ii,base,install_root,system,next,atomic,
   1.180 +      relocations,RAZOR_STAGE_FILES);
   1.181 +    razor_root_update(root,next);
   1.182 +    razor_root_commit(root);
   1.183 +    retval=razor_atomic_commit(atomic);
   1.184 +    if (!retval)
   1.185 +	plover_run_transaction(trans,ii,base,install_root,system,next,atomic,
   1.186 +	  relocations,RAZOR_STAGE_SCRIPTS_POST);
   1.187 +    razor_set_unref(next);
   1.188      razor_install_iterator_destroy(ii);
   1.189 -    return 0;
   1.190 +    return retval;
   1.191  }
   1.192  
   1.193  static int plover_mark_package_for_update(struct razor_transaction *trans,
   1.194 @@ -180,13 +223,14 @@
   1.195  
   1.196  int plover_install(const char *base,const char *prefix,char **pkgs)
   1.197  {
   1.198 -    int i;
   1.199 +    int i,retval;
   1.200      char *s;
   1.201      char *install_root;
   1.202      struct razor_root *root;
   1.203 -    struct razor_set *system,*set,*upstream,*next;
   1.204 +    struct razor_set *system,*set,*upstream;
   1.205      struct razor_transaction *trans;
   1.206      struct razor_relocations *relocations;
   1.207 +    struct razor_atomic *atomic;
   1.208      install_root=getenv("RAZOR_ROOT");
   1.209      if (!install_root)
   1.210  	install_root="";
   1.211 @@ -195,82 +239,110 @@
   1.212  	relocations=razor_relocations_create();
   1.213  	razor_relocations_add(relocations,"/usr",prefix);
   1.214      }
   1.215 +    else
   1.216 +	relocations=NULL;
   1.217 +    atomic=razor_atomic_open("Install packages");
   1.218      /*
   1.219       * Calling razor_root_open() on a system that hasn't yet had
   1.220       * razor_root_create() run generates a confusing error message
   1.221       * on stderr. Avoid this by trying to open it R/O first which
   1.222       * fails without generating any error.
   1.223       */
   1.224 -    set=razor_root_open_read_only(install_root);
   1.225 +    set=razor_root_open_read_only(install_root,atomic);
   1.226      if (set)
   1.227 -	razor_set_destroy(set);
   1.228 +	razor_set_unref(set);
   1.229      else
   1.230  	razor_root_create(install_root);
   1.231 -    root=razor_root_open(install_root);
   1.232 +    root=razor_root_open(install_root,atomic);
   1.233      if (!root)
   1.234 +    {
   1.235 +	fprintf(stderr,"%s\n",razor_atomic_get_error_msg(atomic));
   1.236 +	razor_atomic_destroy(atomic);
   1.237 +	if (relocations)
   1.238 +	    razor_relocations_destroy(relocations);
   1.239  	return -1;
   1.240 +    }
   1.241      system=razor_root_get_system_set(root);
   1.242      if (!system)
   1.243      {
   1.244 +	fprintf(stderr,"%s\n",razor_atomic_get_error_msg(atomic));
   1.245  	razor_root_close(root);
   1.246 +	razor_atomic_destroy(atomic);
   1.247 +	if (relocations)
   1.248 +	    razor_relocations_destroy(relocations);
   1.249  	return -1;
   1.250      }
   1.251      s=plover_strconcat(base,"/repodata",NULL);
   1.252 -    if (!s)
   1.253 +    if (s)
   1.254      {
   1.255 +	retval=chdir(s);
   1.256 +	if (retval<0)
   1.257 +	    perror(s);
   1.258 +    }
   1.259 +    else
   1.260 +	retval=-1;
   1.261 +    free(s);
   1.262 +    if (retval<0)
   1.263 +    {
   1.264 +	fprintf(stderr,"%s\n",razor_atomic_get_error_msg(atomic));
   1.265  	razor_root_close(root);
   1.266 +	razor_atomic_destroy(atomic);
   1.267 +	if (relocations)
   1.268 +	    razor_relocations_destroy(relocations);
   1.269  	return -1;
   1.270      }
   1.271 -    if (chdir(s)<0)
   1.272 +    set=plover_razor_set_create_from_yum(base);
   1.273 +    if (set)
   1.274      {
   1.275 -	perror(s);
   1.276 -	free(s);
   1.277 +	upstream=plover_relocate_packages(set,atomic,base,relocations);
   1.278 +	razor_set_unref(set);
   1.279 +    }
   1.280 +    else
   1.281 +	upstream=NULL;
   1.282 +    if (!upstream)
   1.283 +    {
   1.284 +	fprintf(stderr,"%s\n",razor_atomic_get_error_msg(atomic));
   1.285  	razor_root_close(root);
   1.286 +	razor_atomic_destroy(atomic);
   1.287 +	if (relocations)
   1.288 +	    razor_relocations_destroy(relocations);
   1.289  	return -1;
   1.290      }
   1.291 -    free(s);
   1.292 -    set=plover_razor_set_create_from_yum(base);
   1.293 -    if (!set)
   1.294 -    {
   1.295 -	razor_root_close(root);
   1.296 -	return -1;
   1.297 -    }
   1.298 -    upstream=plover_relocate_packages(set,base,relocations);
   1.299 -    razor_set_destroy(set);
   1.300      trans=razor_transaction_create(system,upstream);
   1.301 +    razor_set_unref(upstream);
   1.302      for(i=0;pkgs[i];i++)
   1.303  	if (plover_mark_package_for_update(trans,system,pkgs[i]) &&
   1.304  	  plover_mark_package_for_update(trans,upstream,pkgs[i]))
   1.305  	{
   1.306  	    fprintf(stderr,"%s: Package not found\n",pkgs[i]);
   1.307 -	    razor_root_close(root);
   1.308 -	    return -1;
   1.309 +	    retval=-1;
   1.310 +	    break;
   1.311  	}
   1.312 -    razor_transaction_resolve(trans);
   1.313 -    if (razor_transaction_describe(trans)>0)
   1.314 +    if (!retval)
   1.315      {
   1.316 +	retval=plover_commit_transaction(trans,base,install_root,root,atomic,
   1.317 +	  relocations);
   1.318 +	if (retval)
   1.319 +	    fprintf(stderr,"%s\n",razor_atomic_get_error_msg(atomic));
   1.320 +    }
   1.321 +    else
   1.322  	razor_root_close(root);
   1.323 -	return -1;
   1.324 -    }
   1.325 -    next=razor_transaction_commit(trans);
   1.326 -    plover_run_transaction(trans,base,install_root,system,next,relocations);
   1.327 -    razor_root_update(root,next);
   1.328      razor_transaction_destroy(trans);
   1.329 -    razor_set_destroy(next);
   1.330 -    razor_set_destroy(upstream);
   1.331 -    if (prefix)
   1.332 +    razor_atomic_destroy(atomic);
   1.333 +    if (relocations)
   1.334  	razor_relocations_destroy(relocations);
   1.335 -    return razor_root_commit(root);
   1.336 +    return retval;
   1.337  }
   1.338  
   1.339  int plover_update(const char *base,const char *prefix,char **pkgs)
   1.340  {
   1.341 -    int i;
   1.342 +    int i,retval;
   1.343      char *install_root,*s;
   1.344      struct razor_root *root;
   1.345 -    struct razor_set *system,*set,*upstream,*next;
   1.346 +    struct razor_set *system,*set,*upstream;
   1.347      struct razor_transaction *trans;
   1.348      struct razor_relocations *relocations;
   1.349 +    struct razor_atomic *atomic;
   1.350      install_root=getenv("RAZOR_ROOT");
   1.351      if (!install_root)
   1.352  	install_root="";
   1.353 @@ -279,73 +351,101 @@
   1.354  	relocations=razor_relocations_create();
   1.355  	razor_relocations_add(relocations,"/usr",prefix);
   1.356      }
   1.357 -    set=razor_root_open_read_only(install_root);
   1.358 +    else
   1.359 +	relocations=NULL;
   1.360 +    atomic=razor_atomic_open("Update packages");
   1.361 +    set=razor_root_open_read_only(install_root,atomic);
   1.362      if (!set)
   1.363 +    {
   1.364 +	fprintf(stderr,"%s\n",razor_atomic_get_error_msg(atomic));
   1.365 +	razor_atomic_destroy(atomic);
   1.366 +	if (relocations)
   1.367 +	    razor_relocations_destroy(relocations);
   1.368  	return 0;
   1.369 -    razor_set_destroy(set);
   1.370 -    root=razor_root_open(install_root);
   1.371 +    }
   1.372 +    razor_set_unref(set);
   1.373 +    root=razor_root_open(install_root,atomic);
   1.374      if (!root)
   1.375 +    {
   1.376 +	fprintf(stderr,"%s\n",razor_atomic_get_error_msg(atomic));
   1.377 +	razor_atomic_destroy(atomic);
   1.378 +	if (relocations)
   1.379 +	    razor_relocations_destroy(relocations);
   1.380  	return -1;
   1.381 +    }
   1.382      system=razor_root_get_system_set(root);
   1.383      if (!system)
   1.384      {
   1.385 +	fprintf(stderr,"%s\n",razor_atomic_get_error_msg(atomic));
   1.386  	razor_root_close(root);
   1.387 +	razor_atomic_destroy(atomic);
   1.388 +	if (relocations)
   1.389 +	    razor_relocations_destroy(relocations);
   1.390  	return -1;
   1.391      }
   1.392      s=plover_strconcat(base,"/repodata",NULL);
   1.393 -    if (!s)
   1.394 +    if (s)
   1.395      {
   1.396 +	retval=chdir(s);
   1.397 +	if (retval)
   1.398 +	    perror(s);
   1.399 +    }
   1.400 +    else
   1.401 +	retval=-1;
   1.402 +    free(s);
   1.403 +    if (retval)
   1.404 +    {
   1.405 +	fprintf(stderr,"%s\n",razor_atomic_get_error_msg(atomic));
   1.406  	razor_root_close(root);
   1.407 +	razor_atomic_destroy(atomic);
   1.408 +	if (relocations)
   1.409 +	    razor_relocations_destroy(relocations);
   1.410  	return -1;
   1.411      }
   1.412 -    if (chdir(s)<0)
   1.413 +    set=plover_razor_set_create_from_yum(base);
   1.414 +    if (set)
   1.415      {
   1.416 -	perror(s);
   1.417 -	free(s);
   1.418 +	upstream=plover_relocate_packages(set,atomic,base,relocations);
   1.419 +	razor_set_unref(set);
   1.420 +    }
   1.421 +    else
   1.422 +	upstream=NULL;
   1.423 +    if (!upstream)
   1.424 +    {
   1.425 +	fprintf(stderr,"%s\n",razor_atomic_get_error_msg(atomic));
   1.426  	razor_root_close(root);
   1.427 +	razor_atomic_destroy(atomic);
   1.428 +	if (relocations)
   1.429 +	    razor_relocations_destroy(relocations);
   1.430  	return -1;
   1.431      }
   1.432 -    free(s);
   1.433 -    set=plover_razor_set_create_from_yum(base);
   1.434 -    if (!set)
   1.435 -    {
   1.436 -	razor_root_close(root);
   1.437 -	return -1;
   1.438 -    }
   1.439 -    upstream=plover_relocate_packages(set,base,relocations);
   1.440 -    razor_set_destroy(set);
   1.441      trans=razor_transaction_create(system,upstream);
   1.442 +    razor_set_unref(upstream);
   1.443      if (pkgs)
   1.444  	for(i=0;pkgs[i];i++)
   1.445  	{
   1.446  	    if (plover_mark_package_for_update(trans,system,pkgs[i]))
   1.447  	    {
   1.448  		fprintf(stderr,"%s: Package not found\n",pkgs[i]);
   1.449 -		razor_transaction_destroy(trans);
   1.450 -		razor_set_destroy(upstream);
   1.451 -		razor_set_destroy(system);
   1.452 -		razor_root_close(root);
   1.453 -		return -1;
   1.454 +		retval=-1;
   1.455 +		break;
   1.456  	    }
   1.457  	}
   1.458      else
   1.459  	razor_transaction_update_all(trans);
   1.460 -    razor_transaction_resolve(trans);
   1.461 -    if (razor_transaction_describe(trans)>0)
   1.462 -    {
   1.463 -	razor_transaction_destroy(trans);
   1.464 -	razor_set_destroy(upstream);
   1.465 -	razor_set_destroy(system);
   1.466 +    if (!retval) {
   1.467 +	retval=plover_commit_transaction(trans,base,install_root,root,atomic,
   1.468 +	  relocations);
   1.469 +	if (retval)
   1.470 +	    fprintf(stderr,"%s\n",razor_atomic_get_error_msg(atomic));
   1.471 +    }
   1.472 +    else
   1.473  	razor_root_close(root);
   1.474 -	return -1;
   1.475 -    }
   1.476 -    next=razor_transaction_commit(trans);
   1.477 -    plover_run_transaction(trans,base,install_root,system,next,relocations);
   1.478 -    razor_root_update(root,next);
   1.479      razor_transaction_destroy(trans);
   1.480 -    razor_set_destroy(next);
   1.481 -    razor_set_destroy(upstream);
   1.482 -    return razor_root_commit(root);
   1.483 +    if (relocations)
   1.484 +	razor_relocations_destroy(relocations);
   1.485 +    razor_atomic_destroy(atomic);
   1.486 +    return retval;
   1.487  }
   1.488  
   1.489  static int plover_mark_packages_for_removal(struct razor_transaction *trans,
   1.490 @@ -371,58 +471,108 @@
   1.491  
   1.492  int plover_remove(char **pkgs)
   1.493  {
   1.494 -    int i;
   1.495 +    int i,retval=0;
   1.496      char *install_root;
   1.497      struct razor_root *root;
   1.498 -    struct razor_set *system,*set,*upstream,*next;
   1.499 +    struct razor_set *system,*set,*upstream;
   1.500      struct razor_transaction *trans;
   1.501 +    struct razor_atomic *atomic;
   1.502      install_root=getenv("RAZOR_ROOT");
   1.503      if (!install_root)
   1.504  	install_root="";
   1.505 -    set=razor_root_open_read_only(install_root);
   1.506 +    atomic=razor_atomic_open("Remove packages");
   1.507 +    set=razor_root_open_read_only(install_root,atomic);
   1.508      if (!set)
   1.509 +    {
   1.510 +	fprintf(stderr,"%s\n",razor_atomic_get_error_msg(atomic));
   1.511 +	razor_atomic_destroy(atomic);
   1.512  	return 0;
   1.513 -    razor_set_destroy(set);
   1.514 -    root=razor_root_open(install_root);
   1.515 +    }
   1.516 +    razor_set_unref(set);
   1.517 +    root=razor_root_open(install_root,atomic);
   1.518      if (!root)
   1.519 +    {
   1.520 +	fprintf(stderr,"%s\n",razor_atomic_get_error_msg(atomic));
   1.521 +	razor_atomic_destroy(atomic);
   1.522  	return -1;
   1.523 +    }
   1.524      system=razor_root_get_system_set(root);
   1.525      if (!system)
   1.526      {
   1.527 +	fprintf(stderr,"%s\n",razor_atomic_get_error_msg(atomic));
   1.528  	razor_root_close(root);
   1.529 +	razor_atomic_destroy(atomic);
   1.530  	return -1;
   1.531      }
   1.532      upstream=razor_set_create_without_root();
   1.533      trans=razor_transaction_create(system,upstream);
   1.534 +    razor_set_unref(upstream);
   1.535      if (pkgs)
   1.536  	for(i=0;pkgs[i];i++)
   1.537  	{
   1.538  	    if (plover_mark_packages_for_removal(trans,system,pkgs[i]))
   1.539  	    {
   1.540  		fprintf(stderr,"%s: Package not found\n",pkgs[i]);
   1.541 -		razor_transaction_destroy(trans);
   1.542 -		razor_set_destroy(upstream);
   1.543 -		razor_set_destroy(system);
   1.544 -		razor_root_close(root);
   1.545 -		return -1;
   1.546 +		retval=-1;
   1.547 +		break;
   1.548  	    }
   1.549  	}
   1.550      else
   1.551  	plover_mark_packages_for_removal(trans,system,NULL);
   1.552 -    razor_transaction_resolve(trans);
   1.553 -    if (razor_transaction_describe(trans)>0)
   1.554 +    if (!retval)
   1.555      {
   1.556 -	razor_transaction_destroy(trans);
   1.557 -	razor_set_destroy(upstream);
   1.558 -	razor_set_destroy(system);
   1.559 +	retval=
   1.560 +	  plover_commit_transaction(trans,NULL,install_root,root,atomic,NULL);
   1.561 +	if (retval)
   1.562 +	    fprintf(stderr,"%s\n",razor_atomic_get_error_msg(atomic));
   1.563 +    }
   1.564 +    else
   1.565  	razor_root_close(root);
   1.566 -	return -1;
   1.567 +    razor_transaction_destroy(trans);
   1.568 +    razor_atomic_destroy(atomic);
   1.569 +    return retval;
   1.570 +}
   1.571 +
   1.572 +/*
   1.573 + * Note: If there are no installed files, then any prefix will match.
   1.574 + */
   1.575 +
   1.576 +int plover_installed_files_match_prefix(const char *prefix)
   1.577 +{
   1.578 +    int len,matches=1;
   1.579 +    const char *name;
   1.580 +    char *install_root;
   1.581 +    struct razor_set *set;
   1.582 +    struct razor_atomic *atomic;
   1.583 +    struct razor_package *package;
   1.584 +    struct razor_package_iterator *pi;
   1.585 +    struct razor_file_iterator *fi;
   1.586 +    len=strlen(prefix);
   1.587 +    while(len && prefix[len-1]=='/')
   1.588 +	len--;
   1.589 +    install_root=getenv("RAZOR_ROOT");
   1.590 +    if (!install_root)
   1.591 +	install_root="";
   1.592 +    atomic=razor_atomic_open("Query packages");
   1.593 +    set=razor_root_open_read_only(install_root,atomic);
   1.594 +    if (set)
   1.595 +    {
   1.596 +	pi=razor_package_iterator_create(set);
   1.597 +	while (matches &&
   1.598 +	  razor_package_iterator_next(pi,&package,RAZOR_DETAIL_LAST))
   1.599 +	{
   1.600 +	    fi=razor_file_iterator_create(set,package,0);
   1.601 +	    while (matches && razor_file_iterator_next(fi,&name))
   1.602 +	    {
   1.603 +		if (strncmp(name,prefix,len) ||
   1.604 +		  name[len]!='\0' && name[len]!='/')
   1.605 +		    matches=0;
   1.606 +	    }
   1.607 +	    razor_file_iterator_destroy(fi);
   1.608 +	}
   1.609 +	razor_package_iterator_destroy(pi);
   1.610 +	razor_set_unref(set);
   1.611      }
   1.612 -    next=razor_transaction_commit(trans);
   1.613 -    plover_run_transaction(trans,NULL,install_root,system,next,NULL);
   1.614 -    razor_root_update(root,next);
   1.615 -    razor_transaction_destroy(trans);
   1.616 -    razor_set_destroy(next);
   1.617 -    razor_set_destroy(upstream);
   1.618 -    return razor_root_commit(root);
   1.619 +    razor_atomic_destroy(atomic);
   1.620 +    return matches;
   1.621  }