Wehen我将zip.MaxOutputSegmentSize设置得足够高,因此只有一个zip文件可以工作。 一旦我限制了MaxOutputSegmentSize,我就会在其中一个分割文件达到其最大大小后得到此错误 - 当我有一个20MB的值时,它总是在文件“.z02”的末尾出现,如果值较小,它也可能稍后会出现一些文件。
如果我使用zip.ZipErrorAction = ZipErrorAction.Skip或.Retry,我会得到一个System.ObjectDisposedException。
这可能是什么问题,或者这是DotNetZip库中的Bug?
ZipFile zip = new ZipFile(backupPath + "Backup.zip");
zip.MaxOutputSegmentSize = maxSize;
//zip.TempFileFolder = @"D:\Backup\Temp"; //seems not to make any difference
zip.Comment = "Backup created at " + System.DateTime.Now.ToString("G");
zip.AddFile(dbBackup.FullName,"Database");
zip.AddDirectory(physicalAppPath,"Application");
zip.AddDirectory(mailArchivePath,"MailArchive");
zip.Save(); //Exception occurs here
堆栈跟踪:
bei System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
bei System.IO.File.Move(String sourceFileName, String destFileName)
bei Ionic.Zip.ZipSegmentedStream.TruncateBackward(UInt32 diskNumber, Int64 offset)
bei Ionic.Zip.ZipEntry.Write(Stream s)
bei Ionic.Zip.ZipFile.Save()
bei MyProject.Configuration.Backup.BackupLogic.Backup(Boolean monthly) in D:\projects\MyProject.Configuration\Backup\BackupLogic.cs:Zeile 100.
bei MyProject.Configuration.Backup.BackupLogic.ScheduledBackup() in D:\projects\MyProject.Configuration\Backup\BackupLogic.cs:Zeile 42.
bei MyProject.Configuration.BackupTimer.CreateThread(Object parameters) in D:\projects\MyProject.Configuration\BackupTimer.cs:Zeile 60.
bei System.Threading.ExecutionContext.runTryCode(Object userData)
bei System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
bei System.Threading.ThreadHelper.ThreadStart(Object obj)
使用ZipErrorAction.Skip的异常和StackTrace:
ObjectDisposed Exception was unhandled: Auf eine geschlossene Datei kann nicht zugegriffen werden. (Could not access an closed file)
bei System.IO.FileStream.get_Position()
bei Ionic.Zip.ZipEntry.Write(Stream s)
bei Ionic.Zip.ZipFile.Save()
...
目标文件夹上带有过滤器的进程监视器没有显示任何可疑内容:(在这种情况下创建了3个分割文件,然后发生了异常)
12:35:25.6312905 PM w3wp.exe 5380 CreateFile D:\Backup SUCCESS Desired Access: Write Data/Add File, Synchronize, Disposition: Open, Options: , Attributes: n/a, ShareMode: Read, Write, AllocationSize: n/a, Impersonating: NT-AUTORITÄT\IUSR, OpenResult: Opened
12:35:25.6319249 PM w3wp.exe 5380 CloseFile D:\Backup SUCCESS
12:35:27.7507327 PM w3wp.exe 5380 CreateFile D:\Backup SUCCESS Desired Access: Write Data/Add File, Synchronize, Disposition: Open, Options: , Attributes: n/a, ShareMode: Read, Write, AllocationSize: n/a, Impersonating: NT-AUTORITÄT\IUSR, OpenResult: Opened
12:35:27.7511904 PM w3wp.exe 5380 CloseFile D:\Backup SUCCESS
12:35:32.9936509 PM w3wp.exe 5380 CreateFile D:\Backup SUCCESS Desired Access: Write Data/Add File, Synchronize, Disposition: Open, Options: , Attributes: n/a, ShareMode: Read, Write, AllocationSize: n/a, Impersonating: NT-AUTORITÄT\IUSR, OpenResult: Opened
12:35:32.9941529 PM w3wp.exe 5380 CloseFile D:\Backup SUCCESS
答案 0 :(得分:1)
问题是在一个文件夹中有gzip文件(带密码的.gz) - 似乎DotNetZip无法分割那些(7zip可以)。因此,只要它到达填充了这些gzip文件的.zip文件的末尾,就会发生异常。
我现在使用了一种解决方法,所以我循环所有文件,计算总大小并在每次达到我的最大尺寸时创建单个(不是拆分的)zip文件。
DotNetZip的问题(Bug?)仍然存在。