Skip to content

Loading…

DDC-1259: Atomic creation of Proxy files #1869

Open
doctrinebot opened this Issue · 1 comment

2 participants

@doctrinebot

Jira issue originally created by user @beberlei:

From 265e5086ea51ebcafc73f91abc64334d17e2f416 Mon Sep 17 00:00:00 2001
From: Karsten Dambekalns <karsten@typo3.org>
Date: Wed, 25 May 2011 12:11:55 <ins>0200
Subject: [PATCH 4/5] Use temporary file and rename for proxy class creation

Instead of a simple file*put*contents() the proxy class code is written to a
temporary file and renamed to the final filename. This allows file access even
if only allowed by the directory permission.
---
 lib/Doctrine/ORM/Proxy/ProxyFactory.php |   10 </ins><ins></ins><ins></ins><ins></ins><ins></ins>-
 1 files changed, 9 insertions(<ins>), 1 deletions(-)

diff --git a/lib/Doctrine/ORM/Proxy/ProxyFactory.php b/lib/Doctrine/ORM/Proxy/ProxyFactory.php
index f0cf19c..b2d42fb 100644
--- a/lib/Doctrine/ORM/Proxy/ProxyFactory.php
</ins><ins></ins> b/lib/Doctrine/ORM/Proxy/ProxyFactory.php
@@ -152,7 <ins>152,15 @@ class ProxyFactory

         $file = str_replace($placeholders, $replacements, $file);

-        file*put_contents($fileName, $file, LOCK*EX);
</ins>        $temporaryFileName = $fileName . uniqid( ) . '.temp';
<ins>        $result = file*put*contents( $temporaryFileName, $file );
</ins>
<ins>        if($result === FALSE) throw new \RuntimeException('The temporary proxy class file "' . $temporaryFileName . '" could not be written.');
</ins>        $i = 0;
<ins>        while(!rename( $temporaryFileName, $fileName ) && $i < 5) {
</ins>            $i<ins></ins>;
<ins>        }
</ins>        if($result === FALSE) throw new \RuntimeException('The proxy class file "' . $fileName . '" could not be written.');
     }

     /****
-- 
1.7.4.1
@doctrinebot

Comment created by @beberlei:

Nette Framework uses a safe stream: https://github.com/nette/nette/blob/master/Nette/Utils/SafeStream.php

@beberlei beberlei was assigned by doctrinebot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.