[Pmwiki-users] autodetect diff and patch

jdkim at socrates.Berkeley.EDU jdkim at socrates.Berkeley.EDU
Thu Jul 3 17:00:31 CDT 2003


Yeah, I agree on the expensive cost of running which every time.  A better
option would be for it to run once during the original installation step
when it's creating the directories and save the variable somewhere
permanent.  That's actually why I sent out the non-autodetecting one first
time around so one can make a choice.

I'm actually at work right now, and don't have a whole lot of time to
spend implementing what I just mentioned, but I did want my Restore
function to work, which is why I only sent out quick hacks.  (Also I know
very little php.)  I personally am using the non-detecting one at the
moment.

John

On Thu, 3 Jul 2003, Patrick R. Michaud wrote:
> Actually, I recommend against automatically running the `which diff`/
> `which patch` command to determine the location of the diff(1)
> program--that's a bit of an expensive command to be running on every
> execution of PmWiki (i.e., every time that a PmWiki page is accessed).
> Plus a lot of system administrators will be wary of executing programs
> where a full path isn't specified--lots of room for some trojan horsing
> to take place there.
>
> I will release a version of PmWiki with the locations of diff(1) and
> patch(1) as configuration variables (but not automatically located); I'll
> also set up an option that makes it easy to have PmWiki search for the
> locations of diff/patch if they aren't available.
>
> Many thanks for the excellent suggestion.
>
> Pm
>
>
> On Thu, Jul 03, 2003 at 02:04:27PM -0700, jdkim at socrates.Berkeley.EDU wrote:
> > Okay, with the following patch, pmwiki will try to detect the location of
> > diff and patch.  But if it fails, you can still set the variable in
> > local.php.  For some reason, when I run "which patch" from within a php
> > code, it returns /usr/bin/patch, even though the same command returns
> > /usr/local/bin/patch when run in shell.
> >
> >
> > *** pmwiki-old.php	Thu Jul  3 12:55:04 2003
> > --- pmwiki.php	Thu Jul  3 13:45:52 2003
> > ***************
> > *** 33,38 ****
> > --- 33,40 ----
> >   $ScriptUrl = 'http://'.$HTTP_SERVER_VARS['HTTP_HOST'];
> >   $ScriptUrl .= $HTTP_SERVER_VARS['SCRIPT_NAME'];
> >   $ScriptDir = preg_replace("#/[^/]*\$#","",$ScriptUrl,1);
> > + $SysDiff = trim(`which diff`);
> > + $SysPatch = trim(`which patch`);
> >   $WikiImgUrl = "$ScriptDir/pmwiki-50.gif";
> >   $DiffKeepDays = 3650;
> >   $WikiDir = "wiki.d";
> > ***************
> > *** 425,431 ****
> >   }
> >
> >   function Diff($oldtext,$newtext) {
> > !   global $WikiDir;
> >     $tempold = tempnam($WikiDir,"old");
> >     if ($oldfp = fopen($tempold,"w")) {
> >       fputs($oldfp,$oldtext);
> > --- 427,433 ----
> >   }
> >
> >   function Diff($oldtext,$newtext) {
> > !   global $WikiDir, $SysDiff;
> >     $tempold = tempnam($WikiDir,"old");
> >     if ($oldfp = fopen($tempold,"w")) {
> >       fputs($oldfp,$oldtext);
> > ***************
> > *** 436,448 ****
> >       fputs($newfp,$newtext);
> >       fclose($newfp);
> >     }
> > !   @$diff = `/usr/bin/diff $tempold $tempnew`;
> >     @unlink($tempold); @unlink($tempnew);
> >     return $diff;
> >   }
> >
> >   function Patch($page,$restore) {
> > !   global $WikiDir;
> >     Lock(2);
> >     $txtfile = tempnam($WikiDir,"txt");
> >     $patfile = tempnam($WikiDir,"pat");
> > --- 438,450 ----
> >       fputs($newfp,$newtext);
> >       fclose($newfp);
> >     }
> > !   @$diff = `$SysDiff $tempold $tempnew`;
> >     @unlink($tempold); @unlink($tempnew);
> >     return $diff;
> >   }
> >
> >   function Patch($page,$restore) {
> > !   global $WikiDir, $SysPatch;
> >     Lock(2);
> >     $txtfile = tempnam($WikiDir,"txt");
> >     $patfile = tempnam($WikiDir,"pat");
> > ***************
> > *** 458,464 ****
> >         fputs($patfp,$v);
> >         fclose($patfp);
> >       }
> > !     $diff = `/usr/bin/patch $txtfile $patfile 2>/dev/null`;
> >     }
> >     $text = implode('',file($txtfile));
> >     @unlink($txtfile); @unlink($patfile);
> > --- 460,466 ----
> >         fputs($patfp,$v);
> >         fclose($patfp);
> >       }
> > !     $diff = `$SysPatch $txtfile $patfile 2>/dev/null`;
> >     }
> >     $text = implode('',file($txtfile));
> >     @unlink($txtfile); @unlink($patfile);
> > ___
> >
> > John Kim
> >
> >
> >
> > _______________________________________________
> > Pmwiki-users mailing list
> > Pmwiki-users at pmichaud.com
> > http://pmichaud.com/mailman/listinfo/pmwiki-users_pmichaud.com
> >
>





More information about the pmwiki-users mailing list