Track file owner ship.
authorKristian H?gsberg <krh@redhat.com>
Mon Oct 22 22:53:55 2007 -0400 (2007-10-22)
changeset 528cb4c45dc86f
parent 51 38e3fe38939b
child 53 a73c2ac05cbe
Track file owner ship.
TODO
main.c
razor.c
razor.h
     1.1 --- a/TODO	Mon Oct 22 20:41:54 2007 -0400
     1.2 +++ b/TODO	Mon Oct 22 22:53:55 2007 -0400
     1.3 @@ -82,3 +82,7 @@
     1.4    is disk bound.  Start installing once we have self-contained set of
     1.5    packages.  Install in reverse topo-sort order.  Interruptible
     1.6    installation; stops at nearest checkpoint.
     1.7 +
     1.8 +- make packages pointers be either an index into the package pool or a
     1.9 +  direct link to a package when there is only one package.  set a high
    1.10 +  bit to indicate which it is.  similar for properties.
     2.1 --- a/main.c	Mon Oct 22 20:41:54 2007 -0400
     2.2 +++ b/main.c	Mon Oct 22 22:53:55 2007 -0400
     2.3 @@ -61,6 +61,21 @@
     2.4  }
     2.5  
     2.6  static int
     2.7 +command_list_file_packages(int argc, const char *argv[])
     2.8 +{
     2.9 +	struct razor_set *set;
    2.10 +
    2.11 +	set = razor_set_open(repo_filename);
    2.12 +	if (set == NULL)
    2.13 +		return 1;
    2.14 +	razor_set_list_file_packages(set, argv[0]);
    2.15 +	razor_set_destroy(set);
    2.16 +
    2.17 +	return 0;
    2.18 +}
    2.19 +
    2.20 +
    2.21 +static int
    2.22  command_what_requires(int argc, const char *argv[])
    2.23  {
    2.24  	struct razor_set *set;
    2.25 @@ -183,6 +198,7 @@
    2.26  	{ "list-requires", "list all requires or requires for the given package", command_list_requires },
    2.27  	{ "list-provides", "list all provides or provides for the give package", command_list_provides },
    2.28  	{ "list-files", "list files for package set", command_list_files },
    2.29 +	{ "list-file-packages", "list packages owning file", command_list_file_packages },
    2.30  	{ "what-requires", "list the packages that have the given requires", command_what_requires },
    2.31  	{ "what-provides", "list the packages that have the given provides", command_what_provides },
    2.32  	{ "import-yum", "import yum filelist.xml on stdin", command_import_yum },
     3.1 --- a/razor.c	Mon Oct 22 20:41:54 2007 -0400
     3.2 +++ b/razor.c	Mon Oct 22 22:53:55 2007 -0400
     3.3 @@ -60,6 +60,7 @@
     3.4  	unsigned long name;
     3.5  	unsigned long count;
     3.6  	unsigned long start;
     3.7 +	unsigned long packages;
     3.8  };
     3.9  
    3.10  struct razor_set {
    3.11 @@ -74,6 +75,18 @@
    3.12  	struct razor_set_header *header;
    3.13  };
    3.14  
    3.15 +struct import_entry {
    3.16 +	unsigned long package;
    3.17 +	char *name;
    3.18 +};
    3.19 +
    3.20 +struct import_directory {
    3.21 +	unsigned long name, count;
    3.22 +	struct array files;
    3.23 +	struct array packages;
    3.24 +	struct import_directory *last;
    3.25 +};
    3.26 +
    3.27  struct import_property_context {
    3.28  	struct array *all;
    3.29  	struct array package;
    3.30 @@ -463,10 +476,13 @@
    3.31  void
    3.32  razor_importer_add_file(struct razor_importer *importer, const char *name)
    3.33  {
    3.34 -	char **p;
    3.35 +	struct import_entry *e;
    3.36  
    3.37 -	p = array_add(&importer->files, sizeof *p);
    3.38 -	*p = strdup(name);
    3.39 +	e = array_add(&importer->files, sizeof *e);
    3.40 +
    3.41 +	e->package = importer->package -
    3.42 +		(struct razor_package *) importer->set->packages.data;
    3.43 +	e->name = strdup(name);
    3.44  }
    3.45  
    3.46  struct razor_importer *
    3.47 @@ -699,22 +715,16 @@
    3.48  static int
    3.49  compare_filenames(const void *p1, const void *p2, void *data)
    3.50  {
    3.51 -	char *f1 = *(char **) p1;
    3.52 -	char *f2 = *(char **) p2;
    3.53 +	const struct import_entry *e1 = p1;
    3.54 +	const struct import_entry *e2 = p2;
    3.55  
    3.56 -	return strcmp(f1, f2);
    3.57 +	return strcmp(e1->name, e2->name);
    3.58  }
    3.59  
    3.60 -struct directory {
    3.61 -	unsigned long name, count;
    3.62 -	struct array files;
    3.63 -	struct directory *last;
    3.64 -};
    3.65 -
    3.66  static void
    3.67 -count_entries(struct directory *d)
    3.68 +count_entries(struct import_directory *d)
    3.69  {
    3.70 -	struct directory *p, *end;
    3.71 +	struct import_directory *p, *end;
    3.72  
    3.73  	p = d->files.data;
    3.74  	end = d->files.data + d->files.size;
    3.75 @@ -727,9 +737,10 @@
    3.76  }
    3.77  
    3.78  static void
    3.79 -serialize_files(struct directory *d, struct array *array)
    3.80 +serialize_files(struct razor_set *set,
    3.81 +		struct import_directory *d, struct array *array)
    3.82  {
    3.83 -	struct directory *p, *end;
    3.84 +	struct import_directory *p, *end;
    3.85  	struct razor_entry *e;
    3.86  	unsigned long s;
    3.87  
    3.88 @@ -742,13 +753,16 @@
    3.89  		e->count = p->files.size / sizeof *p;
    3.90  		e->start = s;
    3.91  		s += p->count;
    3.92 +		e->packages = add_to_property_pool(&set->package_pool,
    3.93 +						   &p->packages);
    3.94 +		array_release(&p->packages);
    3.95  		p++;
    3.96  	}		
    3.97  
    3.98  	p = d->files.data;
    3.99  	end = d->files.data + d->files.size;
   3.100  	while (p < end) {
   3.101 -		serialize_files(p, array);
   3.102 +		serialize_files(set, p, array);
   3.103  		p++;
   3.104  	}
   3.105  }
   3.106 @@ -757,26 +771,28 @@
   3.107  build_file_tree(struct razor_importer *importer)
   3.108  {
   3.109  	int count, i, length;
   3.110 -	char **filenames, *f, *end;
   3.111 -	unsigned long name;
   3.112 +	struct import_entry *filenames;
   3.113 +	char *f, *end;
   3.114 +	unsigned long name, *r;
   3.115  	char dirname[256];
   3.116 -	struct directory *d, root;
   3.117 +	struct import_directory *d, root;
   3.118  	struct razor_entry *e;
   3.119  
   3.120 -	count = importer->files.size / sizeof (char *);
   3.121 +	count = importer->files.size / sizeof (struct import_entry);
   3.122  	qsort_with_data(importer->files.data,
   3.123  			count,
   3.124 -			sizeof (char *),
   3.125 +			sizeof (struct import_entry),
   3.126  			compare_filenames,
   3.127  			NULL);
   3.128  
   3.129  	root.name = razor_importer_tokenize(importer, "");
   3.130  	array_init(&root.files);
   3.131 +	array_init(&root.packages);
   3.132  	root.last = NULL;
   3.133  
   3.134  	filenames = importer->files.data;
   3.135  	for (i = 0; i < count; i++) {
   3.136 -		f = filenames[i];
   3.137 +		f = filenames[i].name;
   3.138  		if (*f != '/')
   3.139  			continue;
   3.140  
   3.141 @@ -794,12 +810,15 @@
   3.142  				d->last->name = name;
   3.143  				d->last->last = NULL;
   3.144  				array_init(&d->last->files);
   3.145 +				array_init(&d->last->packages);
   3.146  			}
   3.147  			d = d->last;				
   3.148  			f = end;
   3.149  		}
   3.150  
   3.151 -		free(filenames[i]);
   3.152 +		r = array_add(&d->packages, sizeof *r);
   3.153 +		*r = filenames[i].package;
   3.154 +		free(filenames[i].name);
   3.155  	}
   3.156  
   3.157  	count_entries(&root);
   3.158 @@ -810,7 +829,7 @@
   3.159  	e->count = root.files.size / sizeof *d;
   3.160  	e->start = 1;
   3.161  
   3.162 -	serialize_files(&root, &importer->set->file_tree);
   3.163 +	serialize_files(importer->set, &root, &importer->set->file_tree);
   3.164  
   3.165  	array_release(&importer->files);
   3.166  }
   3.167 @@ -867,6 +886,27 @@
   3.168  	list_dir(set, e, 2);
   3.169  }
   3.170  
   3.171 +void
   3.172 +razor_set_list_file_packages(struct razor_set *set, const char *filename)
   3.173 +{
   3.174 +	struct razor_entry *e;
   3.175 +	struct razor_package *packages, *p;
   3.176 +	const char *pool;
   3.177 +	unsigned long *r;
   3.178 +
   3.179 +	e = find_entry(set, set->file_tree.data, filename);
   3.180 +	if (e == NULL)
   3.181 +		return;
   3.182 +	
   3.183 +	r = (unsigned long *) set->package_pool.data + e->packages;
   3.184 +	packages = set->packages.data;
   3.185 +	pool = set->string_pool.data;
   3.186 +	while (~*r) {
   3.187 +		p = &packages[*r++];
   3.188 +		printf("%s %s\n", &pool[p->name], &pool[p->version]);
   3.189 +	}
   3.190 +}
   3.191 +
   3.192  struct razor_set *
   3.193  razor_importer_finish(struct razor_importer *importer)
   3.194  {
   3.195 @@ -892,12 +932,11 @@
   3.196  	rmap = malloc(count * sizeof *rmap);
   3.197  	for (i = 0; i < count; i++)
   3.198  		rmap[map[i]] = i;
   3.199 -
   3.200 -	remap_links(&importer->set->package_pool, rmap);
   3.201  	free(map);
   3.202 -	free(rmap);
   3.203  
   3.204  	build_file_tree(importer);
   3.205 +	remap_links(&importer->set->package_pool, rmap);
   3.206 +	free(rmap);
   3.207  
   3.208  	set = importer->set;
   3.209  	array_release(&importer->buckets);
     4.1 --- a/razor.h	Mon Oct 22 20:41:54 2007 -0400
     4.2 +++ b/razor.h	Mon Oct 22 22:53:55 2007 -0400
     4.3 @@ -19,6 +19,7 @@
     4.4  				      const char *name,
     4.5  				      const char *version);
     4.6  void razor_set_list_files(struct razor_set *set, const char *prefix);
     4.7 +void razor_set_list_file_packages(struct razor_set *set, const char *filename);
     4.8  
     4.9  void razor_set_list_unsatisfied(struct razor_set *set);
    4.10  struct razor_set *razor_set_update(struct razor_set *set,