Changeset 23590 for branches


Ignore:
Timestamp:
2014/08/14 11:37:36 (10 years ago)
Author:
kimoto
Message:

recursiveMkDirのPHP4サポートは不要
Windows環境の場合はmkdirのmodeは効かないのでテストを変更する
isAbsoluteRealPathの修正

Location:
branches/version-2_13-dev
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/version-2_13-dev/data/class/util/SC_Utils.php

    r23546 r23590  
    17951795     * この関数は, パスの存在チェックを行なわないため注意すること. 
    17961796     * 
    1797      * @param string $realpath チェック対象のパス 
     1797     * use File_Util::isAbsolute 
     1798     * http://pear.php.net/package/File_Util/ 
     1799     * 
     1800     * @param string $path チェック対象のパス 
    17981801     * @return boolean 絶対パスの場合 true 
    17991802     */ 
    1800     public static function isAbsoluteRealPath($realpath) 
    1801     { 
    1802         if (strpos(PHP_OS, 'WIN') === false) { 
    1803             return substr($realpath, 0, 1) == '/'; 
    1804         } else { 
    1805             return preg_match('/^[a-zA-Z]:(\\\|\/)/', $realpath) ? true : false; 
    1806         } 
     1803    public static function isAbsoluteRealPath($path) 
     1804    { 
     1805        if (preg_match('/(?:\/|\\\)\.\.(?=\/|$)/', $path)) { 
     1806            return false; 
     1807        } 
     1808        if (!strncasecmp(PHP_OS, 'win', 3)) { 
     1809            return (($path{0} == '/') ||  preg_match('/^[a-zA-Z]:(\\\|\/)/', $path)); 
     1810        } 
     1811        return ($path{0} == '/') || ($path{0} == '~'); 
    18071812    } 
    18081813 
    18091814    /** 
    18101815     * ディレクトリを再帰的に作成する. 
    1811      * 
    1812      * mkdir 関数の $recursive パラメーターを PHP4 でサポートする. 
    18131816     * 
    18141817     * @param  string  $pathname ディレクトリのパス 
     
    18171820     * @see http://jp.php.net/mkdir 
    18181821     */ 
    1819     public static function recursiveMkdir($pathname, $mode = 0777) 
    1820     { 
    1821         /* 
    1822          * SC_Utils_Ex への再帰は無限ループやメモリリークの懸念 
    1823          * 自クラスへ再帰する. 
    1824          */ 
    1825         is_dir(dirname($pathname)) || SC_Utils::recursiveMkdir(dirname($pathname), $mode); 
    1826  
    1827         return is_dir($pathname) || @mkdir($pathname, $mode); 
     1822    public static function recursiveMkdir($path, $mode = 0777) 
     1823    { 
     1824        // Windows環境ではmodeは効かない 
     1825        return mkdir($path, $mode, true); 
    18281826    } 
    18291827 
  • branches/version-2_13-dev/tests/class/util/SC_Utils/SC_Utils_recursiveMkDirTest.php

    r23546 r23590  
    3535{ 
    3636 
    37   static $TMP_DIR; 
     37    static $TMP_DIR; 
    3838 
    39   protected function setUp() 
    40   { 
    41     self::$TMP_DIR = realpath(dirname(__FILE__)) . "/../../../tmp"; 
    42     SC_Helper_FileManager::deleteFile(self::$TMP_DIR); 
    43     mkdir(self::$TMP_DIR, 0777, true); 
    44 // parent::setUp(); 
    45   } 
     39    protected function setUp() 
     40    { 
     41        self::$TMP_DIR = realpath(dirname(__FILE__)) . "/../../../tmp"; 
     42        SC_Helper_FileManager::deleteFile(self::$TMP_DIR); 
     43        mkdir(self::$TMP_DIR, 0777, true); 
     44        // parent::setUp(); 
     45    } 
    4646 
    47   protected function tearDown() 
    48   { 
    49     // parent::tearDown(); 
    50   } 
     47    protected function tearDown() 
     48    { 
     49        // parent::tearDown(); 
     50    } 
    5151 
    52   ///////////////////////////////////////// 
    53   public function testRecursiveMkdir_パーミッションを指定した場合_指定のパーミッションでディレクトリが作られる() 
    54   { 
    55     $path = realpath(dirname(__FILE__)) . "/../../../tmp/dir1/dir2/dir3/"; 
    56     $mode = 0755; 
     52    ///////////////////////////////////////// 
     53    public function testRecursiveMkdir_パーミッションを指定した場合_指定のパーミッションでディレクトリが作られる() 
     54    { 
     55        $path = realpath(dirname(__FILE__)) . "/../../../tmp/dir1/dir2/dir3/"; 
     56        $mode = 0755; 
    5757 
    58     $result = SC_Utils::recursiveMkdir($path, $mode); 
    59     $this->expected = '0755'; 
    60     $this->actual = substr(sprintf('%o', fileperms($path)), -4); 
     58        $result = SC_Utils::recursiveMkdir($path, $mode); 
     59        if (DIRECTORY_SEPARATOR == '\\') { 
     60            // Windows環境ではパーミッションを指定したディレクトリ作成が出来ない 
     61            $this->expected = true; 
     62            $this->actual = file_exists($path); 
     63            $this->verify('作成したディレクトリがあるかどうか'); 
     64        } else { 
     65            $this->expected = '0755'; 
     66            $this->actual = substr(sprintf('%o', fileperms($path)), -4); 
     67            $this->verify('作成したディレクトリのパーミッション'); 
     68        } 
    6169 
    62     $this->verify('作成したディレクトリのパーミッション'); 
    63   } 
     70    } 
    6471 
    65   public function testRecursiveMkdir_パーミッションを指定しない場合_0777でディレクトリが作られる() 
    66   { 
    67     $path = realpath(dirname(__FILE__)) . "/../../../tmp/dir1/dir2/dir3/"; 
     72    public function testRecursiveMkdir_パーミッションを指定しない場合_0777でディレクトリが作られる() 
     73    { 
     74        $path = realpath(dirname(__FILE__)) . "/../../../tmp/dir1/dir2/dir3/"; 
    6875 
    69     $result = SC_Utils::recursiveMkdir($path); 
    70     $this->expected = '0777'; 
    71     $this->actual = substr(sprintf('%o', fileperms($path)), -4); 
     76        $result = SC_Utils::recursiveMkdir($path); 
     77        if (DIRECTORY_SEPARATOR == '\\') { 
     78            // Windows環境ではパーミッションを指定したディレクトリ作成が出来ない 
     79            $this->expected = true; 
     80            $this->actual = file_exists($path); 
     81            $this->verify('作成したディレクトリがあるかどうか'); 
     82        } else { 
     83            $this->expected = '0777'; 
     84            $this->actual = substr(sprintf('%o', fileperms($path)), -4); 
     85            $this->verify('作成したディレクトリのパーミッション'); 
     86        } 
    7287 
    73     $this->verify('作成したディレクトリのパーミッション'); 
    74   } 
     88    } 
    7589 
    76   ////////////////////////////////////////// 
     90    ////////////////////////////////////////// 
    7791} 
    7892 
Note: See TracChangeset for help on using the changeset viewer.