kuba--/zip

Issue when deleting files

Closed this issue · 3 comments

Hi,

I am getting an issue when I try to delete entries in my zip.
I am using the following code :

				zip_t* zip = zip_open(it.first.c_str(), 0, 'r');
				for (int i = 0; i < zip_entries_total(zip); i++)
				{
					if (zip_entry_openbyindex(zip, i) == 0)
					{
						std::string filename = zip_entry_name(zip);
						if (it.second.count(filename) > 0)
						{
							indexes.push_back(zip_entry_index(zip));
						}
					}
					zip_entry_close(zip);
				}
				zip_close(zip);
				zip = zip_open(it.first.c_str(), 0, 'd');
				zip_entries_deletebyindex(zip, &indexes[0], indexes.size());
				zip_close(zip);
				

By debugging, I see that my list if full of indexes. But after execution and zip closing. The size of the zip doesn't change and files that should be get deleted are not.

Am I doing something wrong ?

kuba-- commented

What is indexes? Is it a std::vector of size_t?
If yes, have you tried passing indexes.data() instead of &indexes[0]?

I forget to copy the line, but yes it's a size_t vector.

Seems with .data() it's working.
Thanks for your help !

kuba-- commented

I forget to copy the line, but yes it's a size_t vector.

Seems with .data() it's working. Thanks for your help !

Yeah, you need to pass a pointer to size_t elements, no to the vector's container. Anyway, if data() is workable for then great.