[PATCH 1/4] Add the last element of URL path to site chooser, if interesting.

Jon TURNEY jon.turney@dronecode.org.uk
Fri Nov 26 13:49:00 GMT 2010


Currently, for example, if 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)

(Also use LB_FINDSTRINGEXACT rather than LB_FINDSTRING so selected sites are restored correctly if they
have a common initial substring)

2010-11-26  Jon TURNEY  <jon.turney@dronecode.org.uk>

	* site.cc (init): If interesting, show the last element
	of URL, as well as the protocol and sitename in the site chooser.
	(PopulateListBox) Use LB_FINDSTRINGEXACT.

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
---
 site.cc |   29 +++++++++++++++++++++++++++--
 1 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/site.cc b/site.cc
index 2e58c2f..42839f3 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,
@@ -627,7 +652,7 @@ SitePage::PopulateListBox ()
   for (SiteList::const_iterator n = site_list.begin ();
        n != site_list.end (); ++n)
     {
-      int index = SendMessage (listbox, LB_FINDSTRING, (WPARAM) - 1,
+      int index = SendMessage (listbox, LB_FINDSTRINGEXACT, (WPARAM) - 1,
 			       (LPARAM) n->displayed_url.c_str());
       if (index != LB_ERR)
 	{
-- 
1.7.2.3



More information about the Cygwin-apps mailing list