From 27294932cd251d7c39a72f3fac172a1d61ab586a Mon Sep 17 00:00:00 2001 From: Christian Schneider Date: Sun, 2 Mar 2008 17:11:45 +0000 Subject: Do not convert files above 200k, link to unchanged files --- it_auto_prepend.php | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'it_auto_prepend.php') diff --git a/it_auto_prepend.php b/it_auto_prepend.php index c71e38c..0867357 100644 --- a/it_auto_prepend.php +++ b/it_auto_prepend.php @@ -133,19 +133,34 @@ function it_convert($source) else if (@is_readable($source)) { $converted = $GLOBALS['IT_SYNTAXCONVERTER_DIR'] . "/it_syntaxconverter/$sourcerelpath"; + $stat = @lstat($converted); + $mtimeconverted = $stat[9]; - if (@filemtime($converted) < filemtime($source)) + if ($mtimeconverted < filemtime($source)) { - $converter = new it_syntaxconverter(file_get_contents($source)); - $parts = explode("/", dirname($converted)); - - for ($i = 1; $i <= count($parts); $i++) - @mkdir(join("/", array_slice($parts, 0, $i)), 0700); + if ($changed = filesize($source) < 200000) # Do not attempt to convert anything above 200k to avoid large memory consumption + { + $converter = new it_syntaxconverter(file_get_contents($source)); + $parts = explode("/", dirname($converted)); + + for ($i = 1; $i <= count($parts); $i++) + @mkdir(join("/", array_slice($parts, 0, $i)), 0700); + + if ($changed = $converter->changes) + { + @unlink($converted); + if ($output = fopen($converted, "w")) + { + fputs($output, $converter->output); + fclose($output); + } + } + } - if ($output = fopen($converted, "w")) + if (!$changed) # Link to original file if no changes made { - fputs($output, $converter->output); - fclose($output); + @unlink($converted); + symlink(realpath($source), $converted); } clearstatcache(); -- cgit v1.2.3