From: Geoffrey T. D. <da...@us...> - 2001-08-18 02:38:37
|
Update of /cvsroot/phpwiki/phpwiki/lib In directory usw-pr-cvs1:/tmp/cvs-serv30089/lib Modified Files: Tag: release-1_2-branch db_filesystem.php Log Message: Attempt to fix SF bug #413446. I think this bug was due to using PHP's file() function to slurp in the files (as an array of lines). The files, being serialized data, consist of only one (sometimes very long) line. I think (at least in some PHPs) this make the file() function unhappy. Fixed to use fread() rather than file(). Also make sure to open files in 'binary' mode. Index: db_filesystem.php =================================================================== RCS file: /cvsroot/phpwiki/phpwiki/lib/db_filesystem.php,v retrieving revision 1.4.2.2 retrieving revision 1.4.2.3 diff -C2 -r1.4.2.2 -r1.4.2.3 *** db_filesystem.php 2001/08/18 02:05:28 1.4.2.2 --- db_filesystem.php 2001/08/18 02:38:34 1.4.2.3 *************** *** 46,62 **** function RetrievePage($dbi, $pagename, $pagestore) { $filename = $dbi[$pagestore] . "/" . $pagename; ! if ($fd = @fopen($filename, "r")) { $locked = flock($fd, 1); # Read lock if (!$locked) { ExitWiki("Timeout while obtaining lock. Please try again"); } ! if ($data = file($filename)) { // unserialize $data into a hash ! $pagehash = unserialize(join("\n", $data)); ! } ! fclose($fd); ! if($data) { ! return $pagehash; ! } } else { return -1; --- 46,65 ---- function RetrievePage($dbi, $pagename, $pagestore) { $filename = $dbi[$pagestore] . "/" . $pagename; ! if ($fd = @fopen($filename, "rb")) { $locked = flock($fd, 1); # Read lock if (!$locked) { ExitWiki("Timeout while obtaining lock. Please try again"); } ! if ($data = fread($fd, filesize($filename))) { // unserialize $data into a hash ! $pagehash = unserialize($data); ! if (!is_array($pagehash)) ! ExitWiki(sprintf("'%s': corrupt file", ! htmlspecialchars($filename))); ! } ! fclose($fd); ! if ($data) { ! return $pagehash; ! } } else { return -1; *************** *** 80,93 **** $filename = $dbi . "/" . $pagename; ! if($fd = fopen($filename, 'a')) { $locked = flock($fd,2); #Exclusive blocking lock if (!$locked) { ExitWiki("Timeout while obtaining lock. Please try again"); ! } #Second (actually used) filehandle ! $fdsafe = fopen($filename, 'w'); ! fwrite($fdsafe, $pagedata); ! fclose($fdsafe); fclose($fd); } else { --- 83,101 ---- $filename = $dbi . "/" . $pagename; ! if($fd = fopen($filename, 'a+b')) { $locked = flock($fd,2); #Exclusive blocking lock if (!$locked) { ExitWiki("Timeout while obtaining lock. Please try again"); ! } ! #Second (actually used) filehandle ! #$fdsafe = fopen($filename, 'wb'); ! #fwrite($fdsafe, $pagedata); ! #fclose($fdsafe); ! ! rewind($fd); ! ftruncate($fd, 0); ! fwrite($fd, $pagedata); fclose($fd); } else { |