From f38459c730075cbdcd0f5adcdc45c534a9ea15e2 Mon Sep 17 00:00:00 2001 From: Vadim Lebedev Date: Thu, 21 Jul 2022 18:30:03 +0200 Subject: [PATCH] Fix archive element closing --- libarchive/__init__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libarchive/__init__.py b/libarchive/__init__.py index 9df1921..c546db9 100644 --- a/libarchive/__init__.py +++ b/libarchive/__init__.py @@ -544,9 +544,11 @@ class Archive(object): if getattr(self.f, 'closed', False): return # Flush it if not read-only... - if self.f.mode != 'r' and self.f.mode != 'rb': - self.f.flush() - os.fsync(self.f.fileno()) + if hasattr(self.f, "mode") and self.f.mode != 'r' and self.f.mode != 'rb': + if hasattr(self.f, "flush"): + self.f.flush() + if hasattr(self.f, "fileno"): + os.fsync(self.f.fileno()) # and then close it, if we opened it... if getattr(self, '_close', None): self.f.close()