Search code examples
objective-cxcodecocoazlibphp-ziparchive

OSX Lion libz unzipping file structure change


Basically when I unzip a file that has been stored on OSX Lion, I get the zip file name as a folder with the files inside the foler...

So Unzipping zipfile.zip gives me the folder 'zipfile' with 3 files inside of it.

1. zipfile.zip
2. zipfile
   ->file1
   ->file2
   ->file3

BUT

If it has been created/used in OSX Leopard, I get the 3 files unzipped but not in the folder 'zipfile', rather in the same directory as the zip file.

So the parent folder structure 'should' looks like:

1. zipfile.zip
2. file1
3. file2
4. file3

In OSX Lion, if I copy(or create) my file.zip, and unzip it in my xcode project using ZipArchive.mm

by Calling

-(BOOL) UnzipOpenFile:(NSString*) zipFile

and check the Log for:

NSLog([NSString stringWithFormat:@"%d entries in the zip file",globalInfo.number_entry] );

I get '10 entries in the zip file.'

If I do the same in OSX Leopard I get, 6 entries in the zip file.

I'm not really sure what 'globalInfo.number_entry' is supposed to mean, file attributes?

Why is there a difference in the way the zip file is being treated in OSX Lion? Basically it means that I have to copy my project to a Snow Leopard machine to make a build and use a zipfile.zip that has never been on an OSX Lion Operating system which has altered the attributes in some way, causing the process of unzipping to change, causing my project to break.

Anyone know what I'm getting at here? Such a small change and yet a massive problem.

From Lion when I output the zip file structure I have:

filename: zipfile/
filename: zipfile/.DS_Store
filename: __MACOSX/
filename: __MACOSX/zipfile/
filename: __MACOSX/zipfile/._.DS_Store
filename: zipfile/file1.db
filename: zipfile/file2.db
filename: __MACOSX/zipfile/._file2.db
filename: zipfile/suburbs.db
filename: __MACOSX/zipfile/._file3.db

And from OSX Leopard

file1.db
file2.db
__MACOSX/
__MACOSX/._file2.db
file3.db
__MACOSX/._file3.db

Solution

  • Big picture, I would guess that you have gotten TWO different .zip files here, not one, and they've been created differently.

    On one, you have selected the three files, right-clicked and selected "Compress 3 items".

    On the other, you have selected a folder, and selected "Compress (folder name)"

    The full pathname of each entry is stored in the zip file directory, and it won't magically disappear.

    If you really are starting from the exact same zip file on both machines, then I would grab a copy of a real unzip tool (there may already be one in /usr/bin/) and use the '/usr/bin/unzip -l zip file.zip' command to look at what is inside the archive, without expanding it.