OSDN Git Service

ファイルロック処理を調整
authorarino <arino>
Thu, 18 Mar 2004 10:02:13 +0000 (19:02 +0900)
committerarino <arino>
Thu, 18 Mar 2004 10:02:13 +0000 (19:02 +0900)
file.php
plugin/attach.inc.php
plugin/counter.inc.php
plugin/online.inc.php

index 2902cdd..d83bdb8 100644 (file)
--- a/file.php
+++ b/file.php
@@ -2,7 +2,7 @@
 /////////////////////////////////////////////////
 // PukiWiki - Yet another WikiWikiWeb clone.
 //
-// $Id: file.php,v 1.39 2004/02/29 08:01:45 arino Exp $
+// $Id: file.php,v 1.40 2004/03/18 10:02:13 arino Exp $
 //
 
 // ¥½¡¼¥¹¤ò¼èÆÀ
@@ -126,7 +126,9 @@ function file_write($dir,$page,$str,$notimestamp=FALSE)
                
                $fp = fopen($file,'w')
                        or die_message('cannot write page file or diff file or other'.htmlspecialchars($page).'<br />maybe permission is not writable or filename is too long');
+               set_file_buffer($fp, 0);
                flock($fp,LOCK_EX);
+               rewind($fp);
                fputs($fp,$str);
                flock($fp,LOCK_UN);
                fclose($fp);
@@ -193,7 +195,9 @@ function put_recentdeleted($page)
        $lines = array_splice($lines,0,$maxshow_deleted);
        $fp = fopen(get_filename($whatsdeleted),'w')
                or die_message('cannot write page file '.htmlspecialchars($whatsdeleted).'<br />maybe permission is not writable or filename is too long');
+       set_file_buffer($fp, 0);
        flock($fp,LOCK_EX);
+       rewind($fp);
        fputs($fp,join('',$lines));
        fputs($fp,"#norelated\n"); // :)
        flock($fp,LOCK_UN);
@@ -221,7 +225,9 @@ function put_lastmodified()
        // create recent.dat (for recent.inc.php)
        $fp = fopen(CACHE_DIR.'recent.dat','w')
                or die_message('cannot write cache file '.CACHE_DIR.'recent.dat<br />maybe permission is not writable or filename is too long');
+       set_file_buffer($fp, 0);
        flock($fp,LOCK_EX);
+       rewind($fp);
        foreach ($recent_pages as $page=>$time)
        {
                fputs($fp,"$time\t$page\n");
@@ -232,7 +238,9 @@ function put_lastmodified()
        // create RecentChanges
        $fp = fopen(get_filename($whatsnew),'w')
                or die_message('cannot write page file '.htmlspecialchars($whatsnew).'<br />maybe permission is not writable or filename is too long');
+       set_file_buffer($fp, 0);
        flock($fp,LOCK_EX);
+       rewind($fp);
        foreach (array_splice(array_keys($recent_pages),0,$maxshow) as $page)
        {
                $time = $recent_pages[$page];
@@ -251,7 +259,9 @@ function put_lastmodified()
                
                $fp = fopen(CACHE_DIR.'autolink.dat','w')
                        or die_message('cannot write autolink file '.CACHE_DIR.'/autolink.dat<br />maybe permission is not writable');
+               set_file_buffer($fp, 0);
                flock($fp,LOCK_EX);
+               rewind($fp);
                fputs($fp,$pattern."\n");
                fputs($fp,$pattern_a."\n");
                fputs($fp,join("\t",$forceignorelist)."\n");
index 42b0edc..b71ff9f 100644 (file)
@@ -2,7 +2,7 @@
 /////////////////////////////////////////////////
 // PukiWiki - Yet another WikiWikiWeb clone.
 //
-//  $Id: attach.inc.php,v 1.38 2003/12/06 05:12:38 arino Exp $
+//  $Id: attach.inc.php,v 1.39 2004/03/18 10:02:13 arino Exp $
 //
 
 /*
@@ -434,7 +434,9 @@ class AttachFile
                $this->status['count'] = join(',',$this->status['count']);
                $fp = fopen($this->logname,'wb')
                        or die_message('cannot write '.$this->logname);
+               set_file_buffer($fp, 0);
                flock($fp,LOCK_EX);
+               rewind($fp);
                foreach ($this->status as $key=>$value)
                {
                        fwrite($fp,$value."\n");
index 4c1d17c..7531e5a 100644 (file)
@@ -5,7 +5,7 @@
  * CopyRight 2002 Y.MASUI GPL2
  * http://masui.net/pukiwiki/ masui@masui.net
  *
- * $Id: counter.inc.php,v 1.12 2003/12/02 09:21:36 arino Exp $
+ * $Id: counter.inc.php,v 1.13 2004/03/18 10:02:13 arino Exp $
  */
 
 // counter file
@@ -84,17 +84,17 @@ function plugin_counter_get_count($page)
        $counters[$page] = $default;
        
        // ¥«¥¦¥ó¥¿¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤¹¤ë¾ì¹ç¤ÏÆɤ߹þ¤à
-       $fp = NULL;
        $file = COUNTER_DIR.encode($page).COUNTER_EXT;
-       if (file_exists($file))
+       $fp = fopen($file, file_exists($file) ? 'r+' : 'w+')
+               or die_message('counter.inc.php:cannot open '.$file);
+       set_file_buffer($fp, 0);
+       flock($fp,LOCK_EX);
+       rewind($fp);
+       
+       foreach ($default as $key=>$val)
        {
-               $fp = fopen($file, 'r+')
-                       or die_message('counter.inc.php:cannot read '.$file);
-               flock($fp,LOCK_EX);
-               foreach ($default as $key=>$val)
-               {
-                       $counters[$page][$key] = rtrim(fgets($fp,256));
-               }
+               $counters[$page][$key] = rtrim(fgets($fp,256));
+               if (feof($fp)) { break; }
        }
        // ¥Õ¥¡¥¤¥ë¹¹¿·¤¬É¬Íפ«?
        $modify = FALSE;
@@ -120,41 +120,20 @@ function plugin_counter_get_count($page)
        }
        
        //¥Ú¡¼¥¸Æɤ߽Ф·»þ¤Î¤ß¥Õ¥¡¥¤¥ë¤ò¹¹¿·
-//     for PukiWiki/1.3.x
-//     $is_read = !(arg_check('add') || arg_check('edit') || arg_check('preview') ||
-//             $vars['preview'] != '' || $vars['write'] != '');
-//     for PukiWiki/1.4
-       $is_read = ($vars['cmd'] == 'read');
-       
-       if ($modify and $is_read)
+       if ($modify and $vars['cmd'] == 'read')
        {
-               // ¥Õ¥¡¥¤¥ë¤¬³«¤¤¤Æ¤¤¤ë
-               if ($fp)
-               {
-                       // ¥Õ¥¡¥¤¥ë¤ò´Ý¤á¤ë
-                       ftruncate($fp,0);
-                       rewind($fp);
-               }
-               else
-               {
-                       // ¥Õ¥¡¥¤¥ë¤ò³«¤¯
-                       $fp = fopen($file, 'w')
-                               or die_message('counter.inc.php:cannot write '.$file);
-                       flock($fp,LOCK_EX);
-               }
+               // ¥Õ¥¡¥¤¥ë¤ò´Ý¤á¤ë
+               rewind($fp);
+               ftruncate($fp,0);
                // ½ñ¤­½Ð¤¹
                foreach (array_keys($default) as $key)
                {
                        fputs($fp,$counters[$page][$key]."\n");
                }
        }
-       // ¥Õ¥¡¥¤¥ë¤¬³«¤¤¤Æ¤¤¤ë
-       if ($fp)
-       {
-               // ¥Õ¥¡¥¤¥ë¤òÊĤ¸¤ë
-               flock($fp,LOCK_UN);
-               fclose($fp);
-       }
+       // ¥Õ¥¡¥¤¥ë¤òÊĤ¸¤ë
+       flock($fp,LOCK_UN);
+       fclose($fp);
        
        return $counters[$page];
 }
index c92bad9..9d6dad1 100644 (file)
@@ -2,7 +2,7 @@
 /////////////////////////////////////////////////
 // PukiWiki - Yet another WikiWikiWeb clone.
 //
-// $Id: online.inc.php,v 1.7 2003/11/05 10:40:48 arino Exp $
+// $Id: online.inc.php,v 1.8 2004/03/18 10:02:13 arino Exp $
 //
 
 // user list file
@@ -29,7 +29,9 @@ function CheckUser($addr)
 {
        $usr_arr = file(USR_LST);
        $fp = fopen(USR_LST, 'w');
+       set_file_buffer($fp, 0);
        flock($fp,LOCK_EX);
+       rewind($fp);
        $now = UTIME;
        for ($i = 0; $i < count($usr_arr); $i++)
        {