1 commit 2f6b86835cbbad530f838bcf5d3e183f92eb3396
2 Author: Marcin Banasiak <marcin.banasiak@gmail.com>
3 Date: Thu Sep 27 17:44:19 2012 +0200
5 Change the way how / is stored in dirindex
7 Previously, / was stored in dirindex with leading slash (i.e. as //)
8 what caused various side effects as:
10 filesystem-4.0-12.x86_64 obsoleted by filesystem-4.0-13.x86_64
11 filesystem-4.0-13.x86_64 marks FHS-2.3-35.x86_64 (cap //)
12 error: FHS-2.3-35.x86_64: equal version installed, give up
14 diff --git a/pkgdir/pkgdir_dirindex.c b/pkgdir/pkgdir_dirindex.c
15 index a6f422f..abfd05c 100644
16 --- a/pkgdir/pkgdir_dirindex.c
17 +++ b/pkgdir/pkgdir_dirindex.c
18 @@ -103,10 +103,14 @@ static int package_key(char *key, int size, const struct pkg *pkg, int prefix)
19 static tn_buf *dirarray_join(tn_buf *nbuf, tn_array *arr, char *sep)
21 int i, size = n_array_size(arr);
23 for (i=0; i < size; i++) {
24 - n_buf_printf(nbuf, "%s%s", (char*)n_array_nth(arr, i),
25 - i < size - 1 ? sep : "");
26 + const char *dirname = n_array_nth(arr, i);
28 + n_buf_printf(nbuf, "%s%s%s", *dirname != '/' ? "/" : "",
29 + dirname, i < size - 1 ? sep : "");
35 @@ -179,7 +183,8 @@ static int store_from_previous(uint32_t package_no, struct pkg *pkg, struct tndb
38 const char *dir = *tl;
39 - dir = dir + 1; /* skip '/' */
41 + dir = dir + 1; /* skip '/' only when strlen(dir) > 1 */
42 add_to_path_index(path_index, dir, package_no);
45 @@ -238,15 +243,13 @@ void store_package(uint32_t package_no, struct pkg *pkg, struct tndb *db,
49 - n_buf_printf(nbuf, "/"); /* prefix all by '/' */
50 - nbuf = dirarray_join(nbuf, required, ":/");
51 + nbuf = dirarray_join(nbuf, required, ":");
52 tndb_put(db, key, klen, n_buf_ptr(nbuf), n_buf_size(nbuf));
57 - n_buf_printf(nbuf, "/"); /* prefix all by '/' */
58 - nbuf = dirarray_join(nbuf, owned, ":/");
59 + nbuf = dirarray_join(nbuf, owned, ":");
61 /* ugly, but what for another package_key() call */
62 key[1] = PREFIX_PKGKEY_OWNDIR;
63 @@ -323,9 +326,13 @@ static int dirindex_create(const struct pkgdir *pkgdir, const char *path,
64 for (i=0; i < n_array_size(directories); i++) {
65 const char *path = n_array_nth(directories, i);
66 tn_array *ids = n_hash_get(path_index, path);
70 - nbuf = dirarray_join(nbuf, ids, ":");
71 + for (j = 0; j < n_array_size(ids); j++) {
72 + n_buf_printf(nbuf, "%s%s", (char *)n_array_nth(ids, j),
73 + j < n_array_size(ids) - 1 ? ":" : "");
76 DBGF(" dir %s %s\n", path, (char*)n_buf_ptr(nbuf));
78 @@ -774,11 +781,11 @@ tn_array *get_package_directories_as_array(const struct pkgdir *pkgdir,
80 dirs = n_array_new(n, free, (tn_fn_cmp)strcmp);
84 n_array_push(dirs, n_strdup(*tl));
89 n_str_tokl_free(tl_save);
92 @@ -809,7 +816,7 @@ static tn_array *do_dirindex_get(const struct pkgdir_dirindex *dirindex,
93 unsigned char val[8192];
94 int n, found, pkgs_passsed = 1;
97 + if (*path == '/' && path[1] != '\0')
100 if (!tndb_get_str(dirindex->db, path, val, sizeof(val)))
101 @@ -877,7 +884,7 @@ int pkgdir_dirindex_pkg_has_path(const struct pkgdir *pkgdir,
103 DBGF("%s %s\n", pkg_id(pkg), path);
106 + if (*path == '/' && path[1] != '\0')
109 if (!tndb_get_str(dirindex->db, path, val, sizeof(val)))