@@ -86,13 +86,12 @@ fn main() {
86
86
dylint_dst_file. display( )
87
87
) ;
88
88
89
- let zipped_lints = match zip_file (
90
- & out_dir
91
- . join ( "release" )
92
- . join ( "libink_lints@nightly-2021-11-04-x86_64-unknown-linux-gnu.so" ) ,
93
- & dylint_dst_file,
94
- CompressionMethod :: Stored ,
95
- ) {
89
+ //#[cfg(not(target_os = "windows"))]
90
+ let p = & out_dir. join ( "release" ) ;
91
+ //.join("libink_lints@nightly-2021-11-04-x86_64-unknown-linux-gnu.so");
92
+ //#[cfg(target_os = "windows")]
93
+ //let p = &out_dir.join("release").join("libink_lints@nightly-2021-11-04-x86_64-unknown-linux-gnu.so");
94
+ let zipped_lints = match zip_lint_driver ( p, & dylint_dst_file, CompressionMethod :: Stored ) {
96
95
Ok ( _) => {
97
96
println ! (
98
97
"done: {} written to {}" ,
@@ -203,6 +202,61 @@ fn zip_file(src_file: &Path, dst_file: &Path, method: CompressionMethod) -> Resu
203
202
Ok ( ( ) )
204
203
}
205
204
205
+ fn zip_lint_driver ( src_dir : & Path , dst_file : & Path , method : CompressionMethod ) -> Result < ( ) > {
206
+ if !src_dir. exists ( ) {
207
+ anyhow:: bail!( "src_dir '{}' does not exist" , src_dir. display( ) ) ;
208
+ }
209
+ if !src_dir. is_dir ( ) {
210
+ anyhow:: bail!( "src_dir '{}' is not a directory" , src_dir. display( ) ) ;
211
+ }
212
+
213
+ let file = File :: create ( dst_file) ?;
214
+
215
+ let mut zip = ZipWriter :: new ( file) ;
216
+ let options = FileOptions :: default ( )
217
+ . compression_method ( method)
218
+ . unix_permissions ( DEFAULT_UNIX_PERMISSIONS ) ;
219
+
220
+ let mut buffer = Vec :: new ( ) ;
221
+ //let path = src_dir;
222
+ //println!("\npath: {:?}", path);
223
+
224
+ //println!("{}", path.display());
225
+
226
+ let walkdir = WalkDir :: new ( src_dir) ;
227
+ let it = walkdir. into_iter ( ) . filter_map ( |e| e. ok ( ) ) ;
228
+
229
+ //let mut file_path: Option<Path> = None;
230
+ for entry in it {
231
+ let path = entry. path ( ) ;
232
+ let mut name = path. strip_prefix ( & src_dir) ?. to_path_buf ( ) ;
233
+
234
+ let file_path = name. as_os_str ( ) . to_string_lossy ( ) ;
235
+
236
+ if path. is_file ( ) && path. display ( ) . to_string ( ) . contains ( "libink_lints@" ) {
237
+ println ! ( "\n zip_lint {:?}" , path) ;
238
+ //let tmp = name.as_os_str();
239
+ //let f_path = format!("{}", tmp.to_string_lossy()).to_string();
240
+ //file_path = Some(path.);
241
+ //let file_path = file_path.expect("file path must exist");
242
+ //let file_path = path.file_name().expect("failed").to_string_lossy();
243
+
244
+ //zip.start_file(dst_file.as_os_str().to_string_lossy(), options)?;
245
+ zip. start_file ( file_path, options) ?;
246
+ let mut f = File :: open ( path) ?;
247
+
248
+ f. read_to_end ( & mut buffer) ?;
249
+ zip. write_all ( & * buffer) ?;
250
+ buffer. clear ( ) ;
251
+
252
+ zip. finish ( ) ?;
253
+ println ! ( "dst: {:?}" , dst_file) ;
254
+ break ;
255
+ }
256
+ }
257
+ Ok ( ( ) )
258
+ }
259
+
206
260
/// Generate the `cargo:` key output
207
261
fn generate_cargo_keys ( ) {
208
262
let output = Command :: new ( "git" )
0 commit comments