- //XXX: to avoid partial content in reverse cache we use atomic rotation write, unlink and move
- try {
- if (file_put_contents($output.'.new', $content) === false) {
- throw new \Exception();
- }
- } catch(\Exception $e) {
- throw new Error(sprintf('Unable to write to: %s', $output.'.new'), $token->getLine(), $stream->getSourceContext(), $e);
- }
-
- //Remove old file
- if (is_file($output)) {
- try {
- if (unlink($output) === false) {
- throw new \Exception();
- }
- } catch (\Exception $e) {
- throw new Error(sprintf('Unable to unlink: %s', $output), $token->getLine(), $stream->getSourceContext(), $e);
- }
- }
-
- //Rename it