diff --git a/libarchive/__init__.py b/libarchive/__init__.py index 8ef3f42..7e4041b 100644 --- a/libarchive/__init__.py +++ b/libarchive/__init__.py @@ -539,6 +539,7 @@ class Archive(object): if data: member.size = len(data) member.to_archive(self) + if data: _libarchive.archive_write_data_from_str(self._a, data) _libarchive.archive_write_finish_entry(self._a) @@ -554,6 +555,7 @@ class Archive(object): 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()) diff --git a/tests.py b/tests.py index 14411a2..5439942 100644 --- a/tests.py +++ b/tests.py @@ -43,12 +43,13 @@ FILENAMES = [ #'álért.txt', ] + def make_temp_files(): - print TMPDIR if not os.path.exists(ZIPPATH): for name in FILENAMES: file(os.path.join(TMPDIR, name), 'w').write(''.join(random.sample(string.printable, 10))) + def make_temp_archive(): if not os.access(ZIPCMD, os.X_OK): raise AssertionError('Cannot execute %s.' % ZIPCMD) @@ -56,7 +57,7 @@ def make_temp_archive(): make_temp_files() cmd.extend(FILENAMES) os.chdir(TMPDIR) - subprocess.call(cmd) + subprocess.call(cmd, stdout=subprocess.PIPE) class TestIsArchiveName(unittest.TestCase): @@ -175,15 +176,18 @@ class TestZipWrite(unittest.TestCase): f = file(ZIPPATH, mode='w') z = ZipFile(f, 'w') - z.writepath('/home/user/testpath', pathname='/testdir', folder=True) + z.writepath(None, pathname='/testdir', folder=True) + z.writepath(None, pathname='/testdir/testinside', folder=True) z.close() f.close() f = file(ZIPPATH, mode='r') z = ZipFile(f, 'r') - assert len(z.entries) == 1 - assert z.entries[0].isdir() + entries = z.infolist() + + assert len(entries) == 2 + assert entries[0].isdir() z.close() f.close()