Changeset 196ff59


Ignore:
Timestamp:
11/11/11 23:04:16 (6 months ago)
Author:
mrook
Branches:
master
Children:
2baac48
Parents:
85f3723
git-author:
Michiel Rook <mrook@…> (11/11/11 23:04:16)
git-committer:
Michiel Rook <mrook@…> (11/11/11 23:04:16)
Message:

Fixes #818 - add overwrite option to symlink task

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • classes/phing/tasks/ext/SymlinkTask.php

    r1c858ce r196ff59  
    8383     
    8484    /** 
     85     * Whether to override the symlink if it exists but points 
     86     * to a different location 
     87     * 
     88     * (default value: false) 
     89     * 
     90     * @var boolean 
     91     * @access private 
     92     */ 
     93    private $_overwrite = false; 
     94 
     95    /** 
    8596     * setter for _target 
    8697     *  
     
    117128        return $this->_filesets[$num-1]; 
    118129    } 
    119      
     130 
     131    /** 
     132     * setter for _overwrite 
     133     * 
     134     * @access public 
     135     * @param boolean $overwrite 
     136     * @return void 
     137     */ 
     138    public function setOverwrite($overwrite) 
     139    { 
     140        $this->_overwrite = $overwrite; 
     141    } 
     142 
    120143    /** 
    121144     * getter for _target 
     
    158181        return $this->_filesets; 
    159182    } 
    160      
     183 
     184    /** 
     185     * getter for _overwrite 
     186     * 
     187     * @access public 
     188     * @return boolean 
     189     */ 
     190    public function getOverwrite() 
     191    { 
     192        return $this->_overwrite; 
     193    } 
     194 
    161195    /** 
    162196     * Generates an array of directories / files to be linked 
     
    249283    protected function symlink($target, $link) 
    250284    { 
    251         if(file_exists($link)) { 
    252             $this->log('Link exists: ' . $link, Project::MSG_ERR); 
    253             return false; 
     285        if (file_exists($link)) { 
     286            if (!is_link($link)) { 
     287                $this->log('File exists: ' . $link, Project::MSG_ERR); 
     288                return false; 
     289            } 
     290 
     291            if (readlink($link) == $target || !$this->getOverwrite()) { 
     292                $this->log('Link exists: ' . $link, Project::MSG_ERR); 
     293                return false; 
     294            } 
     295 
     296            unlink($link); 
    254297        } 
    255298     
  • docs/phing_guide/book/chapters/appendixes/AppendixC-OptionalTasks.html

    r62794c5 r196ff59  
    72037203                                <td>Yes</td> 
    72047204                        </tr> 
     7205                        <tr> 
     7206                                <td>overwrite</td> 
     7207                                <td>Boolean</td> 
     7208                                <td>Whether to override the symlink if it exists but points  
     7209                                to a different location</td> 
     7210                                <td>false</td> 
     7211                                <td>No</td> 
     7212                        </tr> 
    72057213                </tbody> 
    72067214        </table> 
Note: See TracChangeset for help on using the changeset viewer.