Salvage (part of) a corrupted zip archive in Mac OS X

Perhaps this has been pointed out elsewhere; I haven’t really searched for it, so I don’t know. But it’s rare that I stumble, completely on my own, onto what I believe is truly a “hot tip” for dealing with computer problems, and when I do, I’m excited to share it.

Now then, the problem we’re dealing with here is corrupted zip archives, which seems to be common for me these days given the fact that I’ve foolishly been using some cheap off-brand CD-R’s that have been sitting around my house on a spindle for a couple of years.

The situation manifests as such: You double-click a zip archive to extract the files, BOMArchiveHelper fires up (don’t worry if you have no idea what this is — basically it’s just a background application embedded in Mac OS X for working with zip files), and the extraction process begins.

But then, oh dear. After a while (usually right near the end), the progress bar will change to a disconcerting alert: Unable to unarchive... (Error 1 - Operation not permitted.) Aside from the meaninglessness of the error message itself, you realize, dishearteningly, that the only thing you can do is click the “OK” button, at which point… *poof* everything is gone. Well, the zip file itself is still there, but what good is it if the goodies are forever locked inside?

I’ve discovered, however, that while BOMArchiveHelper is busily extracting the archive, it creates a hidden temporary directory on the hard drive in the same directory as the zip file. Once you click “OK” on this alert, it deletes this temporary directory, but until then, it’s there. With all of the files so far extracted waiting inside. Oblivious to the doom that shortly awaits them.

So what do you do? Well, the first thing you do is get your pointer away from that “OK” button! Leave the alert on the screen, and fire up Terminal. You’re going to need to get your hands dirty with some command line mucky-muck, so if you don’t know where Terminal is, I advise you to just stop right here. Cup your hands over your face and sob quietly.

Now then, this is most likely going to require root access, so type sudo -s and enter your administrator password. Then navigate to the directory where the zip file is. Type ls -al and amongst the hidden files at the top of the list (the ones whose filenames begin with a period), you’ll see a subdirectory named .BAH1234. (The 1234 will be some random number, which I am guessing is the process ID. But it’ll always start with .BAH.) Make note of the exact name, because you’ll need it in a minute.

Everything that’s been extracted so far is inside this directory! So now you can move or copy the contents to another directory and BOMArchiveHelper won’t take it upon itself to “tidy up” after you click the OK button. Here’s some code to try:

mkdir Rescued
mv .BAH1234/* Rescued/

Be sure to change the 1234 portion to whatever the correct name is, as you determined by running ls -al earlier. Also, note that if you’re extracting multiple zip archives at the same time, they may be handled by the same process, so you’ll have a second directory named .BAH1234 2 or something similar. Since this name contains a space, when you’re referring to it at the command line you need to wrap it in quotes, like this:

mv “.BAH1234 2″/* Rescued/

This will create a new (visible) directory at the same place on the hard drive, called Rescued, and it will copy everything from BOMArchiveHelper’s invisible temporary directory into Rescued, where you can now work with the files as you wish. It’s unlikely that everything from the zip file will be in here, but everything that’s not corrupted in the archive will be, and it might just be the things you were looking for.

Once everything’s been moved into your Rescued directory, you can go ahead and succumb to the temptation of that gently pulsating, deliciously blue (or not-so-deliciously gray, depending on your system settings) “OK” button.

Comments

21 responses to “Salvage (part of) a corrupted zip archive in Mac OS X”

  1. zacksmith Avatar

    Thanks for this! Quite a life-saver! Blessings…

  2. Jon Avatar
    Jon

    Thank you, this worked great and saved a ton of work! :-)

  3. Jessica Avatar
    Jessica

    Thank you thank you thank you!!!

    Saved a bunch of ‘corrupted’ files :D

    You are a lifesaver…

  4. Lurker Avatar
    Lurker

    This saved me big time. I really appreciate you posting this!

  5. k.online Avatar
    k.online

    This is soooo cool!!! Thanks so much… you saved my a$$!

  6. aidanRowe Avatar
    aidanRowe

    Thanks – looks like it worked a charm.

  7. Maverick RSA Avatar

    Hey

    I have just had this happen to some work documents that I zipped, I have followed to the steps but when I type ls -al, it does not show the hidden directory named . BAH****

    Please help!

  8. room34.com Avatar

    Hmm… Well, it’s possible that they’ve changed the name of the hidden folder. But, hidden items always start with a period. Also, you can tell if something is a folder by looking at the permissions at the far left. Each item will have a set of permissions that will look something like this:

    -rwxr-xr-x

    On files, this will begin with a hyphen, like shown above. Folders will have a “d” (for directory) at the beginning, like this:

    drwxr-xr-x

    So, assuming you’re looking in the right place (the list should also include the zip file you’re trying to open), then I’d say any hidden folder you see is probably the one. (Probably. You might want to copy it instead of renaming it. Use the command cp instead of mv to copy.)

    Let me know how it goes!

  9. Netta Avatar
    Netta

    I feel silly even having to type this question, but I need help! For some reason terminal is giving me the “Permission denied” messages after navigating to the zip file and typing ls -al. Thoughts? Thanks!

  10. room34.com Avatar

    Well, there may be some file permission issues with the zip file itself, or the files inside the zip may have different permissions set. I don’t think I’ve ever tried this with a zip file I hadn’t created myself (and therefore I’ve always had full permissions on the files inside).

    Do you know if your user account has administrator privileges on the computer?

  11. Netta Avatar
    Netta

    HI, thanks for the super fast response. I did create the zip, actually, which is why I’m so confused by this silly message. I checked the permissions of the zip itself, and set all to read / write and it’s still failing in terminal. Is this a lost cause?

    Thanks again!

  12. al Avatar
    al

    so awesome. helped me out a ton. except this trick doesn’t work with snow leopard. I had to use it on my older laptop with leopard.

    Still, better than no files. Thanks! you are a mad genius.

  13. room34.com Avatar

    Thanks for the tip that this doesn’t work in Snow Leopard. I had no idea, since I haven’t had to deal with this issue in years (probably since I wrote this post, four years ago).

  14. Darren Avatar
    Darren

    room34… I just used this on 10.6.6 and it worked (full recovery). THANK YOU!

  15. Marc Tytus Avatar

    Hmm… Doesn’t work on 10.6.8, FYI.

  16. room34 Avatar

    Can you provide any specifics?

  17. help Avatar
    help

    i am also getting a permission denied error in terminal
    but maybe because when i try to extract the .zip is says that it is “unable to expand “document name” into downloads”

  18. room34 Avatar

    Did you do the sudo -s command as described above? You may need to do that to get around any file permission issues, but if you’ve done it, you should be able to work with any files.

  19. Kanon Kulpa Avatar
    Kanon Kulpa

    Followed your instructions to the letter and didn’t once see “.BAH …” Please advise.

  20. room34 Avatar

    Please bear in mind that this is not an official Apple support website, and that this entry was posted over 5 years ago. It’s quite possible that Apple has changed how BOMArchiveHelper handles extracting zip files now. I haven’t encountered the problem myself in several years, so I haven’t kept up to date on the situation.

    If you do happen to find a solution to the problem as it exists in 2012, though, please feel free to share it here. Thanks!

  21. Plant Fooder Avatar
    Plant Fooder

    The temporary files are handled the same way in The Unarchiver, under a directory called .TheUnarchiverTemp0 in this case, rather than .BAH####.  I’m sure the new place where Archive Utility’s temporary files are located wouldn’t be too hard to find (they’ve got to be SOMEWHERE, right? maybe in the user Library somewhere?), but The Unarchiver is more capable and seems to be the de facto archive utility alternative for OS X anyway, and sometimes is better about extracting “broken” archives anyway, so I’d consider that to be a solution. (under Lion/10.7.3)