diff --git a/lib/Doctrine/Common/Annotations/FileCacheReader.php b/lib/Doctrine/Common/Annotations/FileCacheReader.php index 2acfa3194..24add1b3b 100644 --- a/lib/Doctrine/Common/Annotations/FileCacheReader.php +++ b/lib/Doctrine/Common/Annotations/FileCacheReader.php @@ -56,6 +56,11 @@ class FileCacheReader implements Reader */ private $classNameHashes = array(); + /** + * @var int + */ + private $umask; + /** * Constructor. * @@ -65,10 +70,19 @@ class FileCacheReader implements Reader * * @throws \InvalidArgumentException */ - public function __construct(Reader $reader, $cacheDir, $debug = false) + public function __construct(Reader $reader, $cacheDir, $debug = false, $umask = 0002) { + if ( ! is_int($umask)) { + throw new \InvalidArgumentException(sprintf( + 'The parameter umask must be an integer, was: %s', + gettype($umask) + )); + } + $this->reader = $reader; - if (!is_dir($cacheDir) && !@mkdir($cacheDir, 0777, true)) { + $this->umask = $umask; + + if (!is_dir($cacheDir) && !@mkdir($cacheDir, 0777 & (~$this->umask), true)) { throw new \InvalidArgumentException(sprintf('The directory "%s" does not exist and could not be created.', $cacheDir)); } @@ -206,12 +220,12 @@ private function saveCacheFile($path, $data) throw new \RuntimeException(sprintf('Unable to write cached file to: %s', $tempfile)); } + @chmod($tempfile, 0666 & (~$this->umask)); + if (false === rename($tempfile, $path)) { @unlink($tempfile); throw new \RuntimeException(sprintf('Unable to rename %s to %s', $tempfile, $path)); } - - @chmod($path, 0666 & ~umask()); } /**