Ignore:
Timestamp:
2010/07/20 13:25:33 (14 years ago)
Author:
kajiwara
Message:

EC-CUBE Ver2.4.4 分コミット。詳細はこちら( http://www.ec-cube.net/release/detail.php?release_id=223

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/data/class/util/GC_Utils.php

    r18562 r18758  
    33 * This file is part of EC-CUBE 
    44 * 
    5  * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved. 
     5 * Copyright(c) 2000-2010 LOCKON CO.,LTD. All Rights Reserved. 
    66 * 
    77 * http://www.lockon.co.jp/ 
     
    160160    /** 
    161161     * ログローテーション機能 
    162      * 
     162     * XXX この類のローテーションは通常 0 開始だが、本実装は 1 開始である。 
    163163     * @param integer $max_log 最大ファイル数 
    164164     * @param integer $max_size 最大サイズ 
     
    168168    function gfLogRotation($max_log, $max_size, $path) { 
    169169 
    170         // ディレクトリ名を取得 
    171         $dirname = dirname($path); 
    172         // ファイル名を取得 
    173         $basename = basename($path); 
    174         //umask値を777にする。スクリプトが終われば元のumask値に戻る。 
    175         umask(0); 
    176         // ファイルが最大サイズを超えていないかチェック 
    177         if(filesize($path) > $max_size) { 
    178             if ($dh = opendir($dirname)) { 
    179                 while (($file = readdir($dh)) !== false) { 
    180                     // ログローテーションにて作成されたファイルを取得 
    181                     if(ereg("^". $basename . "\." , $file)) { 
    182                         $arrFile[] = $file; 
    183                     } 
    184                 } 
    185  
    186                 // ローテーションにて作成されたログファイルが存在しない場合は実行しない 
    187                 if(is_array($arrFile)) { 
    188                     // ソートを行う 
    189                     natcasesort($arrFile); 
    190  
    191                     // ファイルログが最大個数なら以上なら古いファイルから削除する 
    192                     $count = count($arrFile); 
    193                     if($count >= $max_log) { 
    194                         $diff = $count - $max_log; 
    195                         for($i = 0; $diff >= $i ; $i++) { 
    196                             unlink($dirname . "/" . array_pop($arrFile)); 
    197                         } 
    198                     } 
    199  
    200                     // ログファイルの添え字をずらす 
    201                     $count = count($arrFile); 
    202                     for($i = $count; 1 <= $i; $i--) { 
    203                         $move_number = $i + 1; 
    204                         if(file_exists("$path.$move_number")) { 
    205                             unlink("$path.$move_number"); 
    206                         } 
    207                         copy("$dirname/" . $arrFile[$i - 1], "$path.$move_number"); 
    208                     } 
    209                 } 
    210                 $ret = copy($path, "$path.1"); 
    211  
    212                 // 新規ログファイルを作成 
    213                 if($ret) { 
    214                     unlink($path); 
    215                     touch($path); 
    216                     chmod($path, 0666); 
    217                 } 
     170        // ファイルが最大サイズを超えていない場合、終了 
     171        if (filesize($path) <= $max_size) return; 
     172 
     173        // アーカイブのインクリメント(削除を兼ねる) 
     174        for ($i = $max_log; $i >= 2; $i--) { 
     175            $path_old = "$path." . ($i - 1); 
     176            $path_new = "$path.$i"; 
     177            if (file_exists($path_old)) { 
     178                rename($path_old, $path_new); 
    218179            } 
    219180        } 
     181 
     182        // 現在ファイルのアーカイブ 
     183        rename($path, "$path.1"); 
    220184    } 
    221185 
Note: See TracChangeset for help on using the changeset viewer.