11use crate :: UNICODE_DIRECTORY ;
22use std:: path:: Path ;
3- use std:: process:: Command ;
3+ use std:: process:: { Command , Output } ;
44
55static URL_PREFIX : & str = "https://www.unicode.org/Public/UCD/latest/ucd/" ;
66
@@ -9,6 +9,18 @@ static README: &str = "ReadMe.txt";
99static RESOURCES : & [ & str ] =
1010 & [ "DerivedCoreProperties.txt" , "PropList.txt" , "UnicodeData.txt" , "SpecialCasing.txt" ] ;
1111
12+ #[ track_caller]
13+ fn fetch ( url : & str ) -> Output {
14+ let output = Command :: new ( "curl" ) . arg ( URL_PREFIX . to_owned ( ) + url) . output ( ) . unwrap ( ) ;
15+ if !output. status . success ( ) {
16+ panic ! (
17+ "Failed to run curl to fetch {url}: stderr: {}" ,
18+ String :: from_utf8_lossy( & output. stderr)
19+ ) ;
20+ }
21+ output
22+ }
23+
1224pub fn fetch_latest ( ) {
1325 let directory = Path :: new ( UNICODE_DIRECTORY ) ;
1426 if directory. exists ( ) {
@@ -20,27 +32,14 @@ pub fn fetch_latest() {
2032 if let Err ( e) = std:: fs:: create_dir_all ( directory) {
2133 panic ! ( "Failed to create {UNICODE_DIRECTORY:?}: {e}" ) ;
2234 }
23- let output = Command :: new ( "curl" ) . arg ( URL_PREFIX . to_owned ( ) + README ) . output ( ) . unwrap ( ) ;
24- if !output. status . success ( ) {
25- panic ! (
26- "Failed to run curl to fetch readme: stderr: {}" ,
27- String :: from_utf8_lossy( & output. stderr)
28- ) ;
29- }
35+ let output = fetch ( README ) ;
3036 let current = std:: fs:: read_to_string ( directory. join ( README ) ) . unwrap_or_default ( ) ;
3137 if current. as_bytes ( ) != & output. stdout [ ..] {
3238 std:: fs:: write ( directory. join ( README ) , output. stdout ) . unwrap ( ) ;
3339 }
3440
3541 for resource in RESOURCES {
36- let output = Command :: new ( "curl" ) . arg ( URL_PREFIX . to_owned ( ) + resource) . output ( ) . unwrap ( ) ;
37- if !output. status . success ( ) {
38- panic ! (
39- "Failed to run curl to fetch {}: stderr: {}" ,
40- resource,
41- String :: from_utf8_lossy( & output. stderr)
42- ) ;
43- }
42+ let output = fetch ( resource) ;
4443 std:: fs:: write ( directory. join ( resource) , output. stdout ) . unwrap ( ) ;
4544 }
4645}
0 commit comments