summaryrefslogtreecommitdiff
path: root/IkiWiki.pm
diff options
context:
space:
mode:
authorJoey Hess <joey@kodama.kitenet.net>2008-03-29 21:02:47 -0400
committerJoey Hess <joey@kodama.kitenet.net>2008-03-29 21:02:47 -0400
commitf6bd81db15340bd1bfa69e98f377099036308b7b (patch)
treeb152102d7c4f29f426e8cf02d0cc949787ca3e3b /IkiWiki.pm
parentb95a86c069ccbcd89104f72081cfc25f986465e3 (diff)
Added a hardlink option in the setup file, useful if the source and dest are on the same filesystem and the wiki includes large media files, which would normally be copied, wasting time and space.
Diffstat (limited to 'IkiWiki.pm')
-rw-r--r--IkiWiki.pm33
1 files changed, 22 insertions, 11 deletions
diff --git a/IkiWiki.pm b/IkiWiki.pm
index 684713821..d1b65cd51 100644
--- a/IkiWiki.pm
+++ b/IkiWiki.pm
@@ -87,6 +87,7 @@ sub defaultconfig () { #{{{
numbacklinks => 10,
account_creation_password => "",
prefix_directives => 0,
+ hardlink => 0,
} #}}}
sub checkconfig () { #{{{
@@ -323,12 +324,9 @@ sub readfile ($;$$) { #{{{
return $ret;
} #}}}
-sub writefile ($$$;$$) { #{{{
- my $file=shift; # can include subdirs
- my $destdir=shift; # directory to put file in
- my $content=shift;
- my $binary=shift;
- my $writer=shift;
+sub prep_writefile ($$) {
+ my $file=shift;
+ my $destdir=shift;
my $test=$file;
while (length $test) {
@@ -337,12 +335,8 @@ sub writefile ($$$;$$) { #{{{
}
$test=dirname($test);
}
- my $newfile="$destdir/$file.ikiwiki-new";
- if (-l $newfile) {
- error("cannot write to a symlink ($newfile)");
- }
- my $dir=dirname($newfile);
+ my $dir=dirname("$destdir/$file");
if (! -d $dir) {
my $d="";
foreach my $s (split(m!/+!, $dir)) {
@@ -353,6 +347,23 @@ sub writefile ($$$;$$) { #{{{
}
}
+ return 1;
+}
+
+sub writefile ($$$;$$) { #{{{
+ my $file=shift; # can include subdirs
+ my $destdir=shift; # directory to put file in
+ my $content=shift;
+ my $binary=shift;
+ my $writer=shift;
+
+ prep_writefile($file, $destdir);
+
+ my $newfile="$destdir/$file.ikiwiki-new";
+ if (-l $newfile) {
+ error("cannot write to a symlink ($newfile)");
+ }
+
my $cleanup = sub { unlink($newfile) };
open (my $out, '>', $newfile) || error("failed to write $newfile: $!", $cleanup);
binmode($out) if ($binary);