]>
Commit | Line | Data |
---|---|---|
a881abeb MB |
1 | commit 2f6b86835cbbad530f838bcf5d3e183f92eb3396 |
2 | Author: Marcin Banasiak <marcin.banasiak@gmail.com> | |
3 | Date: Thu Sep 27 17:44:19 2012 +0200 | |
4 | ||
5 | Change the way how / is stored in dirindex | |
6 | ||
7 | Previously, / was stored in dirindex with leading slash (i.e. as //) | |
8 | what caused various side effects as: | |
9 | ||
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 | |
13 | ||
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) | |
20 | { | |
21 | int i, size = n_array_size(arr); | |
22 | + | |
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); | |
27 | + | |
28 | + n_buf_printf(nbuf, "%s%s%s", *dirname != '/' ? "/" : "", | |
29 | + dirname, i < size - 1 ? sep : ""); | |
30 | } | |
31 | + | |
32 | return nbuf; | |
33 | } | |
34 | ||
35 | @@ -179,7 +183,8 @@ static int store_from_previous(uint32_t package_no, struct pkg *pkg, struct tndb | |
36 | ||
37 | while (*tl) { | |
38 | const char *dir = *tl; | |
39 | - dir = dir + 1; /* skip '/' */ | |
40 | + if (dir[1] != '\0') | |
41 | + dir = dir + 1; /* skip '/' only when strlen(dir) > 1 */ | |
42 | add_to_path_index(path_index, dir, package_no); | |
43 | tl++; | |
44 | } | |
45 | @@ -238,15 +243,13 @@ void store_package(uint32_t package_no, struct pkg *pkg, struct tndb *db, | |
46 | ||
47 | if (required) { | |
48 | n_buf_clean(nbuf); | |
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)); | |
53 | } | |
54 | ||
55 | if (owned) { | |
56 | n_buf_clean(nbuf); | |
57 | - n_buf_printf(nbuf, "/"); /* prefix all by '/' */ | |
58 | - nbuf = dirarray_join(nbuf, owned, ":/"); | |
59 | + nbuf = dirarray_join(nbuf, owned, ":"); | |
60 | ||
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); | |
67 | + int j; | |
68 | ||
69 | n_buf_clean(nbuf); | |
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 ? ":" : ""); | |
74 | + } | |
75 | ||
76 | DBGF(" dir %s %s\n", path, (char*)n_buf_ptr(nbuf)); | |
77 | ||
78 | @@ -774,11 +781,11 @@ tn_array *get_package_directories_as_array(const struct pkgdir *pkgdir, | |
79 | ||
80 | dirs = n_array_new(n, free, (tn_fn_cmp)strcmp); | |
81 | while (*tl) { | |
82 | - if (**tl) | |
83 | + if (**tl) | |
84 | n_array_push(dirs, n_strdup(*tl)); | |
85 | tl++; | |
86 | } | |
87 | - | |
88 | + | |
89 | n_str_tokl_free(tl_save); | |
90 | n_free(val); | |
91 | ||
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; | |
95 | ||
96 | - if (*path == '/') | |
97 | + if (*path == '/' && path[1] != '\0') | |
98 | path++; | |
99 | ||
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, | |
102 | ||
103 | DBGF("%s %s\n", pkg_id(pkg), path); | |
104 | ||
105 | - if (*path == '/') | |
106 | + if (*path == '/' && path[1] != '\0') | |
107 | path++; | |
108 | ||
109 | if (!tndb_get_str(dirindex->db, path, val, sizeof(val))) |