11//! Storage module.
22
3- use anyhow:: bail;
3+ use anyhow:: { Context , anyhow , bail} ;
44#[ cfg( feature = "tui" ) ]
55use colored:: Colorize ;
66use std:: path:: { Path , PathBuf } ;
77
8- use crate :: STORAGE_DIR ;
98use crate :: entities:: info:: ContentInfo ;
109#[ cfg( feature = "tui" ) ]
1110use crate :: entities:: info:: ShortName ;
1211use crate :: i18n;
1312use crate :: rw:: copy_all;
13+ use crate :: { STORAGE_DIR , hmap} ;
1414
1515/// Environment variable name.
1616pub const CUSTOM_STORAGE_PATH : & str = "DEPLOYER_STORAGE_PATH" ;
@@ -116,12 +116,17 @@ pub fn use_from_storage(storage_dir: &Path, build_dir: &Path, content_info: &Con
116116 }
117117 copy_all ( & content_path, & content_path, build_dir, & [ "" ] ) ?;
118118 } else {
119- let mut versions = vec ! [ ] ;
119+ let mut versions = hmap ! ( ) ;
120120 for entry in std:: fs:: read_dir ( & content_path) ? {
121121 let entry = entry?;
122- let name = entry. file_name ( ) . to_str ( ) . unwrap ( ) . to_owned ( ) ;
122+ let name = entry. file_name ( ) . to_string_lossy ( ) . to_string ( ) ;
123123 if name. starts_with ( content_info. short_name ( ) ) {
124- versions. push ( name) ;
124+ let version = name
125+ . split ( '@' )
126+ . next_back ( )
127+ . ok_or ( anyhow ! ( "There is no version spec in folder name!" ) ) ?;
128+ let version = semver:: Version :: parse ( version) . context ( "Can't parse version as SemVer!" ) ?;
129+ versions. insert ( version, name) ;
125130 }
126131 }
127132 if versions. is_empty ( ) {
@@ -132,7 +137,8 @@ pub fn use_from_storage(storage_dir: &Path, build_dir: &Path, content_info: &Con
132137 i18n:: CONTENT_CONSIDER_ADD
133138 )
134139 }
135- let max = versions. iter ( ) . max ( ) . unwrap ( ) ;
140+ let max = versions. keys ( ) . max ( ) . ok_or ( anyhow ! ( "No version available!" ) ) ?;
141+ let max = versions. get ( max) . ok_or ( anyhow ! ( "No version available!" ) ) ?;
136142
137143 crate :: rw:: log ( format ! ( "Decided to choose `{max}` from `latest`." ) ) ;
138144 content_path. push ( max) ;
0 commit comments