Skip to content

ZipFile.AddOrUpdateImpl not adding base dir files if recurse == false #10

@bstordrup

Description

@bstordrup

While debugging, I noticed something that seems like a bug.

if you pass in false in the recurse parameter to the ZipFile.AddOrUpdateImpl function, files in the base folder will not be added to the zip file.

Current implementation (partial):

                String[] filenames = Directory.GetFiles(directoryName);

                if (recurse)
                {
                    // add the files:
                    foreach (String filename in filenames)
                    {
                        if (_addOperationCanceled) break;
                        if (action == AddOrUpdateAction.AddOnly)
                            AddFile(filename, dirForEntries);
                        else
                            UpdateFile(filename, dirForEntries);
                    }

                    if (!_addOperationCanceled)
                    {
                        // add the subdirectories:
                        String[] dirnames = Directory.GetDirectories(directoryName);
                        foreach (String dir in dirnames)
                        {
                            // workitem 8617: Optionally traverse reparse points
                            FileAttributes fileAttrs = System.IO.File.GetAttributes(dir);
                            if (this.AddDirectoryWillTraverseReparsePoints
                                || ((fileAttrs & FileAttributes.ReparsePoint) == 0)
                                )
                                AddOrUpdateDirectoryImpl(dir, rootDirectoryPathInArchive, action, recurse, level + 1);
                        }
                    }
                }

I think the implementation of this part should be:

                String[] filenames = Directory.GetFiles(directoryName);

                // add the files:
                foreach (String filename in filenames)
                {
                    if (_addOperationCanceled) break;
                    if (action == AddOrUpdateAction.AddOnly)
                        AddFile(filename, dirForEntries);
                    else
                        UpdateFile(filename, dirForEntries);
                }

                if (recurse && !_addOperationCanceled)
                {
                    // add the subdirectories:
                    String[] dirnames = Directory.GetDirectories(directoryName);
                    foreach (String dir in dirnames)
                    {
                        // workitem 8617: Optionally traverse reparse points
                        FileAttributes fileAttrs = System.IO.File.GetAttributes(dir);
                        if (this.AddDirectoryWillTraverseReparsePoints
                            || ((fileAttrs & FileAttributes.ReparsePoint) == 0)
                            )
                            AddOrUpdateDirectoryImpl(dir, rootDirectoryPathInArchive, action, recurse, level + 1);
                    }
                }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions