Skip to content

Commit f12f566

Browse files
author
Grant Wuerker
committed
Remote ingot dependencies.
1 parent 40c3a44 commit f12f566

76 files changed

Lines changed: 2319 additions & 684 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 103 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/common/src/cache.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
use camino::Utf8PathBuf;
2+
use std::{env, path::PathBuf};
3+
4+
fn utf8_path_from_os(value: std::ffi::OsString) -> Option<Utf8PathBuf> {
5+
Utf8PathBuf::from_path_buf(PathBuf::from(value)).ok()
6+
}
7+
8+
fn env_path(var: &str) -> Option<Utf8PathBuf> {
9+
env::var_os(var).and_then(utf8_path_from_os)
10+
}
11+
12+
fn join_components(mut base: Utf8PathBuf, components: &[&str]) -> Utf8PathBuf {
13+
for component in components {
14+
base.push(component);
15+
}
16+
base
17+
}
18+
19+
fn xdg_cache_dir() -> Option<Utf8PathBuf> {
20+
env_path("XDG_CACHE_HOME").map(|path| join_components(path, &["fe", "git"]))
21+
}
22+
23+
fn unix_home_cache() -> Option<Utf8PathBuf> {
24+
#[cfg(unix)]
25+
{
26+
env_path("HOME").map(|path| join_components(path, &[".cache", "fe", "git"]))
27+
}
28+
#[cfg(not(unix))]
29+
{
30+
None
31+
}
32+
}
33+
34+
fn windows_local_appdata() -> Option<Utf8PathBuf> {
35+
#[cfg(windows)]
36+
{
37+
env_path("LOCALAPPDATA")
38+
.or_else(|| env_path("USERPROFILE"))
39+
.map(|path| join_components(path, &["Fe", "cache", "git"]))
40+
}
41+
#[cfg(not(windows))]
42+
{
43+
None
44+
}
45+
}
46+
47+
pub fn remote_git_cache_dir() -> Option<Utf8PathBuf> {
48+
env_path("FE_REMOTE_CACHE_DIR")
49+
.or_else(|| {
50+
env_path("FE_CACHE_DIR").map(|path| {
51+
if path.ends_with("git") {
52+
path
53+
} else {
54+
join_components(path, &["git"])
55+
}
56+
})
57+
})
58+
.or_else(xdg_cache_dir)
59+
.or_else(unix_home_cache)
60+
.or_else(windows_local_appdata)
61+
.or_else(|| {
62+
utf8_path_from_os(env::temp_dir().into())
63+
.map(|path| join_components(path, &["fe", "git"]))
64+
})
65+
}

0 commit comments

Comments
 (0)