@@ -21,7 +21,6 @@ use symbol::Symbol;
21
21
use tokenstream;
22
22
use util:: small_vector:: SmallVector ;
23
23
24
- use std:: fs:: File ;
25
24
use std:: io:: prelude:: * ;
26
25
use std:: path:: PathBuf ;
27
26
use rustc_data_structures:: sync:: Lrc ;
@@ -99,7 +98,18 @@ pub fn expand_include<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[tokenstream::T
99
98
None => return DummyResult :: expr ( sp) ,
100
99
} ;
101
100
// The file will be added to the code map by the parser
102
- let path = res_rel_file ( cx, sp, file) ;
101
+ let path = res_rel_file ( cx, sp, file. clone ( ) ) ;
102
+ let env_sb = cx. parse_sess ( ) . env_sandbox ( ) ;
103
+ let path = match env_sb. path_lookup ( & path) {
104
+ Ok ( path) => path,
105
+ Err ( e) => {
106
+ cx. span_err ( sp,
107
+ & format ! ( "couldn't read {}: {}" ,
108
+ file,
109
+ e) ) ;
110
+ return DummyResult :: expr ( sp) ;
111
+ }
112
+ } ;
103
113
let directory_ownership = DirectoryOwnership :: Owned { relative : None } ;
104
114
let p = parse:: new_sub_parser_from_file ( cx. parse_sess ( ) , & path, directory_ownership, None , sp) ;
105
115
@@ -136,9 +146,10 @@ pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::TokenT
136
146
Some ( f) => f,
137
147
None => return DummyResult :: expr ( sp)
138
148
} ;
149
+ let env_sb = cx. parse_sess ( ) . env_sandbox ( ) ;
139
150
let file = res_rel_file ( cx, sp, file) ;
140
151
let mut bytes = Vec :: new ( ) ;
141
- match File :: open ( & file) . and_then ( |mut f| f. read_to_end ( & mut bytes) ) {
152
+ match env_sb . path_open ( & file) . and_then ( |mut f| f. read_to_end ( & mut bytes) ) {
142
153
Ok ( ..) => { }
143
154
Err ( e) => {
144
155
cx. span_err ( sp,
@@ -171,9 +182,10 @@ pub fn expand_include_bytes(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::Toke
171
182
Some ( f) => f,
172
183
None => return DummyResult :: expr ( sp)
173
184
} ;
185
+ let env_sb = cx. parse_sess ( ) . env_sandbox ( ) ;
174
186
let file = res_rel_file ( cx, sp, file) ;
175
187
let mut bytes = Vec :: new ( ) ;
176
- match File :: open ( & file) . and_then ( |mut f| f. read_to_end ( & mut bytes) ) {
188
+ match env_sb . path_open ( & file) . and_then ( |mut f| f. read_to_end ( & mut bytes) ) {
177
189
Err ( e) => {
178
190
cx. span_err ( sp,
179
191
& format ! ( "couldn't read {}: {}" , file. display( ) , e) ) ;
0 commit comments