Skip to content

Commit

Permalink
fix windows build
Browse files Browse the repository at this point in the history
  • Loading branch information
aawsome committed Jan 11, 2025
1 parent 9aeb808 commit 0d17496
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 26 deletions.
13 changes: 8 additions & 5 deletions crates/core/src/backend/ignore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ fn map_entry(
with_atime: bool,
_ignore_devid: bool,
) -> IgnoreResult<ReadSourceEntry<OpenFile>> {
let name = entry.file_name();
let name = entry.file_name().as_encoded_bytes();
let m = entry
.metadata()
.map_err(|err| IgnoreErrorKind::FailedToGetMetadata { source: err })?;
Expand Down Expand Up @@ -498,10 +498,12 @@ fn map_entry(
Node::new_node(name, NodeType::Dir, meta)
} else if m.is_symlink() {
let path = entry.path();
let target = read_link(path).map_err(|err| IgnoreErrorKind::ErrorLink {
path: path.to_path_buf(),
source: err,
})?;
let target = read_link(path)
.map_err(|err| IgnoreErrorKind::ErrorLink {
path: path.to_path_buf(),
source: err,
})?
.as_encoded_bytes();

Check failure on line 506 in crates/core/src/backend/ignore.rs

View workflow job for this annotation

GitHub Actions / Cross checking x86_64-pc-windows-msvc on stable

no method named `as_encoded_bytes` found for struct `std::path::PathBuf` in the current scope

Check failure on line 506 in crates/core/src/backend/ignore.rs

View workflow job for this annotation

GitHub Actions / Cross checking x86_64-pc-windows-gnu on stable

no method named `as_encoded_bytes` found for struct `std::path::PathBuf` in the current scope
let node_type = NodeType::from_link(&target);
Node::new_node(name, node_type, meta)
} else {
Expand All @@ -510,6 +512,7 @@ fn map_entry(

let path = entry.into_path();
let open = Some(OpenFile(path.clone()));
let path: UnixPathBuf = path.try_into().unwrap(); // TODO: Error handling

Check failure on line 515 in crates/core/src/backend/ignore.rs

View workflow job for this annotation

GitHub Actions / Cross checking x86_64-pc-windows-msvc on stable

cannot find type `UnixPathBuf` in this scope

Check failure on line 515 in crates/core/src/backend/ignore.rs

View workflow job for this annotation

GitHub Actions / Cross checking x86_64-pc-windows-gnu on stable

cannot find type `UnixPathBuf` in this scope
Ok(ReadSourceEntry { path, node, open })
}

Expand Down
7 changes: 6 additions & 1 deletion crates/core/src/backend/local_destination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ pub enum LocalDestinationErrorKind {
filename: PathBuf,
source: std::io::Error,
},
#[cfg(windows)]
/// Non-UTF8 filename is not allowed: `{0:?}`
Utf8Error(std::str::Utf8Error),
}

pub(crate) type LocalDestinationResult<T> = Result<T, LocalDestinationErrorKind>;
Expand Down Expand Up @@ -202,7 +205,9 @@ impl LocalDestination {
}
#[cfg(windows)]
{
let item = PathBuf::try_from(item.as_ref())?;
// only utf8 items are allowed on windows
let item = std::str::from_utf8(item.as_ref().as_bytes())
.map_err(LocalDestinationErrorKind::Utf8Error)?;
Ok(self.path.join(item))
}
}
Expand Down
20 changes: 0 additions & 20 deletions crates/core/src/backend/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,25 +337,6 @@ pub fn last_modified_node(n1: &Node, n2: &Node) -> Ordering {
n1.meta.mtime.cmp(&n2.meta.mtime)
}

// TODO: Should be probably called `_lossy`
// TODO(Windows): This is not able to handle non-unicode filenames and
// doesn't treat filenames which need and escape (like `\`, `"`, ...) correctly
#[cfg(windows)]
fn escape_filename(name: &OsStr) -> String {
name.to_string_lossy().to_string()
}

/// Unescape a filename
///
/// # Arguments
///
/// * `s` - The escaped filename
#[cfg(windows)]
fn unescape_filename(s: &str) -> Result<OsString, core::convert::Infallible> {
OsString::from_str(s)
}

#[cfg(not(windows))]
/// Escape a filename
///
/// # Arguments
Expand Down Expand Up @@ -413,7 +394,6 @@ fn escape_filename(name: &[u8]) -> String {
s
}

#[cfg(not(windows))]
/// Unescape a filename
///
/// # Arguments
Expand Down

0 comments on commit 0d17496

Please sign in to comment.