-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add warnings for migrations with prints
- Loading branch information
1 parent
5c27bae
commit c1f9d91
Showing
7 changed files
with
111 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use std::path::{Path, PathBuf}; | ||
|
||
use anyhow::{anyhow, Context, Result}; | ||
use camino::Utf8PathBuf; | ||
|
||
/// Equivalent to [`fs::canonicalize`] with better error messages. | ||
/// | ||
/// Uses [`dunce`] to generate more familiar paths on Windows. | ||
pub fn canonicalize(p: impl AsRef<Path>) -> Result<PathBuf> { | ||
return inner(p.as_ref()); | ||
|
||
fn inner(p: &Path) -> Result<PathBuf> { | ||
dunce::canonicalize(p) | ||
.with_context(|| format!("failed to get absolute path of `{}`", p.display())) | ||
} | ||
} | ||
|
||
/// Equivalent to [`fs::canonicalize`], but for Utf-8 paths, with better error messages. | ||
pub fn canonicalize_utf8(p: impl AsRef<Path>) -> Result<Utf8PathBuf> { | ||
canonicalize(p)?.try_into_utf8() | ||
} | ||
|
||
pub trait PathBufUtf8Ext { | ||
fn try_into_utf8(self) -> Result<Utf8PathBuf>; | ||
} | ||
|
||
impl PathBufUtf8Ext for PathBuf { | ||
fn try_into_utf8(self) -> Result<Utf8PathBuf> { | ||
Utf8PathBuf::from_path_buf(self) | ||
.map_err(|path| anyhow!("path `{}` is not UTF-8 encoded", path.display())) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -331,3 +331,6 @@ pub fn cfg_set_from_component( | |
|
||
Ok(cfg_set) | ||
} | ||
|
||
pub mod serdex; | ||
pub mod fsx; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use anyhow::Result; | ||
use camino::{Utf8Path, Utf8PathBuf}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::scarb_internal::fsx; | ||
|
||
#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)] | ||
#[serde(transparent)] | ||
pub struct RelativeUtf8PathBuf(Utf8PathBuf); | ||
|
||
impl RelativeUtf8PathBuf { | ||
pub fn relative_to_directory(&self, root: &Utf8Path) -> Result<Utf8PathBuf> { | ||
fsx::canonicalize_utf8(root.join(&self.0)) | ||
} | ||
|
||
pub fn relative_to_file(&self, file: &Utf8Path) -> Result<Utf8PathBuf> { | ||
let root = file.parent().expect("Expected file path to not be `/`."); | ||
self.relative_to_directory(root) | ||
} | ||
} |