Anki/build/runner/src/paths.rs
Damien Elmes ded805b504
Switch Rust import style (#2330)
* Prepare to switch Rust import style

* Run nightly format

Closes #2320

* Clean up a few imports

* Enable comment wrapping

* Wrap comments
2023-01-18 21:39:55 +10:00

23 lines
769 B
Rust

// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
use camino::Utf8Path;
/// On Unix, just a normal path. On Windows, c:\foo\bar.txt becomes
/// /c/foo/bar.txt, which msys rsync expects.
pub fn absolute_msys_path(path: &Utf8Path) -> String {
let path = path.canonicalize_utf8().unwrap().into_string();
if !cfg!(windows) {
return path;
}
// strip off \\? verbatim prefix, which things like rsync/ninja choke on
let drive = &path.chars().nth(4).unwrap();
// and \ -> /
format!("/{drive}/{}", path[7..].replace('\\', "/"))
}
/// Converts backslashes to forward slashes
pub fn unix_path(path: &Utf8Path) -> String {
path.as_str().replace('\\', "/")
}