]> cygwin.com Git - cygwin-apps/setup.git/commitdiff
Add support for 'redir' flag in mirrors.lst
authorJon Turney <jon.turney@dronecode.org.uk>
Thu, 6 Jun 2024 15:56:56 +0000 (16:56 +0100)
committerJon Turney <jon.turney@dronecode.org.uk>
Sun, 23 Jun 2024 17:04:54 +0000 (18:04 +0100)
site.cc
site.h

diff --git a/site.cc b/site.cc
index 569235a97f7d1024e953193f64f95dfa50b65460..b76a0bec2967edddef7a1895ff1b78a19b3f2b00 100644 (file)
--- a/site.cc
+++ b/site.cc
@@ -142,7 +142,8 @@ site_list_type::site_list_type (const std::string &_url,
                                const std::string &_area,
                                const std::string &_location,
                                bool _from_mirrors_lst,
-                                bool _noshow = false)
+                                bool _noshow = false,
+                                const std::string &_redir = "")
 {
   url = _url;
   servername = _servername;
@@ -150,6 +151,7 @@ site_list_type::site_list_type (const std::string &_url,
   location = _location;
   from_mirrors_lst = _from_mirrors_lst;
   noshow = _noshow;
+  redir = _redir;
 
   /* Canonicalize URL to ensure it ends with a '/' */
   if (url.at(url.length()-1) != '/')
@@ -286,9 +288,25 @@ load_site_list (SiteList& theSites, char *theString)
           if (!semi[0] || !semi[1] || !semi[2])
             continue;
 
-          bool noshow = semi[3] && (strncmp(semi[3], "noshow", 6) == 0);
+          /* fourth part is an optional, comma-delimited set of flags */
+          bool noshow = FALSE;
+          const char *redir = "";
 
-          site_list_type newsite (bol, semi[0], semi[1], semi[2], true, noshow);
+          char *flag = semi[3];
+          while (flag)
+            {
+              if (strncmp(flag, "noshow", 6) == 0)
+                noshow = TRUE;
+              else if (strncmp(flag, "redir=", 6) == 0)
+                redir = flag+6;
+
+              flag = strchr (flag, ',');
+              if (flag)
+                *flag++ = 0;
+            }
+
+          /* add site to list */
+          site_list_type newsite (bol, semi[0], semi[1], semi[2], true, noshow, redir);
           site_list_insert (theSites, newsite);
         }
         else
@@ -324,6 +342,23 @@ migrate_selected_site_list()
               *i = migrate;
             }
         }
+
+      /* If the saved selected site URL appears in the site list with a redir
+         flag, replace with the redirected URL */
+      {
+        SiteList::iterator j = find (all_site_list.begin(),
+                                     all_site_list.end(), *i);
+
+        if (j != all_site_list.end())
+          {
+            if (!j->redir.empty())
+              {
+                site_list_type migrate(j->redir, "", "", "", false);
+                Log (LOG_PLAIN) << "Migrated " << i->url << " to " << j->redir  << endLog;
+                *i = migrate;
+              }
+          }
+      }
     }
 }
 
diff --git a/site.h b/site.h
index 6ec7cf396b2ba292cfd7e662541424489019b9cf..387de29d66a48ba10da9ac69ed020235eace4e90 100644 (file)
--- a/site.h
+++ b/site.h
@@ -50,7 +50,8 @@ class site_list_type
 public:
   site_list_type () : url (), displayed_url (), key () {};
   site_list_type (const std::string& , const std::string& ,
-                  const std::string& , const std::string&, bool, bool);
+                  const std::string& , const std::string&, bool, bool,
+                  const std::string &);
   ~site_list_type () {};
   std::string url;
   // provided by mirrors.lst but not used
@@ -61,6 +62,9 @@ public:
   bool from_mirrors_lst;
   // marked as "noshow"
   bool noshow;
+  // url to redirect to
+  std::string redir;
+
   std::string displayed_url;
   // sort key
   std::string key;
This page took 0.040223 seconds and 5 git commands to generate.