Skip to content

Commit

Permalink
clean up the code of add_file_from_memory
Browse files Browse the repository at this point in the history
  • Loading branch information
Changaco committed Oct 20, 2019
1 parent 2c86cc2 commit 2bc6ab0
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions libarchive/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,8 @@ def add_files(self, *paths, **kw):

def add_file_from_memory(
self, entry_path, entry_size, entry_data,
filetype=REGULAR_FILE,
permission=DEFAULT_UNIX_PERMISSION,
atime=None,
mtime=None,
ctime=None,
birthtime=None,
filetype=REGULAR_FILE, permission=DEFAULT_UNIX_PERMISSION,
atime=None, mtime=None, ctime=None, birthtime=None,
):
""""Add file from memory to archive.
Expand Down Expand Up @@ -124,21 +120,21 @@ def add_file_from_memory(
entry_set_perm(archive_entry_pointer, permission)

if atime is not None:
archive_entry.set_atime(*(
(atime, 0)
if isinstance(atime, (int, float)) else atime))
if isinstance(atime, (int, float)):
atime = (atime, 0)
archive_entry.set_atime(*atime)
if mtime is not None:
archive_entry.set_mtime(*(
(mtime, 0)
if isinstance(mtime, (int, float)) else mtime))
if isinstance(mtime, (int, float)):
mtime = (mtime, 0)
archive_entry.set_mtime(*mtime)
if ctime is not None:
archive_entry.set_ctime(*(
(ctime, 0)
if isinstance(ctime, (int, float)) else ctime))
if isinstance(ctime, (int, float)):
ctime = (ctime, 0)
archive_entry.set_ctime(*ctime)
if birthtime is not None:
archive_entry.set_birthtime(*(
(birthtime, 0)
if isinstance(birthtime, (int, float)) else birthtime))
if isinstance(birthtime, (int, float)):
birthtime = (birthtime, 0)
archive_entry.set_birthtime(*birthtime)
write_header(archive_pointer, archive_entry_pointer)

for chunk in entry_data:
Expand Down

0 comments on commit 2bc6ab0

Please sign in to comment.