Changeset 220

Show
Ignore:
Timestamp:
08/21/07 00:03:13 (1 year ago)
Author:
hans
Message:

ticket:75 - files excluded by fileset end up in .tgz but not .zip

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/classes/phing/tasks/ext/TarTask.php

    r144 r220  
    242242                    for ($i=0, $fcount=count($files); $i < $fcount; $i++) { 
    243243                        $f = new PhingFile($fsBasedir, $files[$i]); 
    244                         $filesToTar[] = $f->getAbsolutePath();                         
     244                        $filesToTar[] = $f->getAbsolutePath(); 
     245                        $this->log("Adding file " . $f->getPath() . " to archive.", Project::MSG_VERBOSE);                 
    245246                    }                     
    246247                    $tar->addModify($filesToTar, '', $fsBasedir->getAbsolutePath());             
  • trunk/classes/phing/tasks/ext/ZipTask.php

    r191 r220  
    3737class ZipTask extends MatchingTask { 
    3838     
     39        /** 
     40         * @var PhingFile 
     41         */ 
    3942    private $zipFile; 
     43     
     44    /** 
     45     * @var PhingFile 
     46     */ 
    4047    private $baseDir; 
    41  
     48         
     49    /** 
     50     * Whether to include empty dirs in the archive. 
     51     */ 
     52    private $includeEmpty = true; 
     53     
    4254    private $filesets = array(); 
    4355    private $fileSetFiles = array(); 
     
    4860     */ 
    4961    public function createFileSet() { 
    50         $this->fileset = new FileSet(); 
     62        $this->fileset = new ZipFileSet(); 
    5163        $this->filesets[] = $this->fileset; 
    5264        return $this->fileset; 
     
    6981    } 
    7082 
     83    /** 
     84     * Set the include empty dirs flag. 
     85     * @param  boolean  Flag if empty dirs should be tarred too 
     86     * @return void 
     87     * @access public 
     88     */ 
     89    function setIncludeEmptyDirs($bool) { 
     90        $this->includeEmpty = (boolean) $bool; 
     91    } 
     92     
    7193    /** 
    7294     * do the work 
     
    116138            $upToDate = true; 
    117139            foreach($this->filesets as $fs) { 
    118                 $ds = $fs->getDirectoryScanner($this->project); 
    119                 $files = $ds->getIncludedFiles(); 
     140                $files = $fs->getFiles($this->project, $this->includeEmpty); 
    120141                if (!$this->archiveIsUpToDate($files, $fs->getDir($this->project))) { 
    121142                    $upToDate = false; 
     
    137158            $zip = new Archive_Zip($this->zipFile->getAbsolutePath()); 
    138159             
    139             foreach($this->filesets as $fs) {                                 
    140                 $ds = $fs->getDirectoryScanner($this->project); 
    141                 $files = $ds->getIncludedFiles(); 
    142  
    143                 // FIXME  
    144                 // Current model is only adding directories implicitly.  This 
    145                 // won't add any empty directories.  Perhaps modify FileSet::getFiles() 
    146                 // to also include empty directories.  Not high priority, since non-inclusion 
    147                 // of empty dirs is probably not unexpected behavior for ZipTask. 
     160            foreach($this->filesets as $fs) { 
     161                 
     162                $files = $fs->getFiles($this->project, $this->includeEmpty); 
     163                 
    148164                $fsBasedir = (null != $this->baseDir) ? $this->baseDir : 
    149165                                                                        $fs->getDir($this->project); 
     
    152168                for ($i=0, $fcount=count($files); $i < $fcount; $i++) { 
    153169                    $f = new PhingFile($fsBasedir, $files[$i]); 
    154                     $filesToZip[] = $f->getAbsolutePath();                         
     170                    $filesToZip[] = $f->getAbsolutePath(); 
     171                    $this->log("Adding " . $f->getPath() . " to archive.", Project::MSG_VERBOSE);                         
    155172                } 
    156173                $zip->add($filesToZip, array('remove_path' => $fsBasedir->getCanonicalPath())); 
     
    180197    
    181198} 
     199 
     200 
     201 
     202 
     203/** 
     204 * This is a FileSet with the to specify permissions. 
     205 *  
     206 * Permissions are currently not implemented by PEAR Archive_Tar, 
     207 * but hopefully they will be in the future. 
     208 *  
     209 */ 
     210class ZipFileSet extends FileSet { 
     211 
     212    private $files = null; 
     213 
     214    /** 
     215     *  Get a list of files and directories specified in the fileset. 
     216     *  @return array a list of file and directory names, relative to 
     217     *    the baseDir for the project. 
     218     */ 
     219    public function getFiles(Project $p, $includeEmpty = true) { 
     220     
     221        if ($this->files === null) { 
     222         
     223            $ds = $this->getDirectoryScanner($p); 
     224            $this->files = $ds->getIncludedFiles(); 
     225             
     226            if ($includeEmpty) { 
     227             
     228                    // first any empty directories that will not be implicitly added by any of the files 
     229                                $implicitDirs = array(); 
     230                                foreach($this->files as $file) { 
     231                                        $implicitDirs[] = dirname($file); 
     232                                }  
     233                                 
     234                                $incDirs = $ds->getIncludedDirectories(); 
     235                                 
     236                                // we'll need to add to that list of implicit dirs any directories 
     237                                // that contain other *directories* (and not files), since otherwise 
     238                                // we get duplicate directories in the resulting tar 
     239                                foreach($incDirs as $dir) { 
     240                                        foreach($incDirs as $dircheck) { 
     241                                                if (!empty($dir) && $dir == dirname($dircheck)) { 
     242                                                        $implicitDirs[] = $dir; 
     243                                                } 
     244                                        } 
     245                                } 
     246                                 
     247                                $implicitDirs = array_unique($implicitDirs); 
     248                                 
     249                                // Now add any empty dirs (dirs not covered by the implicit dirs) 
     250                                // to the files array.  
     251                                 
     252                                foreach($incDirs as $dir) { // we cannot simply use array_diff() since we want to disregard empty/. dirs 
     253                                        if ($dir != "" && $dir != "." && !in_array($dir, $implicitDirs)) { 
     254                                                // it's an empty dir, so we'll add it. 
     255                                                $this->files[] = $dir; 
     256                                        } 
     257                                } 
     258                        } // if $includeEmpty 
     259                         
     260        } // if ($this->files===null) 
     261         
     262        return $this->files; 
     263    } 
     264 
     265}