Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Changeset 3195

Show
Ignore:
Timestamp:
02/16/08 01:13:06 (10 months ago)
Author:
DRK
Message:

Renamed ZipArchive?,ZipFolder? to ZipFolder?,ZipSubFolder?, and updated the vfszip example to match. closes #839

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/example/vfs/vfszip.d

    r3127 r3195  
    11module vfszip; 
    22 
    3 import tango.io.vfs.ZipArchive
     3import tango.io.vfs.ZipFolder
    44import tango.io.Stdout; 
    55 
     
    2323        zipname = "tmp.zip"; 
    2424 
    25     auto archive = new ZipArchive(zipname); 
     25    auto archive = new ZipFolder(zipname); 
    2626    auto info = archive.self; 
    2727 
  • trunk/tango/io/vfs/ZipFolder.d

    r3185 r3195  
    55    license:    BSD style: $(LICENSE) 
    66 
    7     version:    Initial release: December 2007 
     7    version:    The Great Namechange: February 2008 
     8 
     9                Initial release: December 2007 
    810 
    911    author:     Daniel Keep 
     
    1113*******************************************************************************/ 
    1214 
    13 module tango.io.vfs.ZipArchive
     15module tango.io.vfs.ZipFolder
    1416 
    1517import tango.io.FileConduit : FileConduit; 
     
    2426import tango.util.PathUtil : patternMatch; 
    2527 
    26 debug( ZipArchive
     28debug( ZipFolder
    2729{ 
    2830    import tango.io.Stdout : Stderr; 
     
    172174                        file.tempFile.output.copy(zi).close; 
    173175 
    174                         debug( ZipArchive
     176                        debug( ZipFolder
    175177                            Stderr.formatln("Entry.openOutput: duplicated" 
    176178                                    " temp file {} for {}", 
     
    187189                    file.tempFile = new TempFile; 
    188190 
    189                     debug( ZipArchive
     191                    debug( ZipFolder
    190192                        Stderr.formatln("Entry.openOutput: created" 
    191193                                " temp file {} for {}", 
     
    241243                    break; 
    242244 
    243                 debug( ZipArchive
     245                debug( ZipFolder
    244246                { 
    245247                default: 
     
    277279 
    278280/** 
    279  * ZipArchive serves as the root object for all Zip archives in the VFS. 
     281 * ZipFolder serves as the root object for all Zip archives in the VFS. 
    280282 * Presently, it can only open archives on the local filesystem. 
    281283 */ 
    282 class ZipArchive : ZipFolder 
     284class ZipFolder : ZipSubFolder 
    283285{ 
    284286    /** 
     
    291293    body 
    292294    { 
    293         debug( ZipArchive
    294             Stderr.formatln(`ZipArchive("{}", {})`, path, readonly); 
     295        debug( ZipFolder
     296            Stderr.formatln(`ZipFolder("{}", {})`, path, readonly); 
    295297        this(FilePath(path), readonly); 
    296298    } 
     
    301303    body 
    302304    { 
    303         debug( ZipArchive
    304             Stderr.formatln(`ZipArchive("{}", {})`, path, readonly); 
     305        debug( ZipFolder
     306            Stderr.formatln(`ZipFolder("{}", {})`, path, readonly); 
    305307        this.resetArchive(path, readonly); 
    306308        super(this, root); 
     
    316318    body 
    317319    { 
    318         debug( ZipArchive
    319             Stderr.formatln("ZipArchive.close({})",commit); 
     320        debug( ZipFolder
     321            Stderr.formatln("ZipFolder.close({})",commit); 
    320322 
    321323        // MUTATE 
     
    351353    body 
    352354    { 
    353         debug( ZipArchive
    354             Stderr("ZipArchive.sync()").newline; 
     355        debug( ZipFolder
     356            Stderr("ZipFolder.sync()").newline; 
    355357 
    356358        if( !modified ) 
    357359            return this; 
    358360 
    359 version( ZipArchive_NonMutating ) 
    360 { 
    361         mutate_error("ZipArchive.sync"); 
     361version( ZipFolder_NonMutating ) 
     362{ 
     363        mutate_error("ZipFolder.sync"); 
    362364        assert(false); 
    363365} 
     
    380382                    tempFile = new TempFile(path.path, TempFile.Permanent); 
    381383                    os = tempFile.output; 
    382                     debug( ZipArchive
     384                    debug( ZipFolder
    383385                        Stderr.formatln(" sync: created temp file {}", 
    384386                                tempFile.path); 
     
    422424 
    423425        // With that done, we can free all our handles, etc. 
    424         debug( ZipArchive
     426        debug( ZipFolder
    425427            Stderr(" sync: close").newline; 
    426428        this.close(/*commit*/ false); 
     
    431433        if( tempFile !is null ) 
    432434        { 
    433             debug( ZipArchive
     435            debug( ZipFolder
    434436                Stderr(" sync: destroying temp file").newline; 
    435437            auto tempFilePath = tempFile.path.dup; 
    436438            delete tempFile; 
    437             debug( ZipArchive
     439            debug( ZipFolder
    438440                Stderr.formatln(" sync: renaming {} to {}", 
    439441                        tempFilePath, path); 
     
    443445        // Finally, re-open the archive so that we have all the nicely 
    444446        // compressed files. 
    445         debug( ZipArchive
     447        debug( ZipFolder
    446448            Stderr(" sync: reset archive").newline; 
    447449        this.resetArchive(path, readonly); 
    448450         
    449         debug( ZipArchive
     451        debug( ZipFolder
    450452            Stderr(" sync: reset folder").newline; 
    451453        this.reset(this, root); 
    452454 
    453         debug( ZipArchive
     455        debug( ZipFolder
    454456            Stderr(" sync: done").newline; 
    455457 
     
    484486    final bool closed() 
    485487    { 
    486         debug( ZipArchive
    487             Stderr("ZipArchive.closed()").newline; 
     488        debug( ZipFolder
     489            Stderr("ZipFolder.closed()").newline; 
    488490        return (root is null); 
    489491    } 
     
    491493    final bool valid() 
    492494    { 
    493         debug( ZipArchive
    494             Stderr("ZipArchive.valid()").newline; 
     495        debug( ZipFolder
     496            Stderr("ZipFolder.valid()").newline; 
    495497        return !closed; 
    496498    } 
     
    516518    body 
    517519    { 
    518         debug( ZipArchive
    519             Stderr.formatln(`ZipArchive.resetArchive("{}", {})`, path, readonly); 
    520  
    521         debug( ZipArchive
     520        debug( ZipFolder
     521            Stderr.formatln(`ZipFolder.resetArchive("{}", {})`, path, readonly); 
     522 
     523        debug( ZipFolder
    522524            Stderr.formatln(" .. size of Entry: {0}, {0:x} bytes", Entry.sizeof); 
    523525 
     
    624626 * This class represents a folder in an archive.  In addition to supporting 
    625627 * the sync operation, you can also use the archive member to get a reference 
    626  * to the underlying ZipArchive instance. 
     628 * to the underlying ZipFolder instance. 
    627629 */ 
    628 class ZipFolder : VfsFolder, VfsSync 
     630class ZipSubFolder : VfsFolder, VfsSync 
    629631{ 
    630632    /// 
     
    693695        // Locate the folder in question.  We do this by "walking" the 
    694696        // path components.  If we find a component that doesn't exist, 
    695         // then we create a ZipFolderEntry for the remainder. 
     697        // then we create a ZipSubFolderEntry for the remainder. 
    696698        Entry* curent = this.entry; 
    697699 
     
    719721                // If the next component doesn't exist, return a folder entry. 
    720722                // If the tail is empty, return a folder entry as well (let 
    721                 // the ZipFolderEntry do the last lookup.) 
    722                 return new ZipFolderEntry(archive, curent, ht); 
     723                // the ZipSubFolderEntry do the last lookup.) 
     724                return new ZipSubFolderEntry(archive, curent, ht); 
    723725        } 
    724726        while( true ); 
     
    730732    body 
    731733    { 
    732         return new ZipFolderGroup(archive, this, false); 
     734        return new ZipSubFolderGroup(archive, this, false); 
    733735    } 
    734736 
     
    738740    body 
    739741    { 
    740         return new ZipFolderGroup(archive, this, true); 
     742        return new ZipSubFolderGroup(archive, this, true); 
    741743    } 
    742744 
     
    752754            if( childEntry.isDir ) 
    753755            { 
    754                 VfsFolder childFolder = new ZipFolder(archive, childEntry); 
     756                VfsFolder childFolder = new ZipSubFolder(archive, childEntry); 
    755757                if( (result = dg(childFolder)) != 0 ) 
    756758                    break; 
     
    766768    body 
    767769    { 
    768 version( ZipArchive_NonMutating ) 
     770version( ZipFolder_NonMutating ) 
    769771{ 
    770772        mutate_error("VfsFolder.clear"); 
     
    826828    body 
    827829    { 
    828         auto zipfolder = cast(ZipFolder) folder; 
     830        auto zipfolder = cast(ZipSubFolder) folder; 
    829831 
    830832        if( mounting 
     
    844846 
    845847    /** 
    846      * Returns a reference to the underlying ZipArchive instance. 
     848     * Returns a reference to the underlying ZipFolder instance. 
    847849     */ 
    848     final ZipArchive archive() { return _archive; } 
     850    final ZipFolder archive() { return _archive; } 
    849851 
    850852private: 
    851     ZipArchive _archive; 
     853    ZipFolder _archive; 
    852854    Entry* entry; 
    853855    VfsStats stats; 
    854856 
    855     final ZipArchive archive(ZipArchive v) { return _archive = v; } 
    856  
    857     this(ZipArchive archive, Entry* entry) 
     857    final ZipFolder archive(ZipFolder v) { return _archive = v; } 
     858 
     859    this(ZipFolder archive, Entry* entry) 
    858860    { 
    859861        this.reset(archive, entry); 
    860862    } 
    861863 
    862     final void reset(ZipArchive archive, Entry* entry) 
     864    final void reset(ZipFolder archive, Entry* entry) 
    863865    in 
    864866    { 
     
    895897    } 
    896898 
    897     final ZipFolder[] folders(bool collect) 
    898     in { assert( valid ); } 
    899     body 
    900     { 
    901         ZipFolder[] folders; 
     899    final ZipSubFolder[] folders(bool collect) 
     900    in { assert( valid ); } 
     901    body 
     902    { 
     903        ZipSubFolder[] folders; 
    902904        stats = stats.init; 
    903905 
     
    906908            if( childEntry.isDir ) 
    907909            { 
    908                 if( collect ) folders ~= new ZipFolder(archive, childEntry); 
     910                if( collect ) folders ~= new ZipSubFolder(archive, childEntry); 
    909911                ++ stats.folders; 
    910912            } 
     
    994996    body 
    995997    { 
    996 version( ZipArchive_NonMutating ) 
     998version( ZipFolder_NonMutating ) 
    997999{ 
    9981000        mutate_error("ZipFile.copy"); 
     
    10161018    body 
    10171019    { 
    1018 version( ZipArchive_NonMutating ) 
     1020version( ZipFolder_NonMutating ) 
    10191021{ 
    10201022        mutate_error("ZipFile.move"); 
     
    10391041    body 
    10401042    { 
    1041 version( ZipArchive_NonMutating ) 
     1043version( ZipFolder_NonMutating ) 
    10421044{ 
    10431045        mutate_error("ZipFile.create"); 
     
    10741076    body 
    10751077    { 
    1076 version( ZipArchive_NonMutating ) 
     1078version( ZipFolder_NonMutating ) 
    10771079{ 
    10781080        mutate_error("ZipFile.create"); 
     
    10931095    body 
    10941096    { 
    1095 version( ZipArchive_NonMutating ) 
     1097version( ZipFolder_NonMutating ) 
    10961098{ 
    10971099        mutate_error("ZipFile.remove"); 
     
    11431145    body 
    11441146    { 
    1145 version( ZipArchive_NonMutable ) 
     1147version( ZipFolder_NonMutable ) 
    11461148{ 
    11471149        mutate_error("ZipFile.output"); 
     
    11711173 
    11721174private: 
    1173     ZipArchive archive; 
     1175    ZipFolder archive; 
    11741176    Entry* entry; 
    11751177 
     
    11831185    } 
    11841186 
    1185     this(ZipArchive archive, Entry* parent, Entry* entry) 
     1187    this(ZipFolder archive, Entry* parent, Entry* entry) 
    11861188    in 
    11871189    { 
     
    11991201    } 
    12001202 
    1201     this(ZipArchive archive, Entry* parent, char[] name) 
     1203    this(ZipFolder archive, Entry* parent, char[] name) 
    12021204    in 
    12031205    { 
     
    12361238    } 
    12371239 
    1238     final void reset(ZipArchive archive, Entry* parent, Entry* entry) 
     1240    final void reset(ZipFolder archive, Entry* parent, Entry* entry) 
    12391241    in 
    12401242    { 
     
    12551257    } 
    12561258 
    1257     final void reset(ZipArchive archive, Entry* parent, char[] name) 
     1259    final void reset(ZipFolder archive, Entry* parent, char[] name) 
    12581260    in 
    12591261    { 
     
    12881290// ************************************************************************ // 
    12891291 
    1290 class ZipFolderEntry : VfsFolderEntry 
     1292class ZipSubFolderEntry : VfsFolderEntry 
    12911293{ 
    12921294    final override VfsFolder open() 
     
    12961298        auto entry = (name in parent.dir.children); 
    12971299        if( entry ) 
    1298             return new ZipFolder(archive, *entry); 
     1300            return new ZipSubFolder(archive, *entry); 
    12991301 
    13001302        else 
    13011303        { 
    13021304            // NOTE: this can be called with a multi-part path. 
    1303             error("ZipFolderEntry.open: \"" 
     1305            error("ZipSubFolderEntry.open: \"" 
    13041306                    ~ parent.fullname ~ "/" ~ name 
    13051307                    ~ "\" does not exist"); 
     
    13111313    body 
    13121314    { 
    1313 version( ZipArchive_NonMutating ) 
     1315version( ZipFolder_NonMutating ) 
    13141316{ 
    13151317        // TODO: different exception if folder exists (this operation is 
    13161318        // currently invalid either way...) 
    1317         mutate_error("ZipFolderEntry.create"); 
     1319        mutate_error("ZipSubFolderEntry.create"); 
    13181320        assert(false); 
    13191321} 
     
    13251327        // If the folder exists, we can't really create it, now can we? 
    13261328        if( this.exists ) 
    1327             error("ZipFolderEntry.create: cannot create folder that already " 
     1329            error("ZipSubFolderEntry.create: cannot create folder that already " 
    13281330                    "exists, and believe me, I *tried*"); 
    13291331         
     
    13401342 
    13411343        // Done 
    1342         return new ZipFolder(archive, entry); 
     1344        return new ZipSubFolder(archive, entry); 
    13431345} 
    13441346    } 
     
    13521354 
    13531355private: 
    1354     ZipArchive archive; 
     1356    ZipFolder archive; 
    13551357    Entry* parent; 
    13561358    char[] name; 
    13571359 
    1358     this(ZipArchive archive, Entry* parent, char[] name) 
     1360    this(ZipFolder archive, Entry* parent, char[] name) 
    13591361    in 
    13601362    { 
     
    13981400// ************************************************************************ // 
    13991401 
    1400 class ZipFolderGroup : VfsFolders 
     1402class ZipSubFolderGroup : VfsFolders 
    14011403{ 
    14021404    final override int opApply(int delegate(ref VfsFolder) dg) 
     
    14581460    body 
    14591461    { 
    1460         ZipFolder[] set; 
     1462        ZipSubFolder[] set; 
    14611463 
    14621464        foreach( folder ; members ) 
     
    14641466                set ~= folder; 
    14651467 
    1466         return new ZipFolderGroup(archive, set); 
     1468        return new ZipSubFolderGroup(archive, set); 
    14671469    } 
    14681470 
     
    14871489 
    14881490private: 
    1489     ZipArchive archive; 
    1490     ZipFolder[] members; 
    1491  
    1492     this(ZipArchive archive, ZipFolder root, bool recurse) 
     1491    ZipFolder archive; 
     1492    ZipSubFolder[] members; 
     1493 
     1494    this(ZipFolder archive, ZipSubFolder root, bool recurse) 
    14931495    out { assert( valid ); } 
    14941496    body 
     
    14981500    } 
    14991501 
    1500     this(ZipArchive archive, ZipFolder[] members) 
     1502    this(ZipFolder archive, ZipSubFolder[] members) 
    15011503    out { assert( valid ); } 
    15021504    body 
     
    15111513    } 
    15121514 
    1513     final ZipFolder[] scan(ZipFolder root, bool recurse) 
     1515    final ZipSubFolder[] scan(ZipSubFolder root, bool recurse) 
    15141516    in { assert( valid ); } 
    15151517    body 
     
    15631565 
    15641566private: 
    1565     ZipArchive archive; 
     1567    ZipFolder archive; 
    15661568    FileEntry[] group; 
    15671569    VfsStats stats; 
     
    15731575    } 
    15741576 
    1575     this(ZipArchive archive, ZipFolderGroup host, VfsFilter filter) 
     1577    this(ZipFolder archive, ZipSubFolderGroup host, VfsFilter filter) 
    15761578    out { assert( valid ); } 
    15771579    body 
     
    16011603void mutate_error(char[] method) 
    16021604{ 
    1603     error(method ~ ": mutating the contents of a ZipArchive
     1605    error(method ~ ": mutating the contents of a ZipFolder
    16041606            "is not supported yet; terribly sorry"); 
    16051607}