On 14 Mar 2003, Robert Collins wrote:

> On Fri, [EMAIL PROTECTED]:07, Igor Pechtchanski wrote:
> > On 14 Mar 2003, Robert Collins wrote:
>
> > > Please Extract Method on the duplicate code here.
> > > Cheers,
> > > Rob
> >
> > Umm, shouldn't we do this as two separate steps?  There's duplicate code
> > galore all over that function...  Or do you want it all in one patch?
>
> I was only worried about the code that is being touched by the patch. I
> think it's sufficiently small that a single patch will be ok.
>
> Just describe in the patch log the two steps.
> Cheers,
> Rob

Actually, the rest of the function wasn't that bad, and I might as well do
it all at once, at least for the logging.
        Igor
==============================================================================
ChangeLog:
2003-03-13  Igor Pechtchanski <[EMAIL PROTECTED]>

        * install.cc (install_one_source): Add logging for
        successful replace-on-reboot scheduling.  Factor out
        duplicate code.  Set rebootneeded on Win9x.
        (log_ror_failure) New static function.
        (log_ror_success) New static function.

-- 
                                http://cs.nyu.edu/~pechtcha/
      |\      _,,,---,,_                [EMAIL PROTECTED]
ZZZzz /,`.-'`'    -.  ;-;;,_            [EMAIL PROTECTED]
     |,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
Index: install.cc
===================================================================
RCS file: /cvs/cygwin-apps/setup/install.cc,v
retrieving revision 2.57
diff -u -p -r2.57 install.cc
--- install.cc  12 Mar 2003 22:15:25 -0000      2.57
+++ install.cc  13 Mar 2003 23:30:52 -0000
@@ -161,6 +161,30 @@ replace_one (packagemeta & pkg)
   return errors;
 }
 
+/* log failed scheduling of replace-on-reboot of a given file. */
+/* also increment errors. */
+static int
+log_ror_failure (String const &fn, int &errors)
+{
+  log (LOG_TIMESTAMP,
+       "Unable to schedule reboot replacement of file %s with %s (Win32 Error %ld)",
+       cygpath (String ("/") + fn).cstr_oneuse(),
+       cygpath (String ("/") + fn + ".new").cstr_oneuse(),
+       GetLastError ());
+  ++errors;
+}
+
+/* log successful scheduling of replace-on-reboot of a given file. */
+/* also set rebootneeded. */
+static int
+log_ror_success (String const &fn, bool &rebootneeded)
+{
+  log (LOG_TIMESTAMP,
+       "Scheduled reboot replacement of file %s with %s",
+       cygpath (String ("/") + fn).cstr_oneuse(),
+       cygpath (String ("/") + fn + ".new").cstr_oneuse());
+  rebootneeded = true;
+}
 
 /* install one source at a given prefix. */
 static int
@@ -252,13 +276,7 @@ install_one_source (packagemeta & pkgm, 
                                          source, MAX_PATH);
                      if (!len || len > MAX_PATH)
                        {
-                         log (LOG_TIMESTAMP,
-                              "Unable to schedule reboot replacement of file %s with 
%s (Win32 Error %ld)",
-                              cygpath (String ("/") + fn).cstr_oneuse(),
-                              cygpath (String ("/") + fn +
-                                               ".new").cstr_oneuse(),
-                              GetLastError ());
-                         ++errors;
+                         log_ror_failure (fn, errors);
                        }
                      else
                        {
@@ -269,29 +287,19 @@ install_one_source (packagemeta & pkgm, 
                                              dest, MAX_PATH);
                          if (!len || len > MAX_PATH)
                            {
-                             log (LOG_TIMESTAMP,
-                                  "Unable to schedule reboot replacement of file %s 
with %s (Win32 Error %ld)",
-                                  cygpath (String ("/") + fn).cstr_oneuse(),
-                                  cygpath (String ("/") + fn +
-                                           ".new").cstr_oneuse(),
-                                  GetLastError ());
-                             ++errors;
-
+                             log_ror_failure (fn, errors);
                            }
                          else
                            /* trigger a replacement on reboot */
                          if (!WritePrivateProfileString
                                ("rename", dest, source, "WININIT.INI"))
                            {
-                             log (LOG_TIMESTAMP,
-                                  "Unable to schedule reboot replacement of file %s 
with %s (Win32 Error %ld)",
-                                  cygpath (String ("/") + fn).cstr_oneuse(),
-                                  cygpath (String ("/") + fn +
-                                           ".new").cstr_oneuse(),
-                                  GetLastError ());
-                             ++errors;
+                             log_ror_failure (fn, errors);
+                           }
+                         else
+                           {
+                             log_ror_success (fn, rebootneeded);
                            }
-
                        }
                    }
                      break;
@@ -307,15 +315,12 @@ install_one_source (packagemeta & pkgm, 
                                       MOVEFILE_DELAY_UNTIL_REBOOT |
                                       MOVEFILE_REPLACE_EXISTING))
                        {
-                         log (LOG_TIMESTAMP,
-                              "Unable to schedule reboot replacement of file %s with 
%s (Win32 Error %ld)",
-                              cygpath (String ("/") + fn).cstr_oneuse(),
-                              cygpath (String ("/") + fn + ".new").cstr_oneuse(),
-                              GetLastError ());
-                         ++errors;
+                         log_ror_failure (fn, errors);
                        }
                      else
-                       rebootneeded = true;
+                       {
+                         log_ror_success (fn, rebootneeded);
+                       }
                      break;
                    }
                }

Reply via email to