public inbox for cygwin-apps@cygwin.com
 help / color / mirror / Atom feed
From: Christian Franke <Christian.Franke@t-online.de>
To: cygwin-apps@cygwin.com
Subject: [PATCH setup] Add perpetual support for preremove scripts
Date: Sun, 26 Jun 2022 18:33:10 +0200	[thread overview]
Message-ID: <a6802738-4a58-4274-2394-2acff087fb07@t-online.de> (raw)

[-- Attachment #1: Type: text/plain, Size: 792 bytes --]

Use case: I ITP etckeeper (https://etckeeper.branchable.com/) which I 
frequently use on Debian. For fully automatic operation, it requires 
pre-install and post-install hooks, e.g:

/etc/preremove/0p_000_etckeeper_pre-install.sh
/etc/postinstall/zp_zzz_etckeeper_post-install.sh

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_*.

'class Perpetual0RemoveFindVisitor' is borrowed from postinstall.cc and 
modified. It still uses the ugly pre-C++11 hack to disable copy-ctor and 
operator=. Possible refactoring like merging all 3 mostly similar 
visitors into one (or if C++11 is now allowed, use lambda functions 
instead) are left for later.

-- 
Regards,
Christian


[-- Attachment #2: 0001-Add-perpetual-support-for-preremove-scripts.patch --]
[-- Type: text/plain, Size: 2945 bytes --]

From cae15278d705807da53b0abdeff5ab6b15fb479c Mon Sep 17 00:00:00 2001
From: Christian Franke <christian.franke@t-online.de>
Date: Sun, 26 Jun 2022 18:01:03 +0200
Subject: [PATCH] Add perpetual support for preremove scripts

Always run all /etc/preremove/0p_* first.
---
 install.cc | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/install.cc b/install.cc
index e58ef4b..6689a08 100644
--- a/install.cc
+++ b/install.cc
@@ -33,6 +33,7 @@
 #include <sys/stat.h>
 #include <errno.h>
 #include <process.h>
+#include <algorithm>
 
 #include "ini.h"
 #include "resource.h"
@@ -50,6 +51,8 @@
 #include "archive.h"
 #include "archive_tar.h"
 #include "script.h"
+#include "find.h"
+#include "FindVisitor.h"
 
 #include "package_db.h"
 #include "package_meta.h"
@@ -73,6 +76,28 @@ struct std_dirs_t {
   mode_t mode;
 };
 
+class Perpetual0RemoveFindVisitor : public FindVisitor
+{
+public:
+  explicit Perpetual0RemoveFindVisitor (std::vector<Script> *scripts)
+    : _scripts(scripts)
+  {}
+  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"))
+	  _scripts->push_back(Script (fn));
+    }
+  virtual ~ Perpetual0RemoveFindVisitor () {}
+protected:
+  Perpetual0RemoveFindVisitor (Perpetual0RemoveFindVisitor const &);
+  Perpetual0RemoveFindVisitor & operator= (Perpetual0RemoveFindVisitor const &);
+private:
+  std::vector<Script> *_scripts;
+};
+
 class Installer
 {
   public:
@@ -80,6 +105,7 @@ class Installer
     Installer();
     void initDialog();
     void progress (int bytes);
+    void preremovePerpetual0 ();
     void preremoveOne (packagemeta &);
     void uninstallOne (packagemeta &);
     void replaceOnRebootFailed (const std::string& fn);
@@ -150,6 +176,24 @@ Installer::StandardDirs[] = {
 
 static int num_installs, num_uninstalls;
 
+void
+Installer::preremovePerpetual0 ()
+{
+  std::vector<Script> perpetual;
+  Perpetual0RemoveFindVisitor visitor (&perpetual);
+  Find (cygpath ("/etc/preremove")).accept (visitor);
+  if (perpetual.empty())
+    return;
+
+  Progress.SetText1 (IDS_PROGRESS_PREREMOVE);
+  Progress.SetText2 ("0/Perpetual");
+  std::sort (perpetual.begin(), perpetual.end());
+  for (std::vector<Script>::iterator i = perpetual.begin (); i != perpetual.end (); ++i) {
+    Progress.SetText3 (i->fullName ().c_str());
+    i->run();
+  }
+}
+
 void
 Installer::preremoveOne (packagemeta & pkg)
 {
@@ -859,6 +903,9 @@ do_install_thread (HINSTANCE h, HWND owner)
   }
 
   /* start with uninstalls - remove files that new packages may replace */
+  Progress.SetBar2(0);
+  myInstaller.preremovePerpetual0 ();
+
   Progress.SetBar2(0);
   for (std::vector <packageversion>::iterator i = uninstall_q.begin ();
        i != uninstall_q.end (); ++i)
-- 
2.36.1


             reply	other threads:[~2022-06-26 16:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-26 16:33 Christian Franke [this message]
2022-06-29 13:13 ` Jon Turney
2022-06-29 15:09   ` Christian Franke
2022-06-29 18:35     ` Christian Franke
2022-07-02 12:35       ` Jon Turney
2022-07-01 17:03     ` Christian Franke

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a6802738-4a58-4274-2394-2acff087fb07@t-online.de \
    --to=christian.franke@t-online.de \
    --cc=cygwin-apps@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).