[PATCH] Run postinstall scripts in a thread with progress bars - take 2
Igor Pechtchanski
pechtcha@cs.nyu.edu
Thu Mar 20 21:49:00 GMT 2003
On 21 Mar 2003, Robert Collins wrote:
> On Fri, 2003-03-21 at 04:49, Igor Pechtchanski wrote:
>
> > Same as above, but regenerated against HEAD. ChangeLog is the same.
> > The only thing about this patch that really makes me uncomfortable is
> > having to run through iterators/FindVisitors twice. Any suggestions for
> > improvement are welcome.
>
> Sight unseen - instead of counting in the visitor and iterators, push
> all the script details (and package references if appropriate) onto a
> list or vector first time through.
>
> Then, simply walk the list.
> Rob
Fair enough. "Now, why didn't I think of that?"^TM
A new iteration is attached.
Igor
==============================================================================
ChangeLog:
2003-03-20 Igor Pechtchanski <pechtcha@cs.nyu.edu>
* threebar.h (WM_APP_START_POSTINSTALL): New message.
(WM_APP_POSTINSTALL_THREAD_COMPLETE): New message.
* threebar.cc (ThreeBarProgressPage::OnMessageApp):
Add handling for WM_APP_START_POSTINSTALL and
WM_APP_POSTINSTALL_THREAD_COMPLETE.
* install.cc (do_install_thread): Set next_dialog to
IDD_S_POSTINSTALL.
* desktop.cc (DesktopSetupPage::OnFinish): Move the
do_postinstall call to ThreeBarProgressPage::OnMessageApp.
* postinstall.cc (Progress): New extern variable.
(RunFindVisitor::visitFile): Add script to vector
instead of running.
(RunFindVisitor::_scripts): New member variable.
(do_postinstall_thread): Rename do_postinstall to. Add
Progress bar and text setting. Add package count.
(do_postinstall_reflector): New static function.
(do_postinstall): Rename to do_postinstall_thread.
Create a thread instead.
--
http://cs.nyu.edu/~pechtcha/
|\ _,,,---,,_ pechtcha@cs.nyu.edu
ZZZzz /,`.-'`' -. ;-;;,_ igor@watson.ibm.com
|,4- ) )-,_. ,\ ( `'-' Igor Pechtchanski
'---''(_/--' `-'\_) fL a.k.a JaguaR-R-R-r-r-r-.-.-. Meow!
Oh, boy, virtual memory! Now I'm gonna make myself a really *big* RAMdisk!
-- /usr/games/fortune
-------------- next part --------------
Index: desktop.cc
===================================================================
RCS file: /cvs/cygwin-apps/setup/desktop.cc,v
retrieving revision 2.34
diff -u -p -r2.34 desktop.cc
--- desktop.cc 25 Nov 2002 22:12:08 -0000 2.34
+++ desktop.cc 20 Mar 2003 21:41:09 -0000
@@ -397,8 +397,6 @@ DesktopSetupPage::OnFinish ()
HWND h = GetHWND ();
save_dialog (h);
do_desktop_setup ();
- NEXT (IDD_S_POSTINSTALL);
- do_postinstall (GetInstance (), h);
return true;
}
Index: install.cc
===================================================================
RCS file: /cvs/cygwin-apps/setup/install.cc,v
retrieving revision 2.60
diff -u -p -r2.60 install.cc
--- install.cc 17 Mar 2003 22:23:33 -0000 2.60
+++ install.cc 20 Mar 2003 21:41:09 -0000
@@ -455,7 +455,7 @@ do_install_thread (HINSTANCE h, HWND own
num_installs = 0, num_uninstalls = 0, num_replacements = 0;
rebootneeded = false;
- next_dialog = IDD_DESKTOP;
+ next_dialog = IDD_S_POSTINSTALL;
io_stream::mkpath_p (PATH_TO_DIR, String ("file://") + get_root_dir ());
Index: postinstall.cc
===================================================================
RCS file: /cvs/cygwin-apps/setup/postinstall.cc,v
retrieving revision 2.12
diff -u -p -r2.12 postinstall.cc
--- postinstall.cc 20 Mar 2003 10:02:51 -0000 2.12
+++ postinstall.cc 20 Mar 2003 21:41:09 -0000
@@ -29,40 +29,117 @@ static const char *cvsid =
#include "FilterVisitor.h"
#include "package_db.h"
#include "package_meta.h"
+#include "resource.h"
+#include "threebar.h"
+
+extern ThreeBarProgressPage Progress;
class RunFindVisitor : public FindVisitor
{
public:
- RunFindVisitor (){}
+ RunFindVisitor (std::vector<String> *scripts) : _scripts(scripts) {}
virtual void visitFile(String const &basePath, const WIN32_FIND_DATA *theFile)
{
- run_script ("/etc/postinstall/", theFile->cFileName, TRUE);
+ _scripts->push_back(String("/etc/postinstall/")+theFile->cFileName);
}
virtual ~ RunFindVisitor () {}
protected:
RunFindVisitor (RunFindVisitor const &);
RunFindVisitor & operator= (RunFindVisitor const &);
+private:
+ std::vector<String> *_scripts;
};
-
-void
-do_postinstall (HINSTANCE h, HWND owner)
+
+static void
+do_postinstall_thread (HINSTANCE h, HWND owner)
{
- next_dialog = 0;
+ next_dialog = IDD_DESKTOP;
+
+ Progress.SetText1 ("Running...");
+ Progress.SetText2 ("");
+ Progress.SetText3 ("");
+ Progress.SetBar1 (0, 1);
+ Progress.SetBar2 (0, 1);
+
init_run_script ();
SetCurrentDirectory (get_root_dir ().cstr_oneuse());
packagedb db;
+ std::vector<packagemeta*> packages;
PackageDBConnectedIterator i = db.connectedBegin ();
while (i != db.connectedEnd ())
{
packagemeta & pkg = **i;
if (pkg.installed)
- for (std::vector<Script>::iterator script=pkg.installed.scripts().begin(); script != pkg.installed.scripts().end(); ++script)
- run_script ("/etc/postinstall/", script->baseName(), TRUE);
+ packages.push_back(&pkg);
++i;
}
- RunFindVisitor myVisitor;
+ int numpkg = packages.size() + 1;
+ int k = 0;
+ std::vector<packagemeta*>::iterator j = packages.begin ();
+ while (j != packages.end ())
+ {
+ packagemeta & pkg = **j;
+ int numscr = pkg.installed.scripts().size();
+ Progress.SetText2 (pkg.name.cstr_oneuse());
+ int s = 0;
+ Progress.SetBar1 (s, numscr);
+ for (std::vector<Script>::iterator script=pkg.installed.scripts().begin(); script != pkg.installed.scripts().end(); ++script)
+ {
+ Progress.SetText3 ((String("/etc/postinstall")+script->baseName()).cstr_oneuse());
+ run_script ("/etc/postinstall/", script->baseName(), TRUE);
+ ++s;
+ Progress.SetBar1 (s, numscr);
+ }
+ Progress.SetText3 ("");
+ ++k;
+ Progress.SetBar2 (k, numpkg);
+ ++j;
+ }
+ Progress.SetText2 ("No package");
ExcludeNameFilter notDone("*.done");
- FilterVisitor excludeDoneVisitor(&myVisitor, ¬Done);
String postinst = cygpath ("/etc/postinstall");
+ std::vector<String> scripts;
+ RunFindVisitor myVisitor (&scripts);
+ FilterVisitor excludeDoneVisitor(&myVisitor, ¬Done);
+ Progress.SetBar1 (0, 1);
Find (postinst).accept (excludeDoneVisitor);
+ int numscr = scripts.size();
+ int n = 0;
+ std::vector<String>::iterator s = scripts.begin ();
+ while (s != scripts.end ())
+ {
+ Progress.SetText3 (s->cstr_oneuse());
+ run_script ("", s->cstr_oneuse(), TRUE);
+ ++n;
+ Progress.SetBar1 (n, numscr);
+ ++s;
+ }
+ Progress.SetBar2 (numpkg, numpkg);
}
+
+static DWORD WINAPI
+do_postinstall_reflector (void *p)
+{
+ HANDLE *context;
+ context = (HANDLE *) p;
+
+ do_postinstall_thread ((HINSTANCE) context[0], (HWND) context[1]);
+
+ // Tell the progress page that we're done running scripts
+ Progress.PostMessage (WM_APP_POSTINSTALL_THREAD_COMPLETE);
+
+ ExitThread(0);
+}
+
+static HANDLE context[2];
+
+void
+do_postinstall (HINSTANCE h, HWND owner)
+{
+ context[0] = h;
+ context[1] = owner;
+
+ DWORD threadID;
+ CreateThread (NULL, 0, do_postinstall_reflector, context, 0, &threadID);
+}
+
Index: threebar.cc
===================================================================
RCS file: /cvs/cygwin-apps/setup/threebar.cc,v
retrieving revision 2.4
diff -u -p -r2.4 threebar.cc
--- threebar.cc 26 Jun 2002 21:35:16 -0000 2.4
+++ threebar.cc 20 Mar 2003 21:41:09 -0000
@@ -172,6 +172,18 @@ bool
}
case WM_APP_INSTALL_THREAD_COMPLETE:
{
+ // Install is complete and we want to go on to the postinstall.
+ Window::PostMessage (WM_APP_START_POSTINSTALL);
+ break;
+ }
+ case WM_APP_START_POSTINSTALL:
+ {
+ // Start the postinstall script thread.
+ do_postinstall (GetInstance (), GetHWND ());
+ break;
+ }
+ case WM_APP_POSTINSTALL_THREAD_COMPLETE:
+ {
// Re-enable and "Push" the Next button
GetOwner ()->SetButtons (PSWIZB_NEXT);
GetOwner ()->PressButton (PSBTN_NEXT);
Index: threebar.h
===================================================================
RCS file: /cvs/cygwin-apps/setup/threebar.h,v
retrieving revision 2.4
diff -u -p -r2.4 threebar.h
--- threebar.h 21 Sep 2002 09:36:46 -0000 2.4
+++ threebar.h 20 Mar 2003 21:41:09 -0000
@@ -32,6 +32,8 @@
#define WM_APP_START_SETUP_INI_DOWNLOAD WM_APP+6
#define WM_APP_SETUP_INI_DOWNLOAD_COMPLETE WM_APP+7
// desktop.h: WM_APP_UNATTENDED_FINISH WM_APP+8
+#define WM_APP_START_POSTINSTALL WM_APP+9
+#define WM_APP_POSTINSTALL_THREAD_COMPLETE WM_APP+10
class ThreeBarProgressPage:public PropertyPage
{
More information about the Cygwin-apps
mailing list