1

Closed

FlattenFoldersOnExtract does not work correctly

description

Hi
 
Used Version: V1.9.1.5, build from 2010-02-26 05:30
 
I try to extract files from a zip file (which was created with SharpZipLib by a customer) in a folder
  • I set the property 'FlattenFoldersOnExtract'
    -> The "zipFile.Extract(path)" / "zipFile.ExtractAll(path)" function extract the compressed files every time to the original full compressed path of the files. It ignores the default path which I pass to the extract functions.
    It makes no difference if I set the property 'FlattenFoldersOnExtract' or not.
     
  • A sample file can be found in the attachment.
     
     
    My workaround: I overwrite the filename with a new filename without any path information.
    But this cannot be a solution I think.
     
     
    Regards,
    Demian

file attachments

Closed Aug 3, 2011 at 7:36 AM by Cheeso
fixed in changeset 81486. v1.9.1.6 is the first binary release containing this fix.

comments

Cheeso wrote Aug 20, 2010 at 1:21 PM

Hi Cheso

I have posted the issue 11772.
It appears because the compressed files contains an absolute path with drive letters.

I have debugged the last commited version and do follow changes:


ZIP Partial DLL: ZipEntry.Extract.cs

Your original code:

1218: private bool ValidateOutput(string basedir, Stream outstream, out string OutputFile)
   {
       if (basedir != null)
       {
           // Sometimes the name on the entry starts with a slash.
           // Rather than unpack to the root of the volume, we're going to
           // drop the slash and unpack to the specified base directory.
           string f = this.FileName.Replace("\\","/");
           if (f.StartsWith("/"))
1227: f= this.FileName.Substring(1);


My modified version:

1218: private bool ValidateOutput(string basedir, Stream outstream, out string OutputFile)
   {
       if (basedir != null)
       {
           // Sometimes the name on the entry starts with a slash.
           // Rather than unpack to the root of the volume, we're going to
           // drop the slash and unpack to the specified base directory.
           string f = this.FileName.Replace("\\","/");
           // remove drive letter with separator
           if (f.IndexOf(':') == 1)
               f= f.Substring(2);
           //remove all beginning slashes (UNC path)
           while (f.StartsWith("/"))
           {
               f= f.Substring(1);
           }

You should change your line 1227 in each case into follow, otherwise you re-read the original filename and the replacement of the slashes are undo.
1227: f= f.Substring(1);


Regards,
Demian