Fixed bug #16707: Read from and write to same file hangs GM on network file system
authorJigal van Hemert <jigal@xs4all.nl>
Mon, 3 Jan 2011 11:55:05 +0000 (11:55 +0000)
committerJigal van Hemert <jigal@xs4all.nl>
Mon, 3 Jan 2011 11:55:05 +0000 (11:55 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@9981 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_div.php

index a55d5fb..d7830fb 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
-2011-01-01  Jigal van Hemert  <jigal@xs4all.nl>
+2011-01-03  Jigal van Hemert  <jigal@xs4all.nl>
 
        * Fixed bug #15712: Headline in non latin charsets will break after 100 - substr is not multibyte safe
+       * Fixed bug #16707: Read from and write to same file hangs GM on network file system
 
 2011-01-01  Oliver Hader  <oliver.hader@typo3.org>
 
index 12d1066..b40639f 100644 (file)
@@ -488,8 +488,15 @@ final class t3lib_div {
                $returnCode = '';
                if ($gfxConf['gif_compress'] && strtolower(substr($theFile, -4, 4)) == '.gif') { // GIF...
                        if (($type == 'IM' || !$type) && $gfxConf['im'] && $gfxConf['im_path_lzw']) { // IM
-                               $cmd = self::imageMagickCommand('convert', '"' . $theFile . '" "' . $theFile . '"', $gfxConf['im_path_lzw']);
-                               t3lib_utility_Command::exec($cmd);
+                                       // use temporary file to prevent problems with read and write lock on same file on network file systems
+                               $temporaryName  =  dirname($theFile) . '/' . md5(uniqid()) . '.gif';
+                                       // rename could fail, if a simultaneous thread is currently working on the same thing
+                               if (@rename($theFile, $temporaryName)) {
+                                       $cmd = self::imageMagickCommand('convert', '"' . $temporaryName . '" "' . $theFile . '"', $gfxConf['im_path_lzw']);
+                                       t3lib_utility_Command::exec($cmd);
+                                       unlink($temporaryName);
+                               }
+
                                $returnCode = 'IM';
                                if (@is_file($theFile)) {
                                        self::fixPermissions($theFile);