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

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

Modified:
   trunk/packs.matroska.org/data/download.php
   trunk/packs.matroska.org/data/helper.php
   trunk/packs.matroska.org/data/index.php.de
   trunk/packs.matroska.org/data/index.php.en
   trunk/packs.matroska.org/data/index.php.fr
   trunk/packs.matroska.org/data/index.php.nl
   trunk/packs.matroska.org/data/index.php.pt
   trunk/packs.matroska.org/data/ircstats.php
   trunk/packs.matroska.org/data/showlog.php
Log:
revert to 787

Modified: trunk/packs.matroska.org/data/download.php
===================================================================
--- trunk/packs.matroska.org/data/download.php	2004-11-16 16:19:33 UTC (rev 790)
+++ trunk/packs.matroska.org/data/download.php	2004-11-16 16:31:31 UTC (rev 791)
@@ -26,25 +26,15 @@
 	}
 
 	// Save Download Stats
-/*	
-	$fp = fopen($logfilename,"r+");
-	if($fp)
+	$download = unserialize(safe_read_file($logfilename));
+	
+	// Make sure we opened the logfile correctly, otherwise we're gonna trash it
+	if (count($download) != 0)
 	{
-		if (flock($fp, LOCK_EX)) { // exclusive lock
-			$download = unserialize(fread($fp, filesize($file)));
-		
-			// Make sure we opened the logfile correctly, otherwise we're gonna trash it
-			if (count($download) != 0)
-			{
-				fseek($fp, 0);
-				$download[$version][$_REQUEST["id"]]++;
-				fwrite($fp, serialize($download));
-			}
-			flock($fp, LOCK_UN);
-		}
-		fclose($fp);
-	}    
-	*/
+		$download[$version][$_REQUEST["id"]]++;
+		safe_write_file($logfilename,serialize($download));
+	}
+	
 	// Create New Header
 	header("Location: $link");    
 }

Modified: trunk/packs.matroska.org/data/helper.php
===================================================================
--- trunk/packs.matroska.org/data/helper.php	2004-11-16 16:19:33 UTC (rev 790)
+++ trunk/packs.matroska.org/data/helper.php	2004-11-16 16:31:31 UTC (rev 791)
@@ -64,15 +64,34 @@
 		echo number_format($filesize[$packversion][$packname], 0, '.', '\'') . " Bytes";
 	}
 
-	function read_file($file)
+	function safe_read_file($file)
 	{
 		$return = "";
 		$fp = fopen($file,"r");
 		if($fp)
 		{
-			$return = fread($fp, filesize($file));
+			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)
+	{
+		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);
+			}
+		}
+	}  	
 ?>

Modified: trunk/packs.matroska.org/data/index.php.de
===================================================================
--- trunk/packs.matroska.org/data/index.php.de	2004-11-16 16:19:33 UTC (rev 790)
+++ trunk/packs.matroska.org/data/index.php.de	2004-11-16 16:31:31 UTC (rev 791)
@@ -1,6 +1,6 @@
 <?php
 	include("helper.php");
-	$download = unserialize(read_file('logs.txt'));
+	$download = unserialize(safe_read_file('logs.txt'));
 ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
 <html>

Modified: trunk/packs.matroska.org/data/index.php.en
===================================================================
--- trunk/packs.matroska.org/data/index.php.en	2004-11-16 16:19:33 UTC (rev 790)
+++ trunk/packs.matroska.org/data/index.php.en	2004-11-16 16:31:31 UTC (rev 791)
@@ -1,6 +1,6 @@
 <?php	
 	include("helper.php");
-	$download = unserialize(read_file('logs.txt'));
+	$download = unserialize(safe_read_file('logs.txt'));
 ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
 <html>

Modified: trunk/packs.matroska.org/data/index.php.fr
===================================================================
--- trunk/packs.matroska.org/data/index.php.fr	2004-11-16 16:19:33 UTC (rev 790)
+++ trunk/packs.matroska.org/data/index.php.fr	2004-11-16 16:31:31 UTC (rev 791)
@@ -1,6 +1,6 @@
 <?php
 	include("helper.php");
-	$download = unserialize(read_file('logs.txt'));
+	$download = unserialize(safe_read_file('logs.txt'));
 ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
 <html>

Modified: trunk/packs.matroska.org/data/index.php.nl
===================================================================
--- trunk/packs.matroska.org/data/index.php.nl	2004-11-16 16:19:33 UTC (rev 790)
+++ trunk/packs.matroska.org/data/index.php.nl	2004-11-16 16:31:31 UTC (rev 791)
@@ -1,6 +1,6 @@
 <?php	
 	include("helper.php");
-	$download = unserialize(read_file('logs.txt'));
+	$download = unserialize(safe_read_file('logs.txt'));
 ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
 <html>

Modified: trunk/packs.matroska.org/data/index.php.pt
===================================================================
--- trunk/packs.matroska.org/data/index.php.pt	2004-11-16 16:19:33 UTC (rev 790)
+++ trunk/packs.matroska.org/data/index.php.pt	2004-11-16 16:31:31 UTC (rev 791)
@@ -1,6 +1,6 @@
 <?php
 	include("helper.php");
-	$download = unserialize(read_file('logs.txt'));
+	$download = unserialize(safe_read_file('logs.txt'));
 ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
 <html>

Modified: trunk/packs.matroska.org/data/ircstats.php
===================================================================
--- trunk/packs.matroska.org/data/ircstats.php	2004-11-16 16:19:33 UTC (rev 790)
+++ trunk/packs.matroska.org/data/ircstats.php	2004-11-16 16:31:31 UTC (rev 791)
@@ -4,7 +4,7 @@
 
 $logfilename = "logs.txt";
 include("helper.php");
-$download = unserialize(read_file($logfilename));
+$download = unserialize(safe_read_file($logfilename));
 
 $totalcount = 0;
 $totalsize = 0;

Modified: trunk/packs.matroska.org/data/showlog.php
===================================================================
--- trunk/packs.matroska.org/data/showlog.php	2004-11-16 16:19:33 UTC (rev 790)
+++ trunk/packs.matroska.org/data/showlog.php	2004-11-16 16:31:31 UTC (rev 791)
@@ -3,7 +3,7 @@
 <pre>
 <?php
 $logfilename = "logs.txt";
-$download = unserialize(read_file($logfilename));
+$download = unserialize(safe_read_file($logfilename));
 print_r($download);
 ?>
 </pre>
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.