1
1
use regex:: Regex ;
2
2
use std:: path:: { Path , PathBuf } ;
3
- use tokio:: io:: { BufReader , AsyncBufReadExt } ;
4
- use tokio:: task;
5
- use tokio:: fs:: File ;
6
- use tokio:: runtime:: Handle ;
3
+ use std:: io:: prelude:: * ;
4
+ use std:: io:: BufReader ;
5
+ use std:: fs:: File ;
7
6
use lazy_static:: lazy_static;
8
7
// TODO use clap
9
8
use docopt:: Docopt ;
10
9
use serde:: Deserialize ;
11
10
use std:: ffi:: CString ;
12
11
use cached:: proc_macro:: cached;
12
+ use reqwest:: blocking:: Client ;
13
13
14
14
/// For libxml2 FFI.
15
15
use libc:: { c_char, c_int, c_uint, FILE } ;
@@ -70,16 +70,16 @@ struct Args {
70
70
71
71
/// Return the first Schema URL found, if any.
72
72
/// Panic on any I/O error.
73
- async fn extract_schema_url ( path : & Path ) -> Option < String > {
73
+ fn extract_schema_url ( path : & Path ) -> Option < String > {
74
74
lazy_static ! {
75
75
static ref RE : Regex = Regex :: new( r#"xsi:schemaLocation="\S+\s+(.+?)""# )
76
76
. expect( "failed to compile schemaLocation regex" ) ;
77
77
}
78
78
79
- let file = File :: open ( path) . await . unwrap ( ) ;
80
- let mut lines = BufReader :: new ( file) . lines ( ) ;
81
- while let Some ( line) = lines . next_line ( ) . await . unwrap ( ) {
82
- if let Some ( caps) = RE . captures ( & line) {
79
+ let file = File :: open ( path) . unwrap ( ) ;
80
+ let reader = BufReader :: new ( file) ;
81
+ for line in reader . lines ( ) {
82
+ if let Some ( caps) = RE . captures ( & line. unwrap ( ) ) {
83
83
return Some ( caps[ 1 ] . to_owned ( ) ) ;
84
84
}
85
85
}
@@ -90,15 +90,15 @@ async fn extract_schema_url(path: &Path) -> Option<String> {
90
90
///
91
91
/// Panics on I/O error.
92
92
#[ cached( sync_writes = true ) ]
93
- async fn get_schema ( url : String ) -> XmlSchemaPtr {
93
+ fn get_schema ( url : String ) -> XmlSchemaPtr {
94
94
lazy_static ! {
95
- static ref CLIENT : reqwest :: Client = reqwest :: Client :: new( ) ;
95
+ static ref CLIENT : Client = Client :: new( ) ;
96
96
}
97
97
98
98
// DEBUG to show that download happens only once.
99
99
println ! ( "Downloading now {url}..." ) ;
100
100
101
- let response = CLIENT . get ( url. as_str ( ) ) . send ( ) . await . unwrap ( ) . bytes ( ) . await . unwrap ( ) ;
101
+ let response = CLIENT . get ( url. as_str ( ) ) . send ( ) . unwrap ( ) . bytes ( ) . unwrap ( ) ;
102
102
103
103
unsafe {
104
104
let schema_parser_ctxt = xmlSchemaNewMemParserCtxt ( response. as_ptr ( ) as * const c_char ,
@@ -115,9 +115,9 @@ async fn get_schema(url: String) -> XmlSchemaPtr {
115
115
}
116
116
117
117
/// Copy the behavior of [`xmllint`](https://github.com/GNOME/libxml2/blob/master/xmllint.c)
118
- async fn validate ( path_buf : PathBuf ) {
119
- let url = extract_schema_url ( path_buf. as_path ( ) ) . await . unwrap ( ) ;
120
- let schema = get_schema ( url) . await ;
118
+ fn validate ( path_buf : PathBuf ) {
119
+ let url = extract_schema_url ( path_buf. as_path ( ) ) . unwrap ( ) ;
120
+ let schema = get_schema ( url) ;
121
121
122
122
let path_str = path_buf. to_str ( ) . unwrap ( ) ;
123
123
let c_path = CString :: new ( path_str) . unwrap ( ) ;
@@ -146,8 +146,7 @@ async fn validate(path_buf: PathBuf) {
146
146
}
147
147
}
148
148
149
- #[ tokio:: main]
150
- async fn main ( ) {
149
+ fn main ( ) {
151
150
let args: Args = Docopt :: new ( USAGE )
152
151
. and_then ( |d| d. deserialize ( ) )
153
152
. unwrap_or_else ( |e| e. exit ( ) ) ;
@@ -164,11 +163,7 @@ async fn main() {
164
163
let path = entry. path ( ) . to_owned ( ) ;
165
164
if let Some ( extension) = path. extension ( ) {
166
165
if extension. to_str ( ) . unwrap ( ) == extension_str {
167
- task:: block_in_place ( move || {
168
- Handle :: current ( ) . block_on ( async move {
169
- validate ( path) . await ;
170
- } )
171
- } )
166
+ validate ( path) ;
172
167
}
173
168
}
174
169
}
0 commit comments