Skip to content

Commit

Permalink
Refactored code
Browse files Browse the repository at this point in the history
  • Loading branch information
flip111 authored and Philippe Lagas committed Nov 18, 2013
1 parent 2aef39d commit 15d314f
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/Metadata/Cache/FileCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,26 @@ public function putClassMetadataInCache(ClassMetadata $metadata)
file_put_contents($tmpFile, '<?php return unserialize('.var_export(serialize($metadata), true).');');
chmod($tmpFile, 0666 & ~umask());

if (false === @rename($tmpFile, $path)) {
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
if (false === unlink($path)) {
throw new \RuntimeException(sprintf('(WIN) Could not delete temp cache file to %s.', $path));
$this->renameFile($tmpFile, $path);
}

/**
* Renames a file with fallback for windows
*
* @param string $oldname
* @param string $newname
*/
private function renameFile($oldname, $newname) {
if (false === @rename($oldname, $newname)) {
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
if (false === unlink($newname)) {
throw new \RuntimeException(sprintf('(WIN) Could not delete temp cache file to %s.', $newname));
}
if (false === copy($tmpFile, $path)) {
throw new \RuntimeException(sprintf('(WIN) Could not write new cache file to %s.', $path));
if (false === copy($oldname, $newname)) {
throw new \RuntimeException(sprintf('(WIN) Could not write new cache file to %s.', $newname));
}
} else {
throw new \RuntimeException(sprintf('Could not write new cache file to %s.', $path));
throw new \RuntimeException(sprintf('Could not write new cache file to %s.', $newname));
}
}
}
Expand Down

0 comments on commit 15d314f

Please sign in to comment.