diff options
author | Christian Schneider | 2008-03-02 17:11:45 +0000 |
---|---|---|
committer | Christian Schneider | 2008-03-02 17:11:45 +0000 |
commit | 27294932cd251d7c39a72f3fac172a1d61ab586a (patch) | |
tree | 69d4766e5be8c1c8a212339e2ae34e47f306138b /it_auto_prepend.php | |
parent | 3b1a369795c72ee0d42fdeaa1c71cd97a3685954 (diff) | |
download | itools-27294932cd251d7c39a72f3fac172a1d61ab586a.tar.gz itools-27294932cd251d7c39a72f3fac172a1d61ab586a.tar.bz2 itools-27294932cd251d7c39a72f3fac172a1d61ab586a.zip |
Do not convert files above 200k, link to unchanged files
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(); |