11use log:: { Level , LevelFilter , Log , Metadata , Record , debug, error, warn} ;
22use owo_colors:: { OwoColorize , Style } ;
3+ #[ cfg( unix) ]
34use std:: os:: unix:: fs:: PermissionsExt ;
45use std:: sync:: mpsc;
56use std:: {
@@ -16,6 +17,7 @@ struct Job {
1617 path : PathBuf ,
1718 old_content : Option < Vec < u8 > > ,
1819 new_content : Vec < u8 > ,
20+ #[ cfg( unix) ]
1921 executable : bool ,
2022}
2123
@@ -26,15 +28,31 @@ impl Job {
2628 if & self . new_content != old {
2729 return false ;
2830 }
29- // Check if executable bit would change
30- let current_executable = self
31- . path
32- . metadata ( )
33- . map ( |m| m. permissions ( ) . mode ( ) & 0o111 != 0 )
34- . unwrap_or ( false ) ;
35- current_executable == self . executable
31+ #[ cfg( unix) ]
32+ {
33+ // Check if executable bit would change
34+ let current_executable = self
35+ . path
36+ . metadata ( )
37+ . map ( |m| m. permissions ( ) . mode ( ) & 0o111 != 0 )
38+ . unwrap_or ( false ) ;
39+ current_executable == self . executable
40+ }
41+ #[ cfg( not( unix) ) ]
42+ {
43+ true
44+ }
45+ }
46+ None => {
47+ #[ cfg( unix) ]
48+ {
49+ self . new_content . is_empty ( ) && !self . executable
50+ }
51+ #[ cfg( not( unix) ) ]
52+ {
53+ self . new_content . is_empty ( )
54+ }
3655 }
37- None => self . new_content . is_empty ( ) && !self . executable ,
3856 }
3957 }
4058
@@ -51,6 +69,7 @@ impl Job {
5169 fs:: write ( & self . path , & self . new_content ) ?;
5270
5371 // Set executable bit if needed
72+ #[ cfg( unix) ]
5473 if self . executable {
5574 let mut perms = fs:: metadata ( & self . path ) ?. permissions ( ) ;
5675 perms. set_mode ( perms. mode ( ) | 0o111 ) ;
@@ -103,6 +122,7 @@ fn enqueue_readme_jobs(sender: std::sync::mpsc::Sender<Job>) {
103122 path : readme_path,
104123 old_content,
105124 new_content : readme_content. into_bytes ( ) ,
125+ #[ cfg( unix) ]
106126 executable : false ,
107127 } ;
108128
@@ -283,6 +303,7 @@ fn enqueue_rustfmt_jobs(sender: std::sync::mpsc::Sender<Job>, staged_files: &Sta
283303 path : path. clone ( ) ,
284304 old_content : Some ( original) ,
285305 new_content : formatted,
306+ #[ cfg( unix) ]
286307 executable : false ,
287308 } ;
288309 if let Err ( e) = sender. send ( job) {
@@ -312,6 +333,7 @@ fn enqueue_github_workflow_jobs(sender: std::sync::mpsc::Sender<Job>) {
312333 path : workflow_path. to_path_buf ( ) ,
313334 old_content,
314335 new_content,
336+ #[ cfg( unix) ]
315337 executable : false ,
316338 } ;
317339 if let Err ( e) = sender. send ( job) {
@@ -330,6 +352,7 @@ fn enqueue_github_funding_jobs(sender: std::sync::mpsc::Sender<Job>) {
330352 path : funding_path. to_path_buf ( ) ,
331353 old_content,
332354 new_content,
355+ #[ cfg( unix) ]
333356 executable : false ,
334357 } ;
335358 if let Err ( e) = sender. send ( job) {
@@ -373,6 +396,7 @@ fn enqueue_cargo_husky_precommit_hook_jobs(sender: std::sync::mpsc::Sender<Job>)
373396 path : hook_path. to_path_buf ( ) ,
374397 old_content,
375398 new_content,
399+ #[ cfg( unix) ]
376400 executable : true ,
377401 } ;
378402 if let Err ( e) = sender. send ( job) {
0 commit comments