diff --git a/crates/core/src/backend/ignore.rs b/crates/core/src/backend/ignore.rs index 08e29f84..71c25ab2 100644 --- a/crates/core/src/backend/ignore.rs +++ b/crates/core/src/backend/ignore.rs @@ -444,7 +444,7 @@ fn map_entry( with_atime: bool, _ignore_devid: bool, ) -> IgnoreResult> { - let name = entry.file_name(); + let name = entry.file_name().as_encoded_bytes(); let m = entry .metadata() .map_err(|err| IgnoreErrorKind::FailedToGetMetadata { source: err })?; @@ -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(); let node_type = NodeType::from_link(&target); Node::new_node(name, node_type, meta) } else { @@ -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 Ok(ReadSourceEntry { path, node, open }) } diff --git a/crates/core/src/backend/local_destination.rs b/crates/core/src/backend/local_destination.rs index 027c712a..28dd64db 100644 --- a/crates/core/src/backend/local_destination.rs +++ b/crates/core/src/backend/local_destination.rs @@ -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 = Result; @@ -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)) } } diff --git a/crates/core/src/backend/node.rs b/crates/core/src/backend/node.rs index 0c211c33..71e1debc 100644 --- a/crates/core/src/backend/node.rs +++ b/crates/core/src/backend/node.rs @@ -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::from_str(s) -} - -#[cfg(not(windows))] /// Escape a filename /// /// # Arguments @@ -413,7 +394,6 @@ fn escape_filename(name: &[u8]) -> String { s } -#[cfg(not(windows))] /// Unescape a filename /// /// # Arguments