Changeset 1238

Show
Ignore:
Timestamp:
01/15/08 01:49:21 (8 months ago)
Author:
mikey
Message:

introduce star file format version 2: expanded space for id in header entry from 80 to 232 bytes, dropped basename and path from header entry to keep the maximum length of 256 bytes per header entry

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/build/star/compile-reader.ini

    r1210 r1238  
    1111title = "Stubbles Archive Reader" 
    1212package = "org::stubbles::star" 
    13 version = "0.6.0" 
     13version = "0.7.0" 
    1414author = "Stubbles Development Team <http://stubbles.net> 
    1515copyright = "© 2007-2008 Stubbles Development Team" 
  • trunk/build/star/compile-writer-archive.ini

    r1210 r1238  
    1515title = "Stubbles Archive Writer" 
    1616package = "org::stubbles::star" 
    17 version = "0.6.0" 
     17version = "0.7.0" 
    1818author = "Stubbles Development Team <http://stubbles.net> 
    1919copyright = "© 2007-2008 Stubbles Development Team" 
  • trunk/build/star/compile-writer-cli.ini

    r1210 r1238  
    1616title = "Stubbles Archive CLI Writer" 
    1717package = "org::stubbles::star" 
    18 version = "0.6.0" 
     18version = "0.7.0" 
    1919author = "Stubbles Development Team <http://stubbles.net> 
    2020copyright = "© 2007-2008 Stubbles Development Team" 
  • trunk/src/main/php/org/stubbles/phing/tasks/stubStarWriterTask.php

    r1218 r1238  
    6464    protected $preface     = null; 
    6565    /** 
     66     * the version of the starfile to build 
     67     * 
     68     * @var  int 
     69     */ 
     70    protected $starVersion = 2; 
     71    /** 
    6672     * the path to put the star archive into 
    6773     * 
     
    146152    { 
    147153        $this->preface = $preface; 
     154    } 
     155 
     156    /** 
     157     * sets the star version number 
     158     * 
     159     * @param  string  $starVersion 
     160     */ 
     161    public function setStarVersion($starVersion) 
     162    { 
     163        $this->starVersion = $starVersion; 
    148164    } 
    149165 
     
    205221 
    206222        // works now with refactored buildfile 
    207         /* 
     223         
    208224        $decorators = array(); 
    209225        foreach ($this->decorators as $decorator) { 
    210226            $decorators[$decorator->getStarId()] = $decorator; 
    211227        } 
    212         */ 
    213  
    214         $starArchive = new StarArchive(new StarWriter($this->buildPath)); 
     228         
     229         
     230        $starArchive = new StarArchive(new StarWriter($this->buildPath), $this->starVersion); 
    215231        foreach($this->filesets as $fs) { 
    216232            try { 
     
    240256 
    241257                    $this->log('Adding ' . $fullFileName . ' as ' . $id); 
    242                     if (isset($decorators[$id]) == false) { 
     258                    if (isset($decorators[$id]) === false) { 
    243259                        $starFile = new StarFile($fullFileName, $this->baseSrcPath); 
    244260                    } else { 
  • trunk/src/main/php/org/stubbles/star/StarArchive.php

    r235 r1238  
    5050    protected $metadata             = array(); 
    5151    /** 
    52      * star archive version 
    53      */ 
    54     const VERSION                   = 1; 
     52     * star archive version to create 
     53     * 
     54     * @var  int 
     55     */ 
     56    protected $version                  = 2; 
    5557     
    5658    /** 
     
    5961     * @param  StarWriter  $writer  writer to use 
    6062     */ 
    61     public function __construct(StarWriter $writer
     63    public function __construct(StarWriter $writer, $version = 2
    6264    { 
    6365        $this->writer = $writer; 
    6466        $this->writer->setExtension('star'); 
     67        $this->version = $version; 
    6568    } 
    6669     
     
    137140        $this->writer->write(pack('a4c1a8a14a229', 
    138141                                  'star', 
    139                                   self::VERSION
     142                                  $this->version
    140143                                  (string) count($ids), 
    141144                                  date('YmdHis'), 
     
    146149        // write index 
    147150        foreach ($ids as $id) { 
    148             $this->writer->write(pack('a80a72a80a8a8a8', 
    149                                       $id, 
    150                                       $this->index[$id]['basename'], 
    151                                       $this->index[$id]['path'], 
    152                                       (string) $this->index[$id]['datasize'], 
    153                                       (string) $offset, 
    154                                       "\0" 
    155                                  ) 
    156             ); 
     151            $this->writer->write($this->getHeader($id, $offset)); 
    157152            $offset += $this->index[$id]['datasize']; 
    158153        } 
     
    172167        $this->writer->close(); 
    173168    } 
     169 
     170    /** 
     171     * returns the header of entries depending on requested version 
     172     * 
     173     * @param   string  $id      id of entry to create header data for 
     174     * @param   int     $offset  offset where entry is located in file 
     175     * @return  string 
     176     */ 
     177    protected function getHeader($id, $offset) 
     178    { 
     179        switch ($this->version) { 
     180            case 1: 
     181                $method = 'getHeaderForVersion1'; 
     182                break; 
     183             
     184            case 2: 
     185            default: 
     186                $method = 'getHeaderForVersion2'; 
     187        } 
     188         
     189        return $this->$method($id, $offset); 
     190    } 
     191 
     192    /** 
     193     * returns the header of entries for star files version 1 
     194     * 
     195     * @param   string  $id      id of entry to create header data for 
     196     * @param   int     $offset  offset where entry is located in file 
     197     * @return  string 
     198     */ 
     199    protected function getHeaderForVersion1($id, $offset) 
     200    { 
     201        return pack('a80a72a80a8a8a8', $id, 
     202                                       $this->index[$id]['basename'], 
     203                                       $this->index[$id]['path'], 
     204                                       (string) $this->index[$id]['datasize'], 
     205                                       (string) $offset, 
     206                                       "\0" 
     207               ); 
     208    } 
     209 
     210    /** 
     211     * returns the header of entries for star files version 2 
     212     * 
     213     * @param   string  $id      id of entry to create header data for 
     214     * @param   int     $offset  offset where entry is located in file 
     215     * @return  string 
     216     */ 
     217    protected function getHeaderForVersion2($id, $offset) 
     218    { 
     219        return pack('a232a8a8a8', $id, 
     220                                  (string) $this->index[$id]['datasize'], 
     221                                  (string) $offset, 
     222                                  "\0" 
     223               ); 
     224    } 
    174225} 
    175226?> 
  • trunk/src/main/php/org/stubbles/star/StarConsole.php

    r235 r1238  
    4242                                                         'default' => '' 
    4343                                                   ), 
     44                                   'star'       => array('short'   => 's', 
     45                                                         'min'     => 0, 
     46                                                         'max'     => 1, 
     47                                                         'desc'    => 'Star version to use: 1 or 2.', 
     48                                                         'default' => '' 
     49                                                   ), 
    4450                                   'verbose'    => array('short'   => 'v', 
    4551                                                         'min'     => 0, 
     
    6672     */ 
    6773    private $target; 
     74    /** 
     75     * star version to use 
     76     * 
     77     * @var  int 
     78     */ 
     79    private $starVersion = 2; 
    6880     
    6981    /** 
     
    144156            $this->target = $this->args->getValue('target'); 
    145157        } 
     158         
     159        if ($this->args->isDefined('star') == true) { 
     160            $this->starVersion = $this->args->getValue('star'); 
     161        } 
    146162    } 
    147163     
     
    164180        $target = ((null == $this->target) ? ($conf['MAIN']['target']) : ($this->target)); 
    165181        $this->verbose('Writing star data to ' . $target . "\n"); 
    166         $starArchive = new StarArchive(new StarWriter($target)); 
     182        $starArchive = new StarArchive(new StarWriter($target), $this->starVersion); 
    167183        $removePath  = null; 
    168184        if ($this->args->isDefined('removePath') == true) { 
  • trunk/src/main/php/org/stubbles/star/StarStreamWrapper.php

    r614 r1238  
    103103        } 
    104104         
     105        if (1 === $header['version']) { 
     106            $key = 'a80id/a72filename/a80path/a8size/a8offset/a*reserved'; 
     107        } else { 
     108            $key = 'a232id/a8size/a8offset/a*reserved'; 
     109        } 
     110 
    105111        for ($i = 0; $i < $header['indexsize']; $i++) { 
    106             $entry = unpack('a80id/a72filename/a80path/a8size/a8offset/a*reserved', 
    107                             fread($current['handle'], 0x0100) 
    108                      ); 
    109              
     112            $entry  = unpack($key, fread($current['handle'], 0x0100)); 
    110113            $current['index'][$entry['id']]  = array('size' => (int) $entry['size'], 'offset' => (int) $entry['offset']); 
    111114            $current['header']['totalSize'] += 0x0100 + ((int) $entry['size']);