2011-08-22 43 views
3

Wehen我設置zip.MaxOutputSegmentSize足夠高,以便將只有一個zip文件它的工作。 只要我限制MaxOutputSegmentSize我得到這個錯誤後,其中一個分割文件達到其最大值 - 當我有一個像20MB這樣的值,它總是在文件「.z02」的末尾發生,如果值較小,它可能會之後也會出現一些文件。DotNetZip庫:創建拆分檔案 - System.UnauthorizedAccessException

如果我使用zip.ZipErrorAction = ZipErrorAction.Skip或.Retry,我得到一個System.ObjectDisposedException。

這裏有什麼問題或者這是DotNetZip Library中的一個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:

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

DotNetZip v1.9.1.5中存在與分段存檔相關的錯誤。你使用什麼版本? – Cheeso

+0

這是最新的1.9.1.8「這是DotNetZip v1.9的開發者工具包,這個軟件包的打包時間是星期六08-06-2011-215945.06。」 – SunDawn

+0

unauthorizedaccessexception是File.Move方法的一部分,可能意味着正在寫入的文件已經存在並且已經被使用(可能甚至是您自己的應用程序),或者是隻讀或特權的,否則您無權創建或刪除該目錄中的文件。很難說這裏出了什麼問題,但我想DotNetZip社區可以幫助你,或者你可以嘗試使用SysInternals Suite工具在該文件夾中觀察文件操作,以查看調試過程中發生了什麼。 objectdisposedexception的堆棧跟蹤也可能會告訴我們一些東西,發佈它。 – mtijn

回答

1

問題是在一個文件夾中有gzip文件(帶密碼的.gz) - 似乎DotNetZip不能分割那些(7zip可以)。因此,只要它到達填充了這些gzip文件的.zip文件的末尾,就會發生異常。

我現在使用了一種解決方法,所以我循環所有文件,計算總大小,並在每次達到我的最大大小時創建單個(未分割)zip文件。

DotNetZip的問題(Bug?)依然存在。