|
3 | 3 | import warnings |
4 | 4 |
|
5 | 5 | from . import ffi |
6 | | -from .entry import ArchiveEntry, new_archive_entry |
| 6 | +from .entry import ArchiveEntry |
7 | 7 | from .ffi import ( |
8 | 8 | OPEN_CALLBACK, WRITE_CALLBACK, CLOSE_CALLBACK, NO_OPEN_CB, NO_CLOSE_CB, |
9 | 9 | REGULAR_FILE, DEFAULT_UNIX_PERMISSION, ARCHIVE_EOF, |
@@ -53,26 +53,26 @@ def add_files(self, *paths, **kw): |
53 | 53 | if block_size <= 0: |
54 | 54 | block_size = 10240 # pragma: no cover |
55 | 55 |
|
56 | | - with new_archive_entry() as entry_p: |
57 | | - entry = ArchiveEntry(None, entry_p) |
58 | | - for path in paths: |
59 | | - with new_archive_read_disk(path, **kw) as read_p: |
60 | | - while 1: |
61 | | - r = read_next_header2(read_p, entry_p) |
62 | | - if r == ARCHIVE_EOF: |
63 | | - break |
64 | | - entry.pathname = entry.pathname.lstrip('/') |
65 | | - read_disk_descend(read_p) |
66 | | - write_header(write_p, entry_p) |
67 | | - if entry.isreg: |
68 | | - with open(entry_sourcepath(entry_p), 'rb') as f: |
69 | | - while 1: |
70 | | - data = f.read(block_size) |
71 | | - if not data: |
72 | | - break |
73 | | - write_data(write_p, data, len(data)) |
74 | | - write_finish_entry(write_p) |
75 | | - entry_clear(entry_p) |
| 56 | + entry = ArchiveEntry(None) |
| 57 | + entry_p = entry._entry_p |
| 58 | + for path in paths: |
| 59 | + with new_archive_read_disk(path, **kw) as read_p: |
| 60 | + while 1: |
| 61 | + r = read_next_header2(read_p, entry_p) |
| 62 | + if r == ARCHIVE_EOF: |
| 63 | + break |
| 64 | + entry.pathname = entry.pathname.lstrip('/') |
| 65 | + read_disk_descend(read_p) |
| 66 | + write_header(write_p, entry_p) |
| 67 | + if entry.isreg: |
| 68 | + with open(entry_sourcepath(entry_p), 'rb') as f: |
| 69 | + while 1: |
| 70 | + data = f.read(block_size) |
| 71 | + if not data: |
| 72 | + break |
| 73 | + write_data(write_p, data, len(data)) |
| 74 | + write_finish_entry(write_p) |
| 75 | + entry_clear(entry_p) |
76 | 76 |
|
77 | 77 | def add_file_from_memory( |
78 | 78 | self, entry_path, entry_size, entry_data, |
@@ -110,39 +110,38 @@ def add_file_from_memory( |
110 | 110 | "entry_data: expected bytes, got %r" % type(entry_data) |
111 | 111 | ) |
112 | 112 |
|
113 | | - with new_archive_entry() as archive_entry_pointer: |
114 | | - archive_entry = ArchiveEntry(None, archive_entry_pointer) |
115 | | - |
116 | | - archive_entry.pathname = entry_path |
117 | | - entry_set_size(archive_entry_pointer, entry_size) |
118 | | - entry_set_filetype(archive_entry_pointer, filetype) |
119 | | - entry_set_perm(archive_entry_pointer, permission) |
120 | | - |
121 | | - if atime is not None: |
122 | | - if not isinstance(atime, tuple): |
123 | | - atime = (atime, 0) |
124 | | - archive_entry.set_atime(*atime) |
125 | | - if mtime is not None: |
126 | | - if not isinstance(mtime, tuple): |
127 | | - mtime = (mtime, 0) |
128 | | - archive_entry.set_mtime(*mtime) |
129 | | - if ctime is not None: |
130 | | - if not isinstance(ctime, tuple): |
131 | | - ctime = (ctime, 0) |
132 | | - archive_entry.set_ctime(*ctime) |
133 | | - if birthtime is not None: |
134 | | - if not isinstance(birthtime, tuple): |
135 | | - birthtime = (birthtime, 0) |
136 | | - archive_entry.set_birthtime(*birthtime) |
137 | | - write_header(archive_pointer, archive_entry_pointer) |
138 | | - |
139 | | - for chunk in entry_data: |
140 | | - if not chunk: |
141 | | - break |
142 | | - write_data(archive_pointer, chunk, len(chunk)) |
143 | | - |
144 | | - write_finish_entry(archive_pointer) |
145 | | - entry_clear(archive_entry_pointer) |
| 113 | + archive_entry = ArchiveEntry(None) |
| 114 | + archive_entry_pointer = archive_entry._entry_p |
| 115 | + |
| 116 | + archive_entry.pathname = entry_path |
| 117 | + entry_set_size(archive_entry_pointer, entry_size) |
| 118 | + entry_set_filetype(archive_entry_pointer, filetype) |
| 119 | + entry_set_perm(archive_entry_pointer, permission) |
| 120 | + |
| 121 | + if atime is not None: |
| 122 | + if not isinstance(atime, tuple): |
| 123 | + atime = (atime, 0) |
| 124 | + archive_entry.set_atime(*atime) |
| 125 | + if mtime is not None: |
| 126 | + if not isinstance(mtime, tuple): |
| 127 | + mtime = (mtime, 0) |
| 128 | + archive_entry.set_mtime(*mtime) |
| 129 | + if ctime is not None: |
| 130 | + if not isinstance(ctime, tuple): |
| 131 | + ctime = (ctime, 0) |
| 132 | + archive_entry.set_ctime(*ctime) |
| 133 | + if birthtime is not None: |
| 134 | + if not isinstance(birthtime, tuple): |
| 135 | + birthtime = (birthtime, 0) |
| 136 | + archive_entry.set_birthtime(*birthtime) |
| 137 | + write_header(archive_pointer, archive_entry_pointer) |
| 138 | + |
| 139 | + for chunk in entry_data: |
| 140 | + if not chunk: |
| 141 | + break |
| 142 | + write_data(archive_pointer, chunk, len(chunk)) |
| 143 | + |
| 144 | + write_finish_entry(archive_pointer) |
146 | 145 |
|
147 | 146 |
|
148 | 147 | @contextmanager |
|
0 commit comments