DinoChiesa / DotNetZip

Library for creating and reading .ZIP files from a .NET Language
Other
113 stars 38 forks source link

ZipFile.Save() unhandled exception #10

Open athach opened 3 years ago

athach commented 3 years ago

Hi, First of, thank you very much for your sharing this excellent library!

There is an unhandled exception in SharedUtilities.GetFileLength() when calling ZipFile.Save() and it contains a file that you dont have access to.

I dont know how you want it to work but maybe this exception should be caught, a ZipError event is triggered and the save operation continuous without the file?

Maybe the current way of determining file size was chosen for a reason but there is an alternate way: return new FileInfo(fileName).Length;

Best regards

at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) at Ionic.Zip.SharedUtilities.GetFileLength(String fileName) in DotNetZip-master\Zip\Shared.cs:line 54 at Ionic.Zip.ZipEntry.MaybeUnsetCompressionMethodForWriting(Int32 cycle) in DotNetZip-master\Zip\ZipEntry.Write.cs:line 741 at Ionic.Zip.ZipEntry.WriteHeader(Stream s, Int32 cycle) in Zip\ZipEntry.Write.cs:line 1026 at Ionic.Zip.ZipEntry.Write(Stream s) in DotNetZip-master\Zip\ZipEntry.Write.cs:line 2214 at Ionic.Zip.ZipFile.Save() in DotNetZip-master\Zip\ZipFile.Save.cs:line 169

athach commented 3 years ago

A little background information. I am using the library in a backup application. Some files scheduled for backup may locked by another application, in this case the backup should still be completed but without the files that cannot be accessed.