Skip to content

Commit 0819ecc

Browse files
authored
archive: avoid creating entries for each directory (libvips#3687)
This is not necessary; the ZIP format maintains a hierarchical structure.
1 parent 1131b7d commit 0819ecc

File tree

1 file changed

+7
-41
lines changed

1 file changed

+7
-41
lines changed

libvips/foreign/archive.c

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -209,44 +209,6 @@ vips__archive_new_to_target(VipsTarget *target,
209209
return archive;
210210
}
211211

212-
static int
213-
vips__archive_mkdir_zip(VipsArchive *archive, const char *dirname)
214-
{
215-
struct archive_entry *entry;
216-
217-
vips__worker_lock(vips_libarchive_mutex);
218-
219-
if (!(entry = archive_entry_new())) {
220-
vips_error("archive", "%s", _("unable to create entry"));
221-
g_mutex_unlock(vips_libarchive_mutex);
222-
return -1;
223-
}
224-
225-
char *path;
226-
227-
path = g_build_filename(archive->base_dirname, dirname, NULL);
228-
229-
archive_entry_set_pathname(entry, path);
230-
archive_entry_set_mode(entry, S_IFDIR | 0755);
231-
232-
if (archive_write_header(archive->archive, entry)) {
233-
char *utf8name = g_filename_display_name(path);
234-
vips_error("archive", _("unable to add directory \"%s\", %s"),
235-
utf8name, archive_error_string(archive->archive));
236-
g_free(utf8name);
237-
g_free(path);
238-
archive_entry_free(entry);
239-
g_mutex_unlock(vips_libarchive_mutex);
240-
return -1;
241-
}
242-
243-
archive_entry_free(entry);
244-
g_free(path);
245-
g_mutex_unlock(vips_libarchive_mutex);
246-
247-
return 0;
248-
}
249-
250212
static int
251213
vips__archive_mkdir_file(VipsArchive *archive, const char *dirname)
252214
{
@@ -277,9 +239,13 @@ vips__archive_mkdir_file(VipsArchive *archive, const char *dirname)
277239
int
278240
vips__archive_mkdir(VipsArchive *archive, const char *dirname)
279241
{
280-
return ((archive->archive)
281-
? vips__archive_mkdir_zip
282-
: vips__archive_mkdir_file)(archive, dirname);
242+
/* The ZIP format maintains a hierarchical structure, avoiding
243+
* the need to create individual entries for each (sub-)directory.
244+
*/
245+
if (archive->archive)
246+
return 0;
247+
248+
return vips__archive_mkdir_file(archive, dirname);
283249
}
284250

285251
static int

0 commit comments

Comments
 (0)