17981 pkg set-publisher -P with -p should put new publishers first in search order
--- a/src/client.py Thu Mar 24 09:01:53 2011 +0000
+++ b/src/client.py Thu Mar 24 11:06:45 2011 -0700
@@ -3120,6 +3120,7 @@
updated = []
failed = []
+ last_pub = None
for src_pub in pubs:
prefix = src_pub.prefix
if name and prefix != name:
@@ -3148,6 +3149,15 @@
unset_props=unset_props)
if rval == EXIT_OK:
added.append(prefix)
+
+ if preferred:
+ if not last_pub:
+ api_inst.set_preferred_publisher(
+ prefix=prefix)
+ else:
+ api_inst.set_pub_search_after(prefix,
+ last_pub)
+ last_pub = prefix
else:
# The update case is special and requires some
# finesse. In particular, the update should
--- a/src/man/pkg.1.txt Thu Mar 24 09:01:53 2011 +0000
+++ b/src/man/pkg.1.txt Thu Mar 24 11:06:45 2011 -0700
@@ -765,7 +765,8 @@
new packages, this publisher will be searched first.
Updates to already installed packages will come from the
same publisher that originally provided the package so long
- as that publisher remains sticky.
+ as that publisher remains sticky. When used with -p, only new
+ publishers added will be placed first in search order.
With --non-sticky, specify that higher ranked publishers than
this one may provide updates to packages originally installed
@@ -776,11 +777,13 @@
With --search-before, alter the publisher search order so that
the publisher being modified is now searched before the specified
- publisher.
+ publisher. When used with -p, it is only applied to new
+ publishers.
With --search-after, alter the publisher search order so that
the publisher being modified is now searched after the specified
- publisher.
+ publisher. When used with -p, it is only applied to new
+ publishers.
With --approve-ca-cert, add the given certificate as a CA certificate
that is trusted. The hashes of the user approved CA certificates are
--- a/src/tests/cli/t_pkg_publisher.py Thu Mar 24 09:01:53 2011 +0000
+++ b/src/tests/cli/t_pkg_publisher.py Thu Mar 24 11:06:45 2011 -0700
@@ -677,8 +677,30 @@
self.dcs[6].get_repodir())
self.pkg("unset-publisher test3")
self.dcs[6].refresh()
- self.pkg("set-publisher -p %s" % durl6)
- self.pkg("publisher test3 test2")
+ self.pkg("set-publisher -P -p %s" % durl6)
+
+ # Determine publisher order from output and then verify it
+ # matches expected.
+ def get_pubs():
+ self.pkg("publisher -HF tsv")
+ pubs = []
+ for l in self.output.splitlines():
+ pub, ignored = l.split("\t", 1)
+ if pub not in pubs:
+ pubs.append(pub)
+ return pubs
+
+ # Since -P was used, new publishers should be set first in
+ # search order alphabetically.
+ self.assertEqual(get_pubs(), ["test2", "test3", "test1"])
+
+ # Now change search order and verify that using -P and -p again
+ # won't change it since publishers already exist.
+ self.pkg("set-publisher --search-after=test1 test2")
+ self.pkg("set-publisher --search-after=test2 test3")
+ self.assertEqual(get_pubs(), ["test1", "test2", "test3"])
+ self.pkg("set-publisher -P -p %s" % durl6)
+ self.assertEqual(get_pubs(), ["test1", "test2", "test3"])
def test_set_mirrors_origins(self):
"""Test set-publisher functionality for mirrors and origins."""