1.1 --- a/plover/razor.c Fri Jul 08 08:26:29 2016 +0100
1.2 +++ b/plover/razor.c Sat Jul 16 11:07:18 2016 +0100
1.3 @@ -18,6 +18,7 @@
1.4 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1.5 */
1.6
1.7 +#define _GNU_SOURCE
1.8 #include <stdlib.h>
1.9 #include <stdio.h>
1.10 #include <stdarg.h>
1.11 @@ -48,7 +49,7 @@
1.12 * is met (in which case the action is consumed).
1.13 */
1.14 int plover_run_transaction(struct razor_transaction *trans,
1.15 - struct razor_install_iterator *ii,const char *install_root,
1.16 + struct razor_install_iterator *ii,const char *root_uri,
1.17 struct razor_set *system,PloverPackageSet *next,PloverRepository *upstream,
1.18 struct razor_atomic *atomic,struct razor_relocations *relocations,
1.19 enum razor_stage_type stage,GCancellable *cancellable)
1.20 @@ -62,12 +63,9 @@
1.21 int r,count;
1.22 GError *tmp_error=NULL;
1.23 PloverPackage *package;
1.24 - GFile *file;
1.25 - gchar *uri;
1.26 plover__uri_handler_init();
1.27 - file=g_file_new_for_path(*install_root?install_root:"/");
1.28 - uri=g_file_get_uri(file);
1.29 - g_object_unref(file);
1.30 + if (!*root_uri)
1.31 + root_uri="file:/";
1.32 switch(stage)
1.33 {
1.34 case RAZOR_STAGE_SCRIPTS_PRE:
1.35 @@ -89,7 +87,6 @@
1.36 {
1.37 razor_atomic_abort(atomic,PLOVER_GENERAL_ERROR,
1.38 PLOVER_GENERAL_ERROR_CANCELLED,"Operation was cancelled");
1.39 - g_free(uri);
1.40 return -1;
1.41 }
1.42 if (action==RAZOR_INSTALL_ACTION_REMOVE)
1.43 @@ -99,7 +96,7 @@
1.44 if (stage==RAZOR_STAGE_FILES)
1.45 printf(" Removing : %s ",name);
1.46 r=razor_package_remove(system,plover_package_set_get_razor(next),
1.47 - atomic,pkg,uri,count,stage);
1.48 + atomic,pkg,root_uri,count,stage);
1.49 if (stage==RAZOR_STAGE_FILES)
1.50 printf("\n");
1.51 }
1.52 @@ -111,7 +108,6 @@
1.53 {
1.54 plover_propagate_g_error(&error,tmp_error);
1.55 razor_atomic_propagate_error(atomic,error,NULL);
1.56 - g_free(uri);
1.57 return -1;
1.58 }
1.59 if (stage==RAZOR_STAGE_FILES)
1.60 @@ -119,22 +115,17 @@
1.61 if (relocations)
1.62 razor_rpm_set_relocations(rpm,relocations);
1.63 razor_transaction_fixup_package(trans,pkg,rpm);
1.64 - r=razor_rpm_install(rpm,atomic,uri,1,stage);
1.65 + r=razor_rpm_install(rpm,atomic,root_uri,1,stage);
1.66 razor_rpm_close(rpm);
1.67 if (stage==RAZOR_STAGE_FILES)
1.68 printf("\n");
1.69 }
1.70 - else if (action==RAZOR_INSTALL_ACTION_COMMIT) {
1.71 - g_free(uri);
1.72 + else if (action==RAZOR_INSTALL_ACTION_COMMIT)
1.73 return 1;
1.74 - }
1.75 else
1.76 r=0;
1.77 if (razor_atomic_in_error_state(atomic))
1.78 - {
1.79 - g_free(uri);
1.80 return -1;
1.81 - }
1.82 else if (r)
1.83 {
1.84 if (action==RAZOR_INSTALL_ACTION_REMOVE)
1.85 @@ -164,7 +155,6 @@
1.86 fprintf(stderr,"error: %s, exit status %d\n",t,r);
1.87 razor_atomic_abort(atomic,PLOVER_SCRIPTLET_ERROR,r,t);
1.88 g_free(t);
1.89 - g_free(uri);
1.90 return -1;
1.91 }
1.92 else
1.93 @@ -174,7 +164,6 @@
1.94 name,version,arch,r);
1.95 }
1.96 }
1.97 - g_free(uri);
1.98 return 0;
1.99 }
1.100
1.101 @@ -209,23 +198,12 @@
1.102 GError **error)
1.103 {
1.104 gboolean retval;
1.105 - GError *tmp_error=NULL;
1.106 PloverTransaction *transaction;
1.107 - transaction=plover_transaction_new_update_uri(base_uri,prefix,pkgs,
1.108 - &tmp_error);
1.109 + transaction=plover_transaction_new_update_uri(base_uri,prefix,pkgs,error);
1.110 if (!transaction)
1.111 - {
1.112 - retval=g_error_matches(tmp_error,PLOVER_POSIX_ERROR,ENOENT);
1.113 - if (retval)
1.114 - g_error_free(tmp_error);
1.115 - else
1.116 - g_propagate_error(error,tmp_error);
1.117 - }
1.118 - else
1.119 - {
1.120 - retval=plover_transaction_commit(transaction,NULL,error);
1.121 - g_object_unref(transaction);
1.122 - }
1.123 + return FALSE;
1.124 + retval=plover_transaction_commit(transaction,NULL,error);
1.125 + g_object_unref(transaction);
1.126 return retval;
1.127 }
1.128
1.129 @@ -233,22 +211,12 @@
1.130 GError **error)
1.131 {
1.132 gboolean retval;
1.133 - GError *tmp_error=NULL;
1.134 PloverTransaction *transaction;
1.135 - transaction=plover_transaction_new_update(base,prefix,pkgs,&tmp_error);
1.136 + transaction=plover_transaction_new_update(base,prefix,pkgs,error);
1.137 if (!transaction)
1.138 - {
1.139 - retval=g_error_matches(tmp_error,PLOVER_POSIX_ERROR,ENOENT);
1.140 - if (retval)
1.141 - g_error_free(tmp_error);
1.142 - else
1.143 - g_propagate_error(error,tmp_error);
1.144 - }
1.145 - else
1.146 - {
1.147 - retval=plover_transaction_commit(transaction,NULL,error);
1.148 - g_object_unref(transaction);
1.149 - }
1.150 + return FALSE;
1.151 + retval=plover_transaction_commit(transaction,NULL,error);
1.152 + g_object_unref(transaction);
1.153 return retval;
1.154 }
1.155
1.156 @@ -284,12 +252,15 @@
1.157 }
1.158
1.159 /*
1.160 - * Note: If there are no installed files, then any prefix will match.
1.161 + * Returns:
1.162 + * 0 if there are any installed files that don't match prefix, or
1.163 + * -1 if there are no installed files at all, or
1.164 + * 1 if there are installed files and they all match prefix.
1.165 */
1.166
1.167 int plover_installed_files_match_prefix(const char *prefix)
1.168 {
1.169 - int len,matches=1;
1.170 + int len,matches=-1;
1.171 const char *name;
1.172 const char *install_root;
1.173 struct razor_set *set;
1.174 @@ -316,6 +287,8 @@
1.175 if (strncmp(name,prefix,len) ||
1.176 name[len]!='\0' && name[len]!='/')
1.177 matches=0;
1.178 + else
1.179 + matches=1;
1.180 }
1.181 razor_file_iterator_destroy(fi);
1.182 }
1.183 @@ -324,3 +297,204 @@
1.184 }
1.185 return matches;
1.186 }
1.187 +
1.188 +#include <fcntl.h>
1.189 +#include <dlfcn.h>
1.190 +
1.191 +struct razor_set_counter
1.192 +{
1.193 + struct razor_set *set;
1.194 + int count;
1.195 +};
1.196 +
1.197 +static GList *counters;
1.198 +
1.199 +static struct razor_set_counter *get_razor_set_counter(struct razor_set *set)
1.200 +{
1.201 + GList *lnk;
1.202 + struct razor_set_counter *counter;
1.203 + for(lnk=counters;lnk;lnk=lnk->next)
1.204 + {
1.205 + counter=lnk->data;
1.206 + if (counter->set==set)
1.207 + return counter;
1.208 + }
1.209 + counter=g_new(struct razor_set_counter,1);
1.210 + counter->set=set;
1.211 + counter->count=0;
1.212 + counters=g_list_prepend(counters,counter);
1.213 + return counter;
1.214 +}
1.215 +
1.216 +static void dump_razor_set_ref(struct razor_set *set)
1.217 +{
1.218 + FILE *fp;
1.219 + gchar *filename;
1.220 + void *bt[16];
1.221 + size_t len;
1.222 + struct razor_set_counter *counter;
1.223 + filename=g_strdup_printf("razor-set-%p",set);
1.224 + fp=fopen(filename,"a");
1.225 + g_free(filename);
1.226 + counter=get_razor_set_counter(set);
1.227 + counter->count++;
1.228 + fprintf(fp,"Ref %p (%d refs)\n",set,counter->count);
1.229 + fflush(fp);
1.230 + len=backtrace(bt,G_N_ELEMENTS(bt));
1.231 + backtrace_symbols_fd(bt,len,fileno(fp));
1.232 + fprintf(fp,"\n");
1.233 + fclose(fp);
1.234 +}
1.235 +
1.236 +static void dump_razor_set_unref(struct razor_set *set)
1.237 +{
1.238 + FILE *fp;
1.239 + gchar *filename;
1.240 + void *bt[16];
1.241 + size_t len;
1.242 + struct razor_set_counter *counter;
1.243 + filename=g_strdup_printf("razor-set-%p",set);
1.244 + fp=fopen(filename,"a");
1.245 + g_free(filename);
1.246 + counter=get_razor_set_counter(set);
1.247 + --counter->count;
1.248 + fprintf(fp,"Unref %p (%d refs)\n",set,counter->count);
1.249 + fflush(fp);
1.250 + len=backtrace(bt,G_N_ELEMENTS(bt));
1.251 + backtrace_symbols_fd(bt,len,fileno(fp));
1.252 + fprintf(fp,"\n");
1.253 + fclose(fp);
1.254 +}
1.255 +
1.256 +static void dump_razor_set_peek(struct razor_set *set)
1.257 +{
1.258 + FILE *fp;
1.259 + gchar *filename;
1.260 + void *bt[16];
1.261 + size_t len;
1.262 + struct razor_set_counter *counter;
1.263 + filename=g_strdup_printf("razor-set-%p",set);
1.264 + fp=fopen(filename,"a");
1.265 + g_free(filename);
1.266 + counter=get_razor_set_counter(set);
1.267 + fprintf(fp,"Peek %p (%d refs)\n",set,counter->count);
1.268 + fflush(fp);
1.269 + len=backtrace(bt,G_N_ELEMENTS(bt));
1.270 + backtrace_symbols_fd(bt,len,fileno(fp));
1.271 + fprintf(fp,"\n");
1.272 + fclose(fp);
1.273 +}
1.274 +
1.275 +struct razor_set *razor_set_create_without_root(void)
1.276 +{
1.277 + static struct razor_set *(*next)(void);
1.278 + struct razor_set *set;
1.279 + if (!next)
1.280 + next=dlsym(RTLD_NEXT,"razor_set_create_without_root");
1.281 + set=(*next)();
1.282 + dump_razor_set_ref(set);
1.283 + return set;
1.284 +}
1.285 +
1.286 +struct razor_set *razor_set_create(void)
1.287 +{
1.288 + static struct razor_set *(*next)(void);
1.289 + struct razor_set *set;
1.290 + if (!next)
1.291 + next=dlsym(RTLD_NEXT,"razor_set_create");
1.292 + set=(*next)();
1.293 + dump_razor_set_ref(set);
1.294 + return set;
1.295 +}
1.296 +
1.297 +struct razor_set *razor_set_open(const char *uri,enum razor_set_flags flags,
1.298 + struct razor_error **error)
1.299 +{
1.300 + static struct razor_set *(*next)(const char *uri,enum razor_set_flags flags,
1.301 + struct razor_error **error);
1.302 + struct razor_set *set;
1.303 + if (!next)
1.304 + next=dlsym(RTLD_NEXT,"razor_set_open");
1.305 + set=(*next)(uri,flags,error);
1.306 + dump_razor_set_ref(set);
1.307 + return set;
1.308 +}
1.309 +
1.310 +void razor_set_unref(struct razor_set *set)
1.311 +{
1.312 + static void (*next)(struct razor_set *set);
1.313 + if (!next)
1.314 + next=dlsym(RTLD_NEXT,"razor_set_unref");
1.315 + if (!set)
1.316 + abort();
1.317 + dump_razor_set_unref(set);
1.318 + (*next)(set);
1.319 +}
1.320 +
1.321 +struct razor_set *razor_set_ref(struct razor_set *set)
1.322 +{
1.323 + static struct razor_set *(*next)(struct razor_set *set);
1.324 + if (!next)
1.325 + next=dlsym(RTLD_NEXT,"razor_set_ref");
1.326 + (*next)(set);
1.327 + dump_razor_set_ref(set);
1.328 + return set;
1.329 +}
1.330 +
1.331 +struct razor_set *
1.332 + razor_install_iterator_commit_set(struct razor_install_iterator *ii)
1.333 +{
1.334 + static struct razor_set *(*next)(struct razor_install_iterator *ii);
1.335 + struct razor_set *set;
1.336 + if (!next)
1.337 + next=dlsym(RTLD_NEXT,"razor_install_iterator_commit_set");
1.338 + set=(*next)(ii);
1.339 + dump_razor_set_ref(set);
1.340 + return set;
1.341 +}
1.342 +
1.343 +struct razor_set *razor_transaction_commit(struct razor_transaction *trans)
1.344 +{
1.345 + static struct razor_set *(*next)(struct razor_transaction *trans);
1.346 + struct razor_set *set;
1.347 + if (!next)
1.348 + next=dlsym(RTLD_NEXT,"razor_transaction_commit");
1.349 + set=(*next)(trans);
1.350 + dump_razor_set_ref(set);
1.351 + return set;
1.352 +}
1.353 +
1.354 +struct razor_set *razor_importer_finish(struct razor_importer *importer)
1.355 +{
1.356 + static struct razor_set *(*next)(struct razor_importer *importer);
1.357 + struct razor_set *set;
1.358 + if (!next)
1.359 + next=dlsym(RTLD_NEXT,"razor_importer_finish");
1.360 + set=(*next)(importer);
1.361 + dump_razor_set_ref(set);
1.362 + return set;
1.363 +}
1.364 +
1.365 +struct razor_set *razor_root_open_read_only(const char *root_uri,
1.366 + struct razor_error **error)
1.367 +{
1.368 + static struct razor_set *(*next)(const char *root_uri,
1.369 + struct razor_error **error);
1.370 + struct razor_set *set;
1.371 + if (!next)
1.372 + next=dlsym(RTLD_NEXT,"razor_root_open_read_only");
1.373 + set=(*next)(root_uri,error);
1.374 + dump_razor_set_ref(set);
1.375 + return set;
1.376 +}
1.377 +
1.378 +struct razor_set *razor_root_get_system_set(struct razor_root *root)
1.379 +{
1.380 + static struct razor_set *(*next)(struct razor_root *root);
1.381 + struct razor_set *set;
1.382 + if (!next)
1.383 + next=dlsym(RTLD_NEXT,"razor_root_get_system_set");
1.384 + set=(*next)(root);
1.385 + dump_razor_set_peek(set);
1.386 + return set;
1.387 +}