From eeb95116ccd716ba0104c1c52851042afb9efeb8 Mon Sep 17 00:00:00 2001 From: Ryan Johnston Date: Mon, 4 May 2015 16:40:31 -0400 Subject: [PATCH] Add option to set mode to folder. Add option to set mode to folder. --- libarchive/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libarchive/__init__.py b/libarchive/__init__.py index cee6798..8ef3f42 100644 --- a/libarchive/__init__.py +++ b/libarchive/__init__.py @@ -543,7 +543,7 @@ class Archive(object): _libarchive.archive_write_data_from_str(self._a, data) _libarchive.archive_write_finish_entry(self._a) - def writepath(self, f, pathname=None): + def writepath(self, f, pathname=None, folder=False): '''Writes a file to the archive. f can be a file-like object or a path. Uses write() to do the actual writing.''' member = self.entry_class.from_file(f, encoding=self.encoding) @@ -552,6 +552,8 @@ class Archive(object): f = file(f, 'r') if pathname: member.pathname = pathname + if folder and not member.isdir(): + member.mode = stat.S_IFDIR if hasattr(f, 'read'): # TODO: optimize this to write directly from f to archive. self.write(member, data=f.read())