[www] r787 - trunk/packs.matroska.org/data

[email protected]
Newsgroups gmane.comp.multimedia.matroska.cvs
Message-ID <[email protected]>
Author: robux4
Date: 2004-11-16 18:50:36 +0300 (Tue, 16 Nov 2004)
New Revision: 787

Modified:
   trunk/packs.matroska.org/data/helper.php
Log:
better, but still not good for race conditions (the lock works only when the file has been trashed by fopen("w"))

Modified: trunk/packs.matroska.org/data/helper.php
===================================================================
--- trunk/packs.matroska.org/data/helper.php	2004-11-16 15:24:03 UTC (rev 786)
+++ trunk/packs.matroska.org/data/helper.php	2004-11-16 15:50:36 UTC (rev 787)
@@ -63,29 +63,35 @@
 		echo " / ";
 		echo number_format($filesize[$packversion][$packname], 0, '.', '\'') . " Bytes";
 	}
-	
-	
+
 	function safe_read_file($file)
 	{
-    $fp = fopen($file,"r");
-    if (flock($fp, LOCK_EX)) { // exclusive lock
-    	$return = fread($fp, filesize($file));
-    	flock($fp, LOCK_UN);
-    } else {
-    	$return = "";
-    }
-    fclose($fp);
-    return $return;
-  }
-  
+		$return = "";
+		$fp = fopen($file,"r");
+		if($fp)
+		{
+			if (flock($fp, LOCK_EX)) { // exclusive lock
+				$return = fread($fp, filesize($file));
+				flock($fp, LOCK_UN);
+			}    	
+			fclose($fp);
+		}    
+		return $return;
+	}
+
 	function safe_write_file($file,$data)
 	{
-		$fp = fopen($file, "w");
-		if (flock($fp, LOCK_EX)) { // exclusive lock
-   		fwrite($fp, $data);
-   		flock($fp, LOCK_UN);
+		if(count($data))
+		{
+			$fp = fopen($file, "w");
+			if($fp)
+			{
+				if (flock($fp, LOCK_EX)) { // exclusive lock
+				fwrite($fp, $data);
+				flock($fp, LOCK_UN);
+				}
+				fclose($fp);
+			}
 		}
-		fclose($fp);
-  }
-  	
+	}  	
 ?>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.