File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change 9
9
//! within the `SourceMap`, which upon request can be converted to line and column
10
10
//! information, source code snippets, etc.
11
11
12
+ use std:: fs:: File ;
12
13
use std:: io:: { self , BorrowedBuf , Read } ;
13
14
use std:: { fs, path} ;
14
15
@@ -115,13 +116,18 @@ impl FileLoader for RealFileLoader {
115
116
}
116
117
117
118
fn read_file ( & self , path : & Path ) -> io:: Result < String > {
118
- if path. metadata ( ) . is_ok_and ( |metadata| metadata. len ( ) > SourceFile :: MAX_FILE_SIZE . into ( ) ) {
119
+ let mut file = File :: open ( path) ?;
120
+ let size = file. metadata ( ) . map ( |metadata| metadata. len ( ) ) . ok ( ) . unwrap_or ( 0 ) ;
121
+
122
+ if size > SourceFile :: MAX_FILE_SIZE . into ( ) {
119
123
return Err ( io:: Error :: other ( format ! (
120
124
"text files larger than {} bytes are unsupported" ,
121
125
SourceFile :: MAX_FILE_SIZE
122
126
) ) ) ;
123
127
}
124
- fs:: read_to_string ( path)
128
+ let mut contents = String :: new ( ) ;
129
+ file. read_to_string ( & mut contents) ?;
130
+ Ok ( contents)
125
131
}
126
132
127
133
fn read_binary_file ( & self , path : & Path ) -> io:: Result < Arc < [ u8 ] > > {
You can’t perform that action at this time.
0 commit comments