[PATCH setup] Add perpetual support for preremove scripts

Christian Franke Christian.Franke@t-online.de
Wed Jun 29 18:35:29 GMT 2022


Christian Franke wrote:
> Jon Turney wrote:
>> On 26/06/2022 17:33, Christian Franke wrote:
>>> ...
>>> This patch adds the missing functionality to run the pre-install 
>>> hook. It is limited to /etc/preremove/0p_* because there is possibly 
>>> no use case for /etc/preremove/zp_*.
>>
>> Thanks.
>>
>> I'm not sure what you mean by 'there is possibly no use case': That 
>> you don't have one currently, or that you've reasoned that there 
>> can't be one?
>>
>
> I don't have one currently and found none which is useful in practice, 
> but cannot prove that there is none. If desired, I could provide a 
> patch which adds 'zp_*' support.
>

Meantime I realized that this is one of these cases where discussion may 
take longer than implementation. Attached is a patch ...


>> ...
>>
>> I applied this patch.
>>
>
> Thanks. I found a minor GUI issue during testing: Script filename 
> display persists during package remove phase. Fixed with attached patch.

... which should be applied on top of this last patch.

-------------- next part --------------
From 7e3350f633f18e5639a109e0d779473e949ebe57 Mon Sep 17 00:00:00 2001
From: Christian Franke <christian.franke@t-online.de>
Date: Wed, 29 Jun 2022 19:57:26 +0200
Subject: [PATCH] Also run stratum 'z' perpetual preremove scripts

---
 install.cc | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/install.cc b/install.cc
index 0ceb05f..1fdc699 100644
--- a/install.cc
+++ b/install.cc
@@ -76,26 +76,28 @@ struct std_dirs_t {
   mode_t mode;
 };
 
-class Perpetual0RemoveFindVisitor : public FindVisitor
+class PerpetualRemoveFindVisitor : public FindVisitor
 {
 public:
-  explicit Perpetual0RemoveFindVisitor (std::vector<Script> *scripts)
-    : _scripts(scripts)
+  PerpetualRemoveFindVisitor (std::vector<Script> *scripts, const std::string& stratum)
+    : _scripts(scripts),
+      stratum(stratum)
   {}
   virtual void visitFile(const std::string& basePath,
                          const WIN32_FIND_DATA *theFile)
     {
       std::string fn = std::string("/etc/preremove/") + theFile->cFileName;
       Script script(fn);
-      if (script.is_p("0"))
+      if (script.is_p(stratum))
 	  _scripts->push_back(Script (fn));
     }
-  virtual ~ Perpetual0RemoveFindVisitor () {}
+  virtual ~ PerpetualRemoveFindVisitor () {}
 protected:
-  Perpetual0RemoveFindVisitor (Perpetual0RemoveFindVisitor const &);
-  Perpetual0RemoveFindVisitor & operator= (Perpetual0RemoveFindVisitor const &);
+  PerpetualRemoveFindVisitor (PerpetualRemoveFindVisitor const &);
+  PerpetualRemoveFindVisitor & operator= (PerpetualRemoveFindVisitor const &);
 private:
   std::vector<Script> *_scripts;
+  const std::string stratum;
 };
 
 class Installer
@@ -105,7 +107,7 @@ class Installer
     Installer();
     void initDialog();
     void progress (int bytes);
-    void preremovePerpetual0 ();
+    void preremovePerpetual (const std::string& stratum);
     void preremoveOne (packagemeta &);
     void uninstallOne (packagemeta &);
     void replaceOnRebootFailed (const std::string& fn);
@@ -177,16 +179,16 @@ Installer::StandardDirs[] = {
 static int num_installs, num_uninstalls;
 
 void
-Installer::preremovePerpetual0 ()
+Installer::preremovePerpetual (const std::string& stratum)
 {
   std::vector<Script> perpetual;
-  Perpetual0RemoveFindVisitor visitor (&perpetual);
+  PerpetualRemoveFindVisitor visitor (&perpetual, stratum);
   Find (cygpath ("/etc/preremove")).accept (visitor);
   if (perpetual.empty())
     return;
 
   Progress.SetText1 (IDS_PROGRESS_PREREMOVE);
-  Progress.SetText2 ("0/Perpetual");
+  Progress.SetText2 ((stratum + "/Perpetual").c_str ());
   std::sort (perpetual.begin(), perpetual.end());
   for (std::vector<Script>::iterator i = perpetual.begin (); i != perpetual.end (); ++i) {
     Progress.SetText3 (i->fullName ().c_str());
@@ -905,7 +907,7 @@ do_install_thread (HINSTANCE h, HWND owner)
 
   /* start with uninstalls - remove files that new packages may replace */
   Progress.SetBar2(0);
-  myInstaller.preremovePerpetual0 ();
+  myInstaller.preremovePerpetual ("0");
 
   Progress.SetBar2(0);
   for (std::vector <packageversion>::iterator i = uninstall_q.begin ();
@@ -917,6 +919,9 @@ do_install_thread (HINSTANCE h, HWND owner)
     Progress.SetBar2(std::distance(uninstall_q.begin(), i) + 1, uninstall_q.size());
   }
 
+  Progress.SetBar2(0);
+  myInstaller.preremovePerpetual ("z");
+
   Progress.SetBar2(0);
   for (std::vector <packageversion>::iterator i = uninstall_q.begin ();
        i != uninstall_q.end (); ++i)
-- 
2.36.1



More information about the Cygwin-apps mailing list