From 327a585eac5bad31c95ceb61c3102cb00e638cee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Kn=C3=BCttel?= Date: Wed, 13 Mar 2019 14:01:50 +0100 Subject: [PATCH] added bunker.files.tarfile.RewriteableTarFile.has_file --- bunker/files/tarfile.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/bunker/files/tarfile.py b/bunker/files/tarfile.py index ffa5d36..5afdd71 100644 --- a/bunker/files/tarfile.py +++ b/bunker/files/tarfile.py @@ -98,3 +98,16 @@ class RewriteableTarFile(object): new_handle.addfile(member, handle.extractfile(member)) new_handle.close() + def has_file(self, member): + if(isinstance(member, tarfile.TarInfo)): + member_name = member.name + elif(isinstance(member, str)): + member_name = member + else: + raise TypeError("member must be TarInfo or str, not {}".format(type(member))) + + handle = self._open_handle() + + return member_name in handle.getnames() + +