@@ -3,11 +3,12 @@ use regex::Regex;
33use std:: env;
44use std:: fs;
55use std:: io;
6- use std:: path:: Path ;
76use std:: process:: Command ;
87use std:: process:: Output ;
98use util;
109
10+ pub const PREFETCH_DIR : & str = "aur.tmp" ;
11+
1112
1213fn assert_command_success ( command : & Output ) {
1314 assert ! ( command. status. success( ) ,
@@ -18,23 +19,29 @@ fn assert_command_success(command: &Output) {
1819 ) ;
1920}
2021
22+
2123pub fn fresh_download ( name : & str , dirs : & ProjectDirs ) {
22- let valid_name_regexp = Regex :: new ( r"[a-zA-Z][a-zA-Z._-]*" ) . unwrap ( ) ;
23- assert ! ( valid_name_regexp. is_match( name) , "unexpected package name {}" , name) ;
24- fs:: remove_dir_all ( dirs. cache_dir ( ) . join ( name) ) . expect ( & format ! ( "Failed to clean cache dir for {}" , name) ) ;
24+ lazy_static ! {
25+ static ref name_regexp: Regex = Regex :: new( r"[a-zA-Z][a-zA-Z._-]*" ) . unwrap( ) ;
26+ }
27+ assert ! ( name_regexp. is_match( name) , "unexpected package name {}" , name) ;
28+ let path = dirs. cache_dir ( ) . join ( name) ;
29+ if path. exists ( ) {
30+ fs:: remove_dir_all ( & path) . expect ( & format ! ( "Failed to clean cache dir {:?}" , path) ) ;
31+ }
2532 fs:: create_dir_all ( dirs. cache_dir ( ) . join ( name) ) . expect ( & format ! ( "Failed to create cache dir for {}" , name) ) ;
26- env:: set_current_dir ( dirs. cache_dir ( ) . join ( name) ) . expect ( & format ! ( "Faild to cd into build dir for {}" , name) ) ;
27- let dir = "aur.tmp" ;
2833 let git_http_ref = format ! ( "https://aur.archlinux.org/{}.git" , name) ;
29- let command = Command :: new ( "git" ) . args ( & [ "clone" , & git_http_ref, dir ] )
34+ let command = Command :: new ( "git" ) . args ( & [ "clone" , & git_http_ref, PREFETCH_DIR ] )
3035 . output ( ) . expect ( & format ! ( "Failed to git-clone repository {}" , name) ) ;
3136 assert_command_success ( & command) ;
32- env:: set_current_dir ( & dir) . unwrap ( ) ;
33- assert ! ( Path :: new( "PKGBUILD" ) . exists( ) , "PKGBUILD not found for package {}. \
34- Does this package really exist in AUR?", name) ;
37+ }
38+
39+
40+ pub fn review_repo ( name : & str , dirs : & ProjectDirs ) {
41+ env:: set_current_dir ( dirs. cache_dir ( ) . join ( name) . join ( PREFETCH_DIR ) ) . expect ( & format ! ( "Faild to cd into build dir for {}" , name) ) ;
3542 loop {
36- eprint ! ( "Downloaded {}. V=view PKGBUILD, E=edit PKGBUILD, \
37- I=run shell to inspect, O=ok, use the file : ", name) ;
43+ eprint ! ( "Verifying package {}. V=view PKGBUILD, E=edit PKGBUILD, \
44+ I=run shell to inspect, O=ok, use package : ", name) ;
3845 let mut string = String :: new ( ) ;
3946 io:: stdin ( ) . read_line ( & mut string) . expect ( "RUA requires console to ask confirmation." ) ;
4047 let string = string. trim ( ) . to_lowercase ( ) ;
@@ -51,6 +58,6 @@ pub fn fresh_download(name: &str, dirs: &ProjectDirs) {
5158 }
5259 }
5360 env:: set_current_dir ( ".." ) . unwrap ( ) ;
54- fs:: rename ( dir , "build" )
55- . expect ( & format ! ( "Failed to move temporary directory '{}' to 'build'" , dir ) ) ;
61+ fs:: rename ( PREFETCH_DIR , "build" )
62+ . expect ( & format ! ( "Failed to move temporary directory '{}' to 'build'" , PREFETCH_DIR ) ) ;
5663}
0 commit comments