Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deleteFile erase more files than expected #523

Closed
matteo-cristino opened this issue Aug 1, 2024 · 3 comments · Fixed by #525
Closed

deleteFile erase more files than expected #523

matteo-cristino opened this issue Aug 1, 2024 · 3 comments · Fixed by #525
Labels

Comments

@matteo-cristino
Copy link

matteo-cristino commented Aug 1, 2024

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.

@5saviahv
Copy link
Collaborator

5saviahv commented Aug 4, 2024

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);

@5saviahv 5saviahv linked a pull request Aug 4, 2024 that will close this issue
@matteo-cristino
Copy link
Author

Thank you very much for the quick fix! 🎉

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

@5saviahv
Copy link
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
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants