Browse Source

is_archive: Avoid closing a file not opened by is_archive

test_fixup
Vadim Lebedev 2 years ago
parent
commit
855dc86d1d
1 changed files with 4 additions and 1 deletions
  1. +4
    -1
      libarchive/__init__.py

+ 4
- 1
libarchive/__init__.py View File

@@ -158,8 +158,10 @@ def is_archive(f, formats=(None, ), filters=(None, )):

This function will return True if the file can be opened as an archive using the given
format(s)/filter(s).'''
need_close : bool = False
if isinstance(f, str):
f = open(f, 'r')
need_close = True
a = _libarchive.archive_read_new()
for format in formats:
format = get_func(format, FORMATS, 0)
@@ -180,7 +182,8 @@ def is_archive(f, formats=(None, ), filters=(None, )):
finally:
_libarchive.archive_read_close(a)
_libarchive.archive_read_free(a)
f.close()
if need_close:
f.close()


class EntryReadStream(object):


Loading…
Cancel
Save