Skip to content

Commit 8f429a3

Browse files
committed
undo changes to packaging/metadata
1 parent 36ac234 commit 8f429a3

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

src/packaging/metadata.rs

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Functions to write and create metadata from a given output
22
3+
#[cfg(target_family = "unix")]
4+
use std::os::unix::prelude::OsStrExt;
35
use std::{
46
borrow::Cow,
57
collections::HashSet,
@@ -25,22 +27,33 @@ use super::{PackagingError, TempFiles};
2527
use crate::{hash::HashInput, metadata::Output, recipe::parser::PrefixDetection};
2628

2729
/// Detect if the file contains the prefix in binary mode.
30+
#[allow(unused_variables)]
2831
pub fn contains_prefix_binary(file_path: &Path, prefix: &Path) -> Result<bool, PackagingError> {
2932
// 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+
}
3139

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();
3443

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)?;
3746

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();
4254

43-
Ok(contains_prefix)
55+
Ok(contains_prefix)
56+
}
4457
}
4558

4659
/// This function requires we know the file content we are matching against is
@@ -158,6 +171,14 @@ pub fn create_prefix_placeholder(
158171
return Ok(None);
159172
}
160173

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+
161182
if contains_prefix_binary(file_path, encoded_prefix)? {
162183
has_prefix = Some(encoded_prefix.to_string_lossy().to_string());
163184
}

0 commit comments

Comments
 (0)