1266 Client loses track of authority preference, chaos ensues
authorjohansen <johansen@sun.com>
Wed, 16 Apr 2008 15:45:04 -0700
changeset 331 4f332d6b4036
parent 330 5619f72b91c2
child 332 c4547bf88d96
1266 Client loses track of authority preference, chaos ensues
src/client.py
src/modules/client/filelist.py
src/modules/client/image.py
src/modules/client/retrieve.py
src/modules/fmri.py
--- a/src/client.py	Wed Apr 16 15:24:51 2008 -0700
+++ b/src/client.py	Wed Apr 16 15:45:04 2008 -0700
@@ -674,8 +674,9 @@
                         print
 
                 authority, name, version = m.fmri.tuple()
+                authority = fmri.strip_auth_pfx(authority)
                 summary = m.get("description", "")
-                if authority == img.get_default_authority():
+                if m.fmri.preferred_authority():
                         authority += _(" (preferred)")
 
                 print "          Name:", name
--- a/src/modules/client/filelist.py	Wed Apr 16 15:24:51 2008 -0700
+++ b/src/modules/client/filelist.py	Wed Apr 16 15:45:04 2008 -0700
@@ -32,6 +32,7 @@
 
 import pkg.pkgtarfile as ptf
 import pkg.portable as portable
+import pkg.fmri
 from pkg.misc import versioned_urlopen
 
 class FileList(object):
@@ -122,6 +123,7 @@
                 req_dict = { }
 
                 authority, pkg_name, version = self.fmri.tuple()
+                authority = pkg.fmri.strip_auth_pfx(authority)
                 url_prefix = self.image.get_url_by_authority(authority)
                 ssl_tuple = self.image.get_ssl_credentials(authority)
 
--- a/src/modules/client/image.py	Wed Apr 16 15:24:51 2008 -0700
+++ b/src/modules/client/image.py	Wed Apr 16 15:45:04 2008 -0700
@@ -542,8 +542,7 @@
 
                 return m
 
-        @staticmethod
-        def installed_file_authority(filepath):
+        def installed_file_authority(self, filepath):
                 """Find the pkg's installed file named by filepath.
                 Return the authority that installed this package."""
 
@@ -584,6 +583,10 @@
 
                 f.close()
 
+                if not auth:
+                        auth = "%s_%s" % (pkg.fmri.PREF_AUTH_PFX,
+                            self.get_default_authority())
+
                 return auth
 
         def install_file_present(self, fmri):
@@ -631,8 +634,6 @@
                 assert len(pkgs_inst) <= 1
 
                 auth = self.installed_file_authority(pkgs_inst[0][1])
-                if not auth:
-                        auth = self.get_default_authority()
 
                 return pkg.fmri.PkgFmri(pkgs_inst[0][0], authority = auth)
 
@@ -918,19 +919,18 @@
                                 if not os.path.exists(path):
                                         continue
 
+                                fmristr = urllib.unquote("%s@%s" % (pd, vd))
                                 auth = self.installed_file_authority(path)
-                                if not auth:
-                                        auth = self.get_default_authority()
+                                f = pkg.fmri.PkgFmri(fmristr, authority = auth)
 
-                                fmristr = urllib.unquote("%s@%s" % (pd, vd))
-                                f = pkg.fmri.PkgFmri(fmristr, authority = auth)
                                 self.installed_pkg_cache.append(f)
                                 yield f
 
         def strtofmri(self, myfmri):
                 ret = pkg.fmri.PkgFmri(myfmri, 
-                    self.attrs["Build-Release"],
-                    authority = self.get_default_authority())
+                    self.attrs["Build-Release"])
+                self.fmri_set_default_authority(ret)
+                    
                 return ret
 
         def update_optional_dependency(self, inputfmri):
--- a/src/modules/client/retrieve.py	Wed Apr 16 15:24:51 2008 -0700
+++ b/src/modules/client/retrieve.py	Wed Apr 16 15:45:04 2008 -0700
@@ -26,6 +26,7 @@
 import socket
 import urllib2
 
+import pkg.fmri
 from pkg.misc import versioned_urlopen
 
 # client/retrieve.py - collected methods for retrieval of pkg components
@@ -35,7 +36,7 @@
         """Retrieve a file handle based on a package fmri and a file hash."""
 
         authority, pkg_name, version = fmri.tuple()
-
+        authority = pkg.fmri.strip_auth_pfx(authority)
         url_prefix = img.get_url_by_authority(authority)
         ssl_tuple = img.get_ssl_credentials(authority)
 
@@ -62,7 +63,7 @@
             the caller. """
 
         authority, pkg_name, version = fmri.tuple()
-
+        authority = pkg.fmri.strip_auth_pfx(authority)
         url_prefix = img.get_url_by_authority(authority)
         ssl_tuple = img.get_ssl_credentials(authority)
 
--- a/src/modules/fmri.py	Wed Apr 16 15:24:51 2008 -0700
+++ b/src/modules/fmri.py	Wed Apr 16 15:45:04 2008 -0700
@@ -280,7 +280,7 @@
                 return False
 
         def tuple(self):
-                return self.get_authority(), self.pkg_name, self.version
+                return self.get_authority_str(), self.pkg_name, self.version
 
         def is_name_match(self, fmristr):
                 """True if the regular expression given in fmristr matches the
@@ -338,6 +338,16 @@
 
         return pkg_name
 
+def strip_auth_pfx(auth):
+        """Strip the PREF_AUTH_PFX off of an authority."""
+        if auth.startswith(PREF_AUTH_PFX_):
+                str = auth[len(PREF_AUTH_PFX_):]
+        else:
+                str = auth
+
+        return str
+        
+
 def is_same_authority(auth1, auth2):
         """Compare two authorities.  Return true if they are the same, false
            otherwise. """