Skip to content

Commit

Permalink
Fix normalize path
Browse files Browse the repository at this point in the history
  • Loading branch information
j178 committed Oct 29, 2024
1 parent cd836ed commit e4e8a10
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
9 changes: 7 additions & 2 deletions src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,14 @@ pub(crate) async fn run(
install_hooks(&non_skipped, printer).await?;
drop(lock);

let filenames = all_filenames(hook_stage, from_ref, to_ref, all_files, files).await?;
let filenames = all_filenames(hook_stage, from_ref, to_ref, all_files, files)
.await?
.into_iter()
.map(normalize_path)
.collect::<Vec<_>>();

let filenames = filter_filenames(
filenames.par_iter().map(normalize_path),
filenames.par_iter(),
project.config().files.as_deref(),
project.config().exclude.as_deref(),
)?
Expand Down
7 changes: 3 additions & 4 deletions src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

use std::borrow::Cow;
use std::fmt::Display;
use std::path::{Path, PathBuf};
use std::sync::LazyLock;
Expand Down Expand Up @@ -186,22 +185,22 @@ pub fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> std::io::Re
/// Normalizes a path to use `/` as a separator everywhere, even on platforms
/// that recognize other characters as separators.
#[cfg(unix)]
pub(crate) fn normalize_path(path: Cow<'_, [u8]>) -> Cow<'_, [u8]> {
pub(crate) fn normalize_path(path: String) -> String {
// UNIX only uses /, so we're good.
path
}

/// Normalizes a path to use `/` as a separator everywhere, even on platforms
/// that recognize other characters as separators.
#[cfg(not(unix))]
pub(crate) fn normalize_path(mut path: Cow<[u8]>) -> Cow<[u8]> {
pub(crate) fn normalize_path(mut path: String) -> String {
use std::path::is_separator;

for i in 0..path.len() {
if path[i] == b'/' || !is_separator(char::from(path[i])) {
continue;
}
path.to_mut()[i] = b'/';
path[i] = b'/';
}
path
}

0 comments on commit e4e8a10

Please sign in to comment.