SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

Corrupt zipfiles

Last post 10-07-2008 10:45 AM by JohnReilly. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 09-16-2008 11:10 AM

    • MvZ
    • Not Ranked
    • Joined on 09-16-2008
    • Posts 2

    Corrupt zipfiles

    When there is a file "in use", SharpZiplib (version 0.85.5.452) creates corrupt zipfiles.
    Is this a known issue ?

     

    I create zipfile with:

      

    ZipFile z = ZipFile.Create(zipFileStoragePath + zipFileName);

    z.BeginUpdate();

    GetFilesToZip(fileSystemInfosToZip, z);

    z.CommitUpdate();

    z.Close();

     

        private static void GetFilesToZip(FileSystemInfo[ fileSystemInfosToZip,  ZipFile z)
            {
                if (fileSystemInfosToZip != null && z != null)
                {
                    foreach (FileSystemInfo fi in fileSystemInfosToZip)
                    {
                        if (fi is DirectoryInfo)
                        {
                            DirectoryInfo di = (DirectoryInfo)fi;
                            z.AddDirectory(di.FullName);
                            GetFilesToZip(di.GetFileSystemInfos(), z);       // recursive !
                        }
                        else
                        {
                            z.Add(fi.FullName);
                        }
                    }
              }

    When opening a random file (with Excel) , no errors are generated when zipping, but result is a corrupt zipfile.


     

  • 10-06-2008 8:43 PM In reply to

    Re: Corrupt zipfiles

    You code is not execption safe.  Check out the using statement, or if you'd rather use try/finally to ensure the streams are closed.

    As for the locked file thing I am not aware of it but it could be a bug I guess.

    Cheers, -jr-

  • 10-07-2008 8:57 AM In reply to

    • MvZ
    • Not Ranked
    • Joined on 09-16-2008
    • Posts 2

    Re: Corrupt zipfiles

    Deep inside (DynamicDiskDataSource.GetSource) there's a file.OpenRead().
    If i replace this with File.Open(name,FileMode.Open,FileAccess.Read,FileShare.ReadWrite)

    then the problem is solved !

     

  • 10-07-2008 10:45 AM In reply to

    Re: Corrupt zipfiles

    Hi,

    Partially solved, the allowing FileShare.ReadWrite can allow the contents of the files to be changed which would give rise to fairly subtle problems in hard to pin down circumstances.  It can solve the issue for sure but it now depends on what other software is doing.

    That said it would seem that the current handling isnt quite right either as silent failure is not great.

    Cheers, -jr-

Page 1 of 1 (4 items)
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.