File tree 2 files changed +49
-0
lines changed
2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change
1
+ //! ```cargo
2
+ //! [dependencies]
3
+ //! ar = "0.6.2"
4
+ //! ```
5
+
6
+ use std:: io:: Read ;
7
+
8
+ // 64 gives Invalid file size field in entry header
9
+ // 32 gives unexpected EOF in the middle of archive entry header
10
+ const METADATA_LEN : usize = 64 ;
11
+
12
+ fn main ( ) {
13
+ let mut builder = ar:: Builder :: new ( std:: fs:: File :: create ( "test.a" ) . expect ( "create" ) ) ;
14
+
15
+ // Remove this append and there is no problem.
16
+ let header = ar:: Header :: new ( b"core-fc675.rcgu.o" . to_vec ( ) , 0 ) ;
17
+ // Remove any of the characters in the filename and ! from will show up in the error message.
18
+ // Making it shorter than 17 chars will fix the problem though.
19
+
20
+ builder. append ( & header, & mut ( & [ ] as & [ u8 ] ) ) . expect ( "add rcgu" ) ;
21
+
22
+ let mut buf: Vec < u8 > = vec ! [ '!' as u8 ; 28 ] ;
23
+ buf. extend ( b"hello worl" ) ;
24
+ buf. extend ( & [ '*' as u8 ; 26 ] as & [ u8 ] ) ;
25
+ assert ! ( buf. len( ) >= METADATA_LEN ) ;
26
+
27
+ let header = ar:: Header :: new ( b"rust.metadata.bin" . to_vec ( ) , METADATA_LEN as u64 ) ;
28
+ builder. append ( & header, & mut ( & buf[ 0 ..METADATA_LEN ] ) ) . expect ( "add meta" ) ;
29
+
30
+ std:: mem:: drop ( builder) ;
31
+
32
+ // Remove this ranlib invocation and there is no problem.
33
+ /*assert!(
34
+ std::process::Command::new("ranlib")
35
+ .arg("test.a")
36
+ .status()
37
+ .expect("Couldn't run ranlib")
38
+ .success()
39
+ );*/
40
+
41
+ let mut archive = ar:: Archive :: new ( std:: fs:: File :: open ( "test.a" ) . expect ( "open" ) ) ;
42
+ while let Some ( entry) = archive. next_entry ( ) {
43
+ entry. unwrap ( ) ;
44
+ }
45
+ }
Original file line number Diff line number Diff line change @@ -75,6 +75,8 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
75
75
}
76
76
77
77
fn add_file ( & mut self , file : & Path ) {
78
+ println ! ( "add_file({})" , file. display( ) ) ;
79
+ std:: fs:: copy ( file, PathBuf :: from ( "./" ) . join ( file. file_name ( ) . unwrap ( ) ) ) . unwrap ( ) ;
78
80
self . builder . append_path ( file) . unwrap ( ) ;
79
81
}
80
82
@@ -126,6 +128,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
126
128
header. set_uid ( orig_header. uid ( ) ) ;
127
129
header. set_gid ( orig_header. gid ( ) ) ;
128
130
header. set_mode ( orig_header. mode ( ) ) ;
131
+ println ! ( "build with src archive" ) ;
129
132
self . builder . append ( & header, entry) . unwrap ( ) ;
130
133
}
131
134
}
@@ -165,6 +168,7 @@ impl<'a> ArArchiveBuilder<'a> {
165
168
header. set_uid ( orig_header. uid ( ) ) ;
166
169
header. set_gid ( orig_header. gid ( ) ) ;
167
170
header. set_mode ( orig_header. mode ( ) ) ;
171
+ println ! ( "add archive" ) ;
168
172
self . builder . append ( & header, entry) . unwrap ( ) ;
169
173
}
170
174
Ok ( ( ) )
You can’t perform that action at this time.
0 commit comments