Browse Source

Fix archive element closing

test_fixup
Vadim Lebedev 2 years ago
parent
commit
f38459c730
1 changed files with 5 additions and 3 deletions
  1. +5
    -3
      libarchive/__init__.py

+ 5
- 3
libarchive/__init__.py View File

@@ -544,9 +544,11 @@ class Archive(object):
if getattr(self.f, 'closed', False): if getattr(self.f, 'closed', False):
return return
# Flush it if not read-only... # 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... # and then close it, if we opened it...
if getattr(self, '_close', None): if getattr(self, '_close', None):
self.f.close() self.f.close()


Loading…
Cancel
Save