-
- # if any files were added or removed, check to see if each page
- # needs an update due to linking to them
- # TODO: inefficient; pages may get rendered above and again here;
- # problem is the bestlink may have changed and we won't know until
- # now
- if (@add || @del) {
-FILE: foreach my $file (@files) {
- my $page=pagename($file);
- foreach my $f (@add, @del) {
- my $p=pagename($f);
- foreach my $link (@{$links{$page}}) {
- if (bestlink($page, $link) eq $p) {
- debug("rendering $file, which links to $p");
- render($file);
- $rendered{$file}=1;
- next FILE;
- }
- }
- }
- }
- }
-
- # handle linkbacks; if a page has added/removed links, update the
- # pages it links to
- # TODO: inefficient; pages may get rendered above and again here;
- # problem is the linkbacks could be wrong in the first pass render
- # above
- if (%rendered) {
- my %linkchanged;
- foreach my $file (keys %rendered, @del) {
- my $page=pagename($file);
- if (exists $links{$page}) {
- foreach my $link (@{$links{$page}}) {
- $link=bestlink($page, $link);
- if (length $link &&
- ! exists $oldlinks{$page} ||
- ! grep { $_ eq $link } @{$oldlinks{$page}}) {
- $linkchanged{$link}=1;
- }
- }
- }
- if (exists $oldlinks{$page}) {
- foreach my $link (@{$oldlinks{$page}}) {
- $link=bestlink($page, $link);
- if (length $link &&
- ! exists $links{$page} ||
- ! grep { $_ eq $link } @{$links{$page}}) {
- $linkchanged{$link}=1;
- }
- }
- }
- }
- foreach my $link (keys %linkchanged) {
- my $linkfile=$pagesources{$link};
- if (defined $linkfile) {
- debug("rendering $linkfile, to update its linkbacks");
- render($linkfile);
- }
- }
- }
-}
-
-# Generates a C wrapper program for running ikiwiki in a specific way.
-# The wrapper may be safely made suid.
-sub gen_wrapper ($$) {
- my ($svn, $rebuild)=@_;
-
- eval {use Cwd 'abs_path'};
- $srcdir=abs_path($srcdir);
- $destdir=abs_path($destdir);
- my $this=abs_path($0);
- if (! -x $this) {
- error("$this doesn't seem to be executable");
- }
-
- my $call=qq{"$this", "$this", "$srcdir", "$destdir", "--wikiname=$wikiname"};
- $call.=', "--verbose"' if $verbose;
- $call.=', "--rebuild"' if $rebuild;
- $call.=', "--nosvn"' if !$svn;
- $call.=', "--cgi"' if $cgi;
- $call.=', "--url='.$url.'"' if $url;
-
- my @envsave;
- push @envsave, qw{REMOTE_ADDR QUERY_STRING REQUEST_METHOD REQUEST_URI
- CONTENT_TYPE CONTENT_LENGTH GATEWAY_INTERFACE} if $cgi;
- my $envsave="";
- foreach my $var (@envsave) {
- $envsave.=<<"EOF"
- if ((s=getenv("$var")))
- asprintf(&newenviron[i++], "%s=%s", "$var", s);
-EOF
- }
-
- open(OUT, ">ikiwiki-wrap.c") || error("failed to write ikiwiki-wrap.c: $!");;
- print OUT <<"EOF";
-/* A wrapper for ikiwiki, can be safely made suid. */
-#define _GNU_SOURCE
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-
-extern char **environ;
-
-int main (void) {
- /* Sanitize environment. */
- char *s;
- char *newenviron[$#envsave+3];
- int i=0;
- $envsave;
- newenviron[i++]="HOME=$ENV{HOME}";
- newenviron[i]=NULL;
- environ=newenviron;
-
- execl($call, NULL);
- perror("failed to run $this");
- exit(1);
-}
-EOF
- close OUT;
- if (system("gcc", "ikiwiki-wrap.c", "-o", "ikiwiki-wrap") != 0) {
- error("failed to compile ikiwiki-wrap.c");
- }
- unlink("ikiwiki-wrap.c");
- print "successfully generated ikiwiki-wrap\n";
- exit 0;
-}