Skip to content

Commit 6221a05

Browse files
committed
feat: add more archive formats, default to tar.gz
1 parent 4c25788 commit 6221a05

File tree

8 files changed

+295
-113
lines changed

8 files changed

+295
-113
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,28 @@ publish = false
1212

1313
[dependencies]
1414
async-recursion = "1.1.1"
15+
bzip2 = "0.4.4"
1516
clap = { version = "4.5.19", features = ["derive"] }
1617
clap_complete = "4.5.32"
1718
color-eyre = "0.6.3"
1819
dirs = "5.0.1"
1920
enum_dispatch = "0.3.13"
2021
eyre = "0.6.12"
22+
flate2 = "1.0.34"
2123
owo-colors = "4.1.0"
2224
regex = "1.11.0"
2325
reqwest = { version = "0.12.8", features = ["rustls-tls", "brotli"], default-features = false }
2426
rust-embed = "8.5.0"
2527
serde = { version = "1.0.210", features = ["derive"] }
26-
sysinfo = "0.31.4"
28+
sysinfo = "0.32.0"
29+
tar = "0.4.42"
2730
temp-dir = "0.1.14"
2831
tokio = { version = "1.40.0", features = ["full"] }
32+
tokio-stream = { version = "0.1.16", features = ["full"] }
2933
toml = "0.8.19"
34+
xz2 = "0.1.7"
3035
zip = "2.2.0"
36+
zstd = "0.13.2"
3137

3238
[lints.clippy]
3339
all = { level = "warn", priority = -1 }

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ nyoom specifies sources for userchromes in a special format.
5959
- **GitHub**: `github:<owner>/<repo>[#ref]`
6060
- **Codeberg**: `codeberg:<owner>/<repo>[#ref]`
6161
- **GitLab**: `gitlab:<owner>/<repo>[#ref]`
62-
- **URL** (to zip file): `url:<url>`
62+
- **Path** to a directory: `path:<path>`
63+
- **URL** (to a known archive format of `.zip`, `.tar`, `.tgz`, `.tar.gz`, `.tar.xz`, `.tar.bz2` or `.tar.zst`): `url:<url>` or just `<url>`
6364

6465
You can add a new userchrome by using the `nyoom add` command:
6566

flake.lock

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

src/switch.rs

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
use eyre::{bail, Result};
66
use temp_dir::TempDir;
77

8-
use std::{env, path::Path, process::Stdio, sync::LazyLock};
8+
use std::{
9+
env,
10+
path::{Path, PathBuf},
11+
process::Stdio,
12+
sync::LazyLock,
13+
};
914
use tokio::{fs, process::Command};
1015

1116
use owo_colors::OwoColorize as _;
@@ -131,7 +136,7 @@ static CODEBERG_REGEX: LazyLock<Regex> = LazyLock::new(|| {
131136
});
132137

133138
static GITLAB_REGEX: LazyLock<Regex> =
134-
LazyLock::new(|| Regex::new(r"cgitlab:(?P<repo>[\w\-_/]+)(#(?P<ref>[\w\-_]+))?").unwrap());
139+
LazyLock::new(|| Regex::new(r"gitlab:(?P<repo>[\w\-_/]+)(#(?P<ref>[\w\-_]+))?").unwrap());
135140

136141
async fn handle_source(source: &str, target_dir: &Path) -> Result<()> {
137142
if let Some(github) = GITHUB_REGEX.captures(source) {
@@ -140,37 +145,46 @@ async fn handle_source(source: &str, target_dir: &Path) -> Result<()> {
140145
.map_or("main", |ref_match| ref_match.into());
141146

142147
let url = format!(
143-
"https://github.com/{}/archive/refs/heads/{}.zip",
148+
"https://github.com/{}/archive/refs/heads/{}.tar.gz",
144149
&github["repo"], &ref_str,
145150
);
146151

147-
utils::download_zip(&url, target_dir).await?;
152+
utils::download_archive(&url, target_dir).await?;
148153
} else if let Some(codeberg) = CODEBERG_REGEX.captures(source) {
149154
let ref_str = codeberg
150155
.name("ref")
151156
.map_or("main", |ref_match| ref_match.into());
152157

153158
let url = format!(
154-
"https://codeberg.org/{}/archive/{}.zip",
159+
"https://codeberg.org/{}/archive/{}.tar.gz",
155160
&codeberg["repo"], &ref_str,
156161
);
157162

158-
utils::download_zip(&url, target_dir).await?;
163+
utils::download_archive(&url, target_dir).await?;
159164
} else if let Some(gitlab) = GITLAB_REGEX.captures(source) {
160165
let ref_str = gitlab
161166
.name("ref")
162167
.map_or("main", |ref_match| ref_match.into());
163168

164169
let url = format!(
165-
"https://gitlab.com/{}/-/archive/{}/source-{}.zip",
170+
"https://gitlab.com/{}/-/archive/{}/source-{}.tar.gz",
166171
&gitlab["repo"], &ref_str, &ref_str,
167172
);
168173

169-
utils::download_zip(&url, target_dir).await?;
174+
utils::download_archive(&url, target_dir).await?;
175+
} else if let Some(path) = source.strip_prefix("path:") {
176+
let source = PathBuf::from(path);
177+
if !source.is_dir() {
178+
bail!("provided path {path:?} is not a directory");
179+
}
180+
181+
utils::copy_dir_all(&source, target_dir).await?;
170182
} else if let Some(url) = source.strip_prefix("url:") {
171-
utils::download_zip(url, target_dir).await?;
183+
utils::download_archive(url, target_dir).await?;
184+
} else if source.starts_with("https://") || source.starts_with("http://") {
185+
utils::download_archive(source, target_dir).await?;
172186
} else {
173-
bail!("Invalid source specification: {}", source);
187+
bail!("invalid source specification: {}", source);
174188
}
175189

176190
Ok(())
@@ -202,12 +216,13 @@ pub async fn switch(userchrome: Option<&Userchrome>, profile: &Path) -> Result<(
202216
fs::remove_dir_all(&new_chrome_dir).await?;
203217
}
204218

205-
let mut cloned_chrome_dir = temp_path.join("chrome");
206-
if !cloned_chrome_dir.exists() {
207-
temp_path.clone_into(&mut cloned_chrome_dir);
208-
}
219+
let src_chrome_dir = if temp_path.join("chrome").exists() {
220+
temp_path.join("chrome")
221+
} else {
222+
temp_path.to_owned()
223+
};
209224

210-
utils::copy_dir_all(&cloned_chrome_dir, &new_chrome_dir).await?;
225+
utils::copy_dir_all(&src_chrome_dir, &new_chrome_dir).await?;
211226
fs::write(new_chrome_dir.join(".nyoom-chrome-name"), &userchrome.name).await?;
212227
} else {
213228
println!("{} removing userchrome", step_counter.to_string().green());

0 commit comments

Comments
 (0)