diff options
Diffstat (limited to 'it_auto_prepend.php')
-rw-r--r-- | it_auto_prepend.php | 33 |
1 files changed, 24 insertions, 9 deletions
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(); |