Quantcast
Channel: SharpDevelop Community
Viewing all articles
Browse latest Browse all 1764

Zip.FastZipHandling.ReadingOfLockedDataFiles NUnit test fails...

$
0
0

I downloaded the 0.86.0 SharpZipLib source, and built the binaries against the .NET 4.0 Framework, using MSVS2010.  I also installed the .msi distribution of NUnit v2.6.1 and ran the tests in the SharpZipLibTests project.

The NUnit Zip->FastZipHandling->ReadingOfLockedDataFiles test failed with the following information:

ICSharpCode.SharpZipLib.Tests.Zip.FastZipHandling.ReadingOfLockedDataFiles:
System.IO.IOException : The process cannot access the file 'C:\Users\me\AppData\Local\Temp\a.dat' because it is being used by another process.

The StackTrace reported is:

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)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at System.IO.File.Open(String path, FileMode mode, FileAccess access, FileShare share)
at ICSharpCode.SharpZipLib.Zip.FastZip.ProcessFile(Object sender, ScanEventArgs e) in C:\SDKs\SharpZipLib\SrcSamples\src\Zip\FastZip.cs:line 532
at ICSharpCode.SharpZipLib.Core.FileSystemScanner.OnProcessFile(String file) in C:\SDKs\SharpZipLib\SrcSamples\src\Core\FileSystemScanner.cs:line 410
at ICSharpCode.SharpZipLib.Core.FileSystemScanner.ScanDir(String directory, Boolean recurse) in C:\SDKs\SharpZipLib\SrcSamples\src\Core\FileSystemScanner.cs:line 496
at ICSharpCode.SharpZipLib.Core.FileSystemScanner.Scan(String directory, Boolean recurse) in C:\SDKs\SharpZipLib\SrcSamples\src\Core\FileSystemScanner.cs:line 455
at ICSharpCode.SharpZipLib.Zip.FastZip.CreateZip(Stream outputStream, String sourceDirectory, Boolean recurse, String fileFilter, String directoryFilter) in C:\SDKs\SharpZipLib\SrcSamples\src\Zip\FastZip.cs:line 394
at ICSharpCode.SharpZipLib.Tests.Zip.FastZipHandling.ReadingOfLockedDataFiles() in C:\SDKs\SharpZipLib\SrcSamples\tests\Zip\ZipTests.cs:line 2802

In SharpZipLibTests/Zip/ZipTests.cs (Line 2800), the FileAccess specified is Write and the FileShare specified is ReadWrite.  However, following the stack to the FastZip.ProcessFile method (Line 518; Line 532 listed in the StackTrace, is the end of the Catch), the FileAccess specified is Read and the FileShare specified there is only Read, not ReadWrite, which in the context of the File.Open call fails, because File.Open declares its FileShare parameter to be, "A System.IO.FileShare value specifying the type of access other threads have to the file" and with FastZipHandling.ReadingOfLockedDataFiles already writing to the file, it can't successfully open the file while guaranteeing other threads are only reading the file.

Changing the FileShare parameter to ReadWrite in FastZip.ProcessFile allows the NUnit test to succeed, though from the comments in the file I don't believe the behavior of allowing a file being processed to also be written to is really desired.  The solution seems to be to rewrite the unit test to work with a file that already exists and is being read from, with the associated File.Open call only allowing a FileShare permission of Read.  Please correct the issue.

Thank you.


Viewing all articles
Browse latest Browse all 1764

Trending Articles