55use eyre:: { bail, Result } ;
66use 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+ } ;
914use tokio:: { fs, process:: Command } ;
1015
1116use owo_colors:: OwoColorize as _;
@@ -131,7 +136,7 @@ static CODEBERG_REGEX: LazyLock<Regex> = LazyLock::new(|| {
131136} ) ;
132137
133138static 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
136141async 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