Showing the changes to git-path/src (1 of 4 files). Show all
Unified · Split
| @@ -1,4 +1,4 @@ | |||
| 1 | #![forbid(unsafe_code, rust_2018_idioms)] | 1 | #![forbid(unsafe_code, rust_2018_idioms, missing_docs)] |
| 2 | //! This crate contains an assortment of utilities to deal with paths and their conversions. | 2 | //! This crate contains an assortment of utilities to deal with paths and their conversions. |
| 3 | //! | 3 | //! |
| 4 | //! Generally `git` treats paths as bytes, but inherently assumes non-illformed UTF-8 as encoding on windows. Internally, it expects | 4 | //! Generally `git` treats paths as bytes, but inherently assumes non-illformed UTF-8 as encoding on windows. Internally, it expects |
| @@ -55,56 +55,10 @@ · 50 unmodified lines | |||
| 55 | pub struct Spec(bstr::BString); | 55 | pub struct Spec(bstr::BString); |
| 56 | 56 | ||
| 57 | mod convert; | 57 | mod convert; |
| 58 | mod spec; | ||
| 59 | |||
| 60 | use std::{fs::create_dir_all, ops::Deref, path::Path}; | ||
| 61 | |||
| 62 | pub use convert::*; | 58 | pub use convert::*; |
| 63 | use tempfile::tempdir_in; | 59 | |
| 60 | mod spec; | ||
| 64 | 61 | ||
| 65 | /// | 62 | /// |
| 66 | pub mod realpath; | 63 | pub mod realpath; |
| 67 | pub use realpath::function::{realpath, realpath_opts}; | 64 | pub use realpath::function::{realpath, realpath_opts}; |
| 68 | |||
| 69 | pub fn create_symlink(from: &Path, to: &Path) { | ||
| 70 | create_dir_all(from.parent().unwrap()).unwrap(); | ||
| 71 | #[cfg(not(target_os = "windows"))] | ||
| 72 | std::os::unix::fs::symlink(to, &from).unwrap(); | ||
| 73 | #[cfg(target_os = "windows")] | ||
| 74 | std::os::windows::fs::symlink_file(to, &from).unwrap(); | ||
| 75 | } | ||
| 76 | |||
| 77 | pub struct CanonicalizedTempDir { | ||
| 78 | pub dir: tempfile::TempDir, | ||
| 79 | } | ||
| 80 | |||
| 81 | impl CanonicalizedTempDir { | ||
| 82 | pub fn new() -> Self { | ||
| 83 | #[cfg(windows)] | ||
| 84 | let canonicalized_tempdir = std::env::temp_dir(); | ||
| 85 | #[cfg(not(windows))] | ||
| 86 | let canonicalized_tempdir = std::env::temp_dir().canonicalize().unwrap(); | ||
| 87 | let dir = tempdir_in(canonicalized_tempdir).unwrap(); | ||
| 88 | Self { dir } | ||
| 89 | } | ||
| 90 | } | ||
| 91 | |||
| 92 | impl Default for CanonicalizedTempDir { | ||
| 93 | fn default() -> Self { | ||
| 94 | Self::new() | ||
| 95 | } | ||
| 96 | } | ||
| 97 | |||
| 98 | impl AsRef<Path> for CanonicalizedTempDir { | ||
| 99 | fn as_ref(&self) -> &Path { | ||
| 100 | self | ||
| 101 | } | ||
| 102 | } | ||
| 103 | |||
| 104 | impl Deref for CanonicalizedTempDir { | ||
| 105 | type Target = Path; | ||
| 106 | |||
| 107 | fn deref(&self) -> &Self::Target { | ||
| 108 | self.dir.path() | ||
| 109 | } | ||
| 110 | } | ||