Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unzip aborts when a file being unzipped already exists #54

Open
thomfriedel opened this issue Mar 17, 2018 · 8 comments
Open

Unzip aborts when a file being unzipped already exists #54

thomfriedel opened this issue Mar 17, 2018 · 8 comments

Comments

@thomfriedel
Copy link

Summary

Unzip aborts when a file being unzipped already exists

not unzipped Error Domain=NSCocoaErrorDomain Code=516 "The file “Painted_Bunting_184832.jpg” couldn’t be saved in the folder “Documents” because a file with the same name already exists." UserInfo={NSFilePath=/var/mobile/Containers/Data/Application/9C36C53F-A273-4C59-BCFB-241CA89ED18F/Documents/Painted_Bunting_184832.jpg}

I think there should be a way to configure abort/overwrite/skip for this situation. I need anything but abort. How can I change that? Thanks!

Steps to Reproduce

Expected Results

Actual Results

Regression & Version

Related Link

@weichsel
Copy link
Owner

The unzipItem method in the FileManager extension currently only supports simple extraction of an archive to an empty destination. I plan to add a delegate protocol (similar to the FileManagerDelegate of Foundation) in the future. This will allow custom actions before- or after individual entry extraction.

In the meantime, you can manually instantiate an Archive and iterate over all entries:

guard let archive = Archive(url: archiveURL, accessMode: .read) else  {
    return
}
for entry in archive {
    // Perform extraction here and skip for already existing entries
     try? archive.extract(entry, to: destinationURL)
}

@thomfriedel
Copy link
Author

thomfriedel commented Mar 19, 2018 via email

@lyc2345
Copy link

lyc2345 commented Jan 21, 2019

Hi @weichsel

I want to extract each files in .zip into a folder. And this folder has other files which can not be removed. So I need to extract my default data from .zip into that folder which default data sometimes modified.

How could I replace the existing file? I do the solution like above which you provide. But still face the same error.

Error Domain=NSCocoaErrorDomain Code=516 "The file “acc_head077_ch011.png” couldn’t be saved in the folder “DefaultData” because a file with the same name already exists." " UserInfo={NSFilePath=/var/mobile/Containers/Data/Application/71AD1914-4645-43D8-ACB2-14199BF24A65/Documents/AvatarDefaultData/acc_head077_ch011.png}

Here is my code

guard let archive = Archive(url: sourceURL, accessMode: .read) else {
        return
}
for entry in archive {
  let destinationEntryURL = destinationURL.appendingPathComponent(entry.path)
  _ = try archive.extract(entry, to: destinationEntryURL)
}

What do I miss?

Thanks for the reply

@weichsel
Copy link
Owner

You have to manually check for the items existence and then remove it via FileManager.removeItem(at:).

@lyc2345
Copy link

lyc2345 commented Jan 21, 2019

Got it!
Thanks so much

@tranty9597
Copy link

The unzipItem method in the FileManager extension currently only supports simple extraction of an archive to an empty destination. I plan to add a delegate protocol (similar to the FileManagerDelegate of Foundation) in the future. This will allow custom actions before- or after individual entry extraction.

In the meantime, you can manually instantiate an Archive and iterate over all entries:

guard let archive = Archive(url: archiveURL, accessMode: .read) else  {
    return
}
for entry in archive {
    // Perform extraction here and skip for already existing entries
     try? archive.extract(entry, to: destinationURL)
}

I've trying to do this but the performance is so terrible. Has any way to make it faster

@weichsel
Copy link
Owner

Are you running a debug build? There is a huge difference between debug and release builds.
You can also try to pass skipCRC32: true during extraction. This skips checksum calculations, which also speeds up extraction.

@NikKovIos
Copy link

Any news?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants