public inbox for cygwin-apps-cvs@sourceware.org
help / color / mirror / Atom feed
* [setup - the official Cygwin setup program] branch master, updated. release_2.905-3-gb4947fb6
@ 2020-08-22 14:54 Jon TURNEY
  0 siblings, 0 replies; only message in thread
From: Jon TURNEY @ 2020-08-22 14:54 UTC (permalink / raw)
  To: cygwin-apps-cvs




https://sourceware.org/git/gitweb.cgi?p=cygwin-apps/setup.git;h=b4947fb6db0cbd8b0c673dc49a18224c44da8116

commit b4947fb6db0cbd8b0c673dc49a18224c44da8116
Author: Jon Turney <jon.turney@dronecode.org.uk>
Date:   Mon Jul 20 15:30:44 2020 +0100

    Migrate selected sites from http:// to https://
    
    If a selected site URL saved from the last run starts with "http://",
    and an identical URL except starting with "https://" is in the current
    mirror list, migrate it from "http://" to "https://".

https://sourceware.org/git/gitweb.cgi?p=cygwin-apps/setup.git;h=57ddb743c06996e93567a98c6de6694ddcc5d616

commit 57ddb743c06996e93567a98c6de6694ddcc5d616
Author: Jon Turney <jon.turney@dronecode.org.uk>
Date:   Tue Jul 21 14:52:58 2020 +0100

    Factor out site_list_insert in site.cc
    
    Factor out site_list_insert in site.cc, and add comments to descibe what
    what nutty thing this wacky code is doing, after we've expended the
    mental effort to figure it out.

https://sourceware.org/git/gitweb.cgi?p=cygwin-apps/setup.git;h=d15c11e7954977ee27712989b36e7102fc70639e

commit d15c11e7954977ee27712989b36e7102fc70639e
Author: Jon Turney <jon.turney@dronecode.org.uk>
Date:   Mon Jul 20 17:35:47 2020 +0100

    Remove pointless variable from do_download_site_info_thread()


Diff:
---
 site.cc | 105 +++++++++++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 68 insertions(+), 37 deletions(-)

diff --git a/site.cc b/site.cc
index 46ec53a3..d5cd1e0e 100644
--- a/site.cc
+++ b/site.cc
@@ -214,6 +214,29 @@ site_list_type::operator < (site_list_type const &rhs) const
   return stricmp (key.c_str(), rhs.key.c_str()) < 0; 
 }
 
+/*
+  A SiteList is maintained as an in-order std::vector of site_list_type, by
+  replacing it with a new object with the new item inserted in the correct
+  place.
+
+  Yes, we could just use an ordered container, instead.
+*/
+static void
+site_list_insert(SiteList &site_list, site_list_type newsite)
+{
+  SiteList::iterator i = find (site_list.begin(), site_list.end(), newsite);
+  if (i == site_list.end())
+    {
+      SiteList result;
+      merge (site_list.begin(), site_list.end(),
+             &newsite, &newsite + 1,
+             inserter (result, result.begin()));
+      site_list = result;
+    }
+  else
+    *i = newsite;
+}
+
 static void
 save_dialog (HWND h)
 {
@@ -288,19 +311,7 @@ load_site_list (SiteList& theSites, char *theString)
 	    continue;
 
 	  site_list_type newsite (bol, semi, semi2, semi3, true);
-	  SiteList::iterator i = find (theSites.begin(),
-				       theSites.end(), newsite);
-	  if (i == theSites.end())
-	    {
-	      SiteList result;
-	      merge (theSites.begin(), theSites.end(),
-		     &newsite, &newsite + 1,
-		     inserter (result, result.begin()));
-	      theSites = result;
-	    }
-	  else
-	    //TODO: remove and remerge 
-	    *i = newsite;
+	  site_list_insert (theSites, newsite);
 	}
         else
         {
@@ -309,6 +320,35 @@ load_site_list (SiteList& theSites, char *theString)
     }
 }
 
+static void
+migrate_selected_site_list()
+{
+  const std::string http = "http://";
+
+  for (SiteList::iterator i = site_list.begin();
+       i != site_list.end();
+       ++i)
+    {
+      /* If the saved selected site URL starts with "http://", and the same URL,
+         but starting with "https://" appears in the mirror list, migrate to
+         "https://" */
+      if (strnicmp(i->url.c_str(), http.c_str(), strlen(http.c_str())) == 0)
+        {
+          std::string migrated_site = "https://";
+          migrated_site.append(i->url.substr(http.length()));
+
+          site_list_type migrate(migrated_site, "", "", "", false);
+          SiteList::iterator j = find (all_site_list.begin(),
+                                       all_site_list.end(), migrate);
+          if (j != all_site_list.end())
+            {
+              Log (LOG_PLAIN) << "Migrated " << i->url << " to " << migrated_site  << endLog;
+              *i = migrate;
+            }
+        }
+    }
+}
+
 static int
 get_site_list (HINSTANCE h, HWND owner)
 {
@@ -359,10 +399,12 @@ get_site_list (HINSTANCE h, HWND owner)
 
   load_site_list (all_site_list, theMirrorString);
   load_site_list (cached_site_list, theCachedString);
-  
+
   delete[] theMirrorString;
   delete[] theCachedString;
 
+  migrate_selected_site_list();
+
   return 0;
 }
 
@@ -379,25 +421,16 @@ void
 SiteSetting::registerSavedSite (const char * site)
 {
   site_list_type tempSite(site, "", "", "", false);
-  SiteList::iterator i = find (all_site_list.begin(),
-			       all_site_list.end(), tempSite);
-  if (i == all_site_list.end())
-    {
-      /* Don't default to certain machines if they suffer
-	 from bandwidth limitations. */
-      if (strnicmp (site, NOSAVE1, NOSAVE1_LEN) == 0
-	  || strnicmp (site, NOSAVE2, NOSAVE2_LEN) == 0
-	  || strnicmp (site, NOSAVE3, NOSAVE3_LEN) == 0)
-	return;
-      SiteList result;
-      merge (all_site_list.begin(), all_site_list.end(),
-	     &tempSite, &tempSite + 1,
-	     inserter (result, result.begin()));
-      all_site_list = result;
-      site_list.push_back (tempSite);
-    }
-  else
-    site_list.push_back (*i);
+
+  /* Don't default to certain machines if they suffer from bandwidth
+     limitations. */
+  if (strnicmp (site, NOSAVE1, NOSAVE1_LEN) == 0
+      || strnicmp (site, NOSAVE2, NOSAVE2_LEN) == 0
+      || strnicmp (site, NOSAVE3, NOSAVE3_LEN) == 0)
+    return;
+
+  site_list_insert (all_site_list, tempSite);
+  site_list.push_back (tempSite);
 }
 
 void
@@ -424,8 +457,7 @@ do_download_site_info_thread (void *p)
   {
     hinst = (HINSTANCE) (context[0]);
     h = (HWND) (context[1]);
-    static bool downloaded = false;
-    if (!downloaded && get_site_list (hinst, h))
+    if (get_site_list (hinst, h))
     {
       // Error: Couldn't download the site info.
       // Go back to the Net setup page.
@@ -436,9 +468,8 @@ do_download_site_info_thread (void *p)
       // Tell the progress page that we're done downloading
       Progress.PostMessageNow (WM_APP_SITE_INFO_DOWNLOAD_COMPLETE, 0, IDD_NET);
     }
-    else 
+    else
     {
-      downloaded = true;
       // Everything worked, go to the site select page
       // Tell the progress page that we're done downloading
       Progress.PostMessageNow (WM_APP_SITE_INFO_DOWNLOAD_COMPLETE, 0, IDD_SITE);



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-08-22 14:54 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-22 14:54 [setup - the official Cygwin setup program] branch master, updated. release_2.905-3-gb4947fb6 Jon TURNEY

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).