DDC-1259: Atomic creation of Proxy files #1585

Open
opened 2026-01-22 13:19:03 +01:00 by admin · 0 comments
Owner

Originally created by @doctrinebot on GitHub (Jul 8, 2011).

Originally assigned to: @Ocramius on GitHub.

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
Originally created by @doctrinebot on GitHub (Jul 8, 2011). Originally assigned to: @Ocramius on GitHub. 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 ```
admin added the ImprovementWon't Fix labels 2026-01-22 13:19:03 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1585