in cargo-guppy/src/mv.rs [191:226]
fn new(pkg_graph: &PackageGraph, dest_dir: &Utf8Path) -> Result<Self> {
let workspace = pkg_graph.workspace();
let workspace_root = workspace.root();
match dest_dir.canonicalize() {
Ok(dest_dir) => {
if !dest_dir.is_dir() {
bail!("destination {} is not a directory", dest_dir.display());
}
// The destination directory exists.
Ok(DestDir::Exists(
rel_path(&dest_dir, workspace_root)?.to_path_buf(),
))
}
Err(err) if err.kind() == io::ErrorKind::NotFound => {
// The destination directory doesn't exist and needs to be created.
// Canonicalize the parent, then glue the last component to it.
let last_component = dest_dir
.file_name()
.ok_or_else(|| eyre!("destination {} cannot end with ..", dest_dir))?;
let parent = dest_dir
.parent()
.ok_or_else(|| eyre!("destination {} cannot end with ..", dest_dir))?;
let parent = if parent.as_os_str() == "" {
Utf8Path::new(".")
} else {
parent
};
let parent = canonicalize_dir(pkg_graph, parent)?;
Ok(DestDir::Create(parent.join(last_component)))
}
Err(err) => Err(err).wrap_err_with(|| eyre!("reading destination {} failed", dest_dir)),
}
}