1
1
use crate :: UNICODE_DIRECTORY ;
2
2
use std:: path:: Path ;
3
- use std:: process:: Command ;
3
+ use std:: process:: { Command , Output } ;
4
4
5
5
static URL_PREFIX : & str = "https://www.unicode.org/Public/UCD/latest/ucd/" ;
6
6
@@ -9,6 +9,18 @@ static README: &str = "ReadMe.txt";
9
9
static RESOURCES : & [ & str ] =
10
10
& [ "DerivedCoreProperties.txt" , "PropList.txt" , "UnicodeData.txt" , "SpecialCasing.txt" ] ;
11
11
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
+
12
24
pub fn fetch_latest ( ) {
13
25
let directory = Path :: new ( UNICODE_DIRECTORY ) ;
14
26
if directory. exists ( ) {
@@ -20,27 +32,14 @@ pub fn fetch_latest() {
20
32
if let Err ( e) = std:: fs:: create_dir_all ( directory) {
21
33
panic ! ( "Failed to create {UNICODE_DIRECTORY:?}: {e}" ) ;
22
34
}
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 ) ;
30
36
let current = std:: fs:: read_to_string ( directory. join ( README ) ) . unwrap_or_default ( ) ;
31
37
if current. as_bytes ( ) != & output. stdout [ ..] {
32
38
std:: fs:: write ( directory. join ( README ) , output. stdout ) . unwrap ( ) ;
33
39
}
34
40
35
41
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) ;
44
43
std:: fs:: write ( directory. join ( resource) , output. stdout ) . unwrap ( ) ;
45
44
}
46
45
}
0 commit comments