Skip to content

deleteFile erase more files than expected #523

Closed

Description

@matteo-cristino

To reporduce the issue create a folder with the following form

test
├── path1
│   ├── file1.txt
│   └── folder1
│       └── file2.txt
└── path2
    ├── file1.txt
    └── folder1
        └── file2.txt

create a zip, for example on linux terminal with

zip -r test.zip test

Now run the following code

import AdmZip from "adm-zip";

let zip = new AdmZip("./test.zip");

console.log("* Before delete of test/path1/:");
zip.getEntries().forEach((entry) => {
  console.log(entry.entryName);
});

zip.deleteFile("test/path1/");

console.log("");
console.log("* After delete of test/path1/:");
zip.getEntries().forEach((entry) => {
  console.log(entry.entryName);
});

The result will be

* Before delete of test/path1/:
test/
test/path2/
test/path2/file1.txt
test/path2/folder1/
test/path2/folder1/file2.txt
test/path1/
test/path1/file1.txt
test/path1/folder1/
test/path1/folder1/file2.txt

* After delete of test/path1/:
test/
test/path2/
test/path2/file1.txt
test/path2/folder1/

As it can be seen during the deletion of /test/path1/ also /test/path2/folder1/file2.txt has been eliminated.

I have not debugged it to much, but from a first look to me it is that in the deleteFile function, in particular when eliminating the entry from the entryList here, the entry is not found and thus indexOf will return -1 that causes the elimination of the last element of the array.

Activity

  1. 5saviahv commented on Aug 4, 2024

    @5saviahv
    Collaborator

    Hmm, it seems there is error when deleting folders with multiple levels deep (with sub folder(s) ).

    File is already deleted and searching its location with IndexOf returns -1. Since there is no value check, it will simply delete last entry.

    entryList.splice(entryList.indexOf(entry), 1);

  2. linked a pull request that will close this issuedeleteFile is too eager #525on Aug 4, 2024
  3. matteo-cristino commented on Aug 5, 2024

    @matteo-cristino
    Author

    Thank you very much for the quick fix! 🎉

    Do you know when a new release will be done to have this bug fixed?

  4. 5saviahv commented on Aug 10, 2024

    @5saviahv
    Collaborator

    fix should be in last release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions