1
1
//! Functions to write and create metadata from a given output
2
2
3
+ #[ cfg( target_family = "unix" ) ]
4
+ use std:: os:: unix:: prelude:: OsStrExt ;
3
5
use std:: {
4
6
borrow:: Cow ,
5
7
collections:: HashSet ,
@@ -25,22 +27,33 @@ use super::{PackagingError, TempFiles};
25
27
use crate :: { hash:: HashInput , metadata:: Output , recipe:: parser:: PrefixDetection } ;
26
28
27
29
/// Detect if the file contains the prefix in binary mode.
30
+ #[ allow( unused_variables) ]
28
31
pub fn contains_prefix_binary ( file_path : & Path , prefix : & Path ) -> Result < bool , PackagingError > {
29
32
// Convert the prefix to a Vec<u8> for binary comparison
30
- let prefix_bytes = prefix. to_string_lossy ( ) . as_bytes ( ) . to_vec ( ) ;
33
+ // TODO on Windows check both ascii and utf-8 / 16?
34
+ #[ cfg( target_family = "windows" ) ]
35
+ {
36
+ tracing:: warn!( "Windows is not supported yet for binary prefix checking." ) ;
37
+ Ok ( false )
38
+ }
31
39
32
- // Open the file
33
- let file = File :: open ( file_path) ?;
40
+ #[ cfg( target_family = "unix" ) ]
41
+ {
42
+ let prefix_bytes = prefix. as_os_str ( ) . as_bytes ( ) . to_vec ( ) ;
34
43
35
- // Read the file's content
36
- let data = unsafe { memmap2 :: Mmap :: map ( & file ) } ?;
44
+ // Open the file
45
+ let file = File :: open ( file_path ) ?;
37
46
38
- // Check if the content contains the prefix bytes with memchr
39
- let contains_prefix = memchr:: memmem:: find_iter ( data. as_ref ( ) , & prefix_bytes)
40
- . next ( )
41
- . is_some ( ) ;
47
+ // Read the file's content
48
+ let data = unsafe { memmap2:: Mmap :: map ( & file) } ?;
49
+
50
+ // Check if the content contains the prefix bytes with memchr
51
+ let contains_prefix = memchr:: memmem:: find_iter ( data. as_ref ( ) , & prefix_bytes)
52
+ . next ( )
53
+ . is_some ( ) ;
42
54
43
- Ok ( contains_prefix)
55
+ Ok ( contains_prefix)
56
+ }
44
57
}
45
58
46
59
/// This function requires we know the file content we are matching against is
@@ -158,6 +171,14 @@ pub fn create_prefix_placeholder(
158
171
return Ok ( None ) ;
159
172
}
160
173
174
+ if target_platform. is_windows ( ) {
175
+ tracing:: debug!(
176
+ "Binary prefix replacement is not performed fors Windows: {:?}" ,
177
+ relative_path
178
+ ) ;
179
+ return Ok ( None ) ;
180
+ }
181
+
161
182
if contains_prefix_binary ( file_path, encoded_prefix) ? {
162
183
has_prefix = Some ( encoded_prefix. to_string_lossy ( ) . to_string ( ) ) ;
163
184
}
0 commit comments