@@ -166,25 +166,26 @@ fn append_zip_entry<W: std::io::Write + std::io::Seek>(
166166 compression_level : Option < i64 > ,
167167 tree_prefix : Option < & bstr:: BString > ,
168168) -> Result < ( ) , Error > {
169+ use bstr:: ByteSlice ;
169170 let path = add_prefix ( entry. relative_path ( ) , tree_prefix) . into_owned ( ) ;
170171 let unix_permissions = if entry. mode . is_executable ( ) { 0o755 } else { 0o644 } ;
171-
172+ let path = path. to_str ( ) . map_err ( |_| {
173+ Error :: Io ( std:: io:: Error :: new (
174+ std:: io:: ErrorKind :: InvalidData ,
175+ "Invalid UTF-8 in entry path" ,
176+ ) )
177+ } ) ?;
178+
172179 match entry. mode . kind ( ) {
173180 gix_object:: tree:: EntryKind :: Blob | gix_object:: tree:: EntryKind :: BlobExecutable => {
174- use bstr:: ByteSlice ;
175181 let file_builder = ar
176- . new_file ( path. to_str ( ) . map_err ( |_| {
177- Error :: Io ( std:: io:: Error :: new (
178- std:: io:: ErrorKind :: InvalidData ,
179- "Invalid UTF-8 in file path" ,
180- ) )
181- } ) ?)
182+ . new_file ( path)
182183 . compression_method ( rawzip:: CompressionMethod :: Deflate )
183184 . last_modified ( mtime)
184185 . unix_permissions ( unix_permissions) ;
185-
186+
186187 let ( mut zip_entry, config) = file_builder. start ( ) . map_err ( std:: io:: Error :: other) ?;
187-
188+
188189 // Use flate2 for compression. Level 9 is the maximum compression level for deflate.
189190 let encoder = flate2:: write:: DeflateEncoder :: new (
190191 & mut zip_entry,
@@ -200,50 +201,38 @@ fn append_zip_entry<W: std::io::Write + std::io::Seek>(
200201 zip_entry. finish ( descriptor) . map_err ( std:: io:: Error :: other) ?;
201202 }
202203 gix_object:: tree:: EntryKind :: Tree | gix_object:: tree:: EntryKind :: Commit => {
203- use bstr:: ByteSlice ;
204204 // rawzip requires directory paths to end with '/'
205- let mut dir_path = path. to_str ( ) . map_err ( |_| {
206- Error :: Io ( std:: io:: Error :: new (
207- std:: io:: ErrorKind :: InvalidData ,
208- "Invalid UTF-8 in directory path" ,
209- ) )
210- } ) ?. to_string ( ) ;
205+ let mut dir_path = path. to_owned ( ) ;
211206 if !dir_path. ends_with ( '/' ) {
212207 dir_path. push ( '/' ) ;
213208 }
214209 ar. new_dir ( & dir_path)
215- . last_modified ( mtime)
216- . unix_permissions ( unix_permissions)
217- . create ( )
218- . map_err ( std:: io:: Error :: other) ?;
210+ . last_modified ( mtime)
211+ . unix_permissions ( unix_permissions)
212+ . create ( )
213+ . map_err ( std:: io:: Error :: other) ?;
219214 }
220215 gix_object:: tree:: EntryKind :: Link => {
221- use bstr:: ByteSlice ;
222216 buf. clear ( ) ;
223217 std:: io:: copy ( & mut entry, buf) ?;
224-
218+
225219 // For symlinks, we need to create a file with symlink permissions
226- let symlink_path = path. to_str ( ) . map_err ( |_| {
227- Error :: Io ( std:: io:: Error :: new (
228- std:: io:: ErrorKind :: InvalidData ,
229- "Invalid UTF-8 in symlink path" ,
230- ) )
231- } ) ?;
220+ let symlink_path = path;
232221 let target = buf. as_bstr ( ) . to_str ( ) . map_err ( |_| {
233222 Error :: Io ( std:: io:: Error :: new (
234223 std:: io:: ErrorKind :: InvalidData ,
235224 "Invalid UTF-8 in symlink target" ,
236225 ) )
237226 } ) ?;
238-
227+
239228 let ( mut zip_entry, config) = ar
240229 . new_file ( symlink_path)
241230 . compression_method ( rawzip:: CompressionMethod :: Store )
242231 . last_modified ( mtime)
243232 . unix_permissions ( 0o120644 ) // Symlink mode
244233 . start ( )
245234 . map_err ( std:: io:: Error :: other) ?;
246-
235+
247236 let mut writer = config. wrap ( & mut zip_entry) ;
248237 writer. write_all ( target. as_bytes ( ) ) ?;
249238 let ( _, descriptor) = writer. finish ( ) . map_err ( std:: io:: Error :: other) ?;
0 commit comments