Skip to content

Commit 7f81cac

Browse files
committed
Merge pull request #84 from mendelk/master
Touch new cacheFile with original file's timestamp. Fixes #83.
2 parents 7148fbf + b4b2cd7 commit 7f81cac

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

lib/MtHaml/Support/Php/Executor.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ private function compileFile($file)
7979
. '/' . substr($hash, 0, 2) . '/' . substr($hash, 2, 2) . '/'
8080
. substr($hash, 4) . '_' . basename($file) . '.php';
8181

82-
if ($this->options['debug'] || !file_exists($cacheFile) || filemtime($cacheFile) !== filemtime($file)) {
82+
$fileMtime = filemtime($file);
83+
84+
if ($this->options['debug'] || !file_exists($cacheFile) || filemtime($cacheFile) !== $fileMtime) {
8385

8486
$hamlCode = file_get_contents($file);
8587

@@ -93,7 +95,7 @@ private function compileFile($file)
9395
$compiledCode = $this->environment->compileString($hamlCode, $file);
9496
$compiledCode = $this->wrapCompiledCode($compiledCode, $funName);
9597

96-
$this->writeCacheFile($cacheFile, $compiledCode);
98+
$this->writeCacheFile($cacheFile, $compiledCode, $fileMtime);
9799
}
98100

99101
require_once $cacheFile;
@@ -117,8 +119,9 @@ function $funName(\$__variables)
117119
PHP;
118120
}
119121

120-
private function writeCacheFile($cacheFile, $contents)
122+
private function writeCacheFile($cacheFile, $contents, $timestamp)
121123
{
124+
122125
$dir = dirname($cacheFile);
123126

124127
if (!is_dir($dir)) {
@@ -153,5 +156,13 @@ private function writeCacheFile($cacheFile, $contents)
153156
, $cacheFile
154157
));
155158
}
159+
160+
if (!touch($cacheFile, $timestamp)) {
161+
throw new Exception(sprintf(
162+
"Failed writing cache file: `%s`"
163+
, $cacheFile
164+
));
165+
}
166+
156167
}
157168
}

0 commit comments

Comments
 (0)