Currently, if, for example, I manually add the site 
http://mirrors.kernel.org/sources.redhat.com/cygwinports/
to setup's mirror list, I get two indistinguishable entries named 
http://mirrors.kernel.org.

Furthermore, because the code to ensure the site just added is selected uses 
the string inside the list control
to locate elements, we end up with a random one of those two indistinguishable 
entries selected (usually the
previously existing one).  This problem also prevents the selected sites being 
correctly saved and restored
for the next setup run.

So, to make the site chooser list entries unique and distinguishable, add the 
last element of the URL path to
the site chooser, if it exists and isn't 'cygwin' (or some other alternatives 
used by current mirrors)

(Also fix the logic for identifying protocol and site name part of the URL to 
find the first '/' after a '//',
rather than the first '/' after a '.', to handle sitenames which aren't FQDNs 
correctly)

2010-11-06  Jon TURNEY  <[email protected]>

        * site.cc (init): If interesting, Show the last element of URL, as well
        as the protocol and sitename in the site chooser
---
 site.cc |   27 ++++++++++++++++++++++++++-
 1 files changed, 26 insertions(+), 1 deletions(-)

diff --git a/site.cc b/site.cc
index eacd0e9..1a65ec9 100644
--- a/site.cc
+++ b/site.cc
@@ -140,8 +140,13 @@ site_list_type::init (const string &_url, const string 
&_servername,
   servername = _servername;
   area = _area;
   location = _location;
-  displayed_url = url.substr (0, url.find ("/", url.find (".")));
 
+  /* displayed_url is protocol and site name part of url */
+  string::size_type path_offset = url.find ("/", url.find ("//") + 2);
+  displayed_url = url.substr(0, path_offset);
+
+  /* the sorting key is hostname components in reverse order (to sort by 
country code)
+     plus the url (to ensure uniqueness) */
   key = string();
   string::size_type last_idx = displayed_url.length () - 1;
   string::size_type idx = url.find_last_of("./", last_idx);
@@ -160,6 +165,26 @@ site_list_type::init (const string &_url, const string 
&_servername,
       idx = 0;
   } while (idx > 0);
   key += url;
+
+  /* add last element of url if it exists, and isn't "cygwin" to displayed_url 
*/
+  if (path_offset+1 < url.length())
+    {
+      string url_path = url.substr(path_offset+1);
+
+      /* trim any trailing / */
+      if (url_path.at(url_path.length()-1) == '/')
+        url_path.erase(url_path.length()-1);
+
+      /* add the last path element, if it exists, and isn't "cygwin"
+         (or some aliases used by existing sites) */
+      string::size_type pos = url_path.rfind('/');
+      string lpe = url_path.substr(pos+1);
+      if ((pos != string::npos) && (lpe.compare("cygwin") != 0) && 
(lpe.compare("cygwin.com") != 0)
+          && (lpe.compare("cygwin32") != 0) && (lpe.compare("gnu-win32") != 0))
+        {
+          displayed_url.append(" (" + lpe +  ")");
+        }
+    }
 }
 
 site_list_type::site_list_type (const string &_url,
-- 
1.7.2.3

Reply via email to