File tree Expand file tree Collapse file tree 1 file changed +19
-9
lines changed
Expand file tree Collapse file tree 1 file changed +19
-9
lines changed Original file line number Diff line number Diff line change 11use error_stack:: Result ;
22use lazy_static:: lazy_static;
33use regex:: Regex ;
4+ use std:: fs:: File ;
5+ use std:: io:: { BufRead , BufReader } ;
46use std:: path:: { Path , PathBuf } ;
57
68use crate :: {
@@ -49,8 +51,8 @@ impl<'a> ProjectFileBuilder<'a> {
4951}
5052
5153pub ( crate ) fn build_project_file_without_cache ( path : & PathBuf ) -> ProjectFile {
52- let content = match std :: fs :: read_to_string ( path) {
53- Ok ( content ) => content ,
54+ let file = match File :: open ( path) {
55+ Ok ( file ) => file ,
5456 Err ( _) => {
5557 return ProjectFile {
5658 path : path. clone ( ) ,
@@ -59,13 +61,21 @@ pub(crate) fn build_project_file_without_cache(path: &PathBuf) -> ProjectFile {
5961 }
6062 } ;
6163
62- let first_line = content. lines ( ) . next ( ) ;
63- let Some ( first_line) = first_line else {
64- return ProjectFile {
65- path : path. clone ( ) ,
66- owner : None ,
67- } ;
68- } ;
64+ let mut reader = BufReader :: new ( file) ;
65+ let mut first_line = String :: with_capacity ( 256 ) ;
66+
67+ match reader. read_line ( & mut first_line) {
68+ Ok ( 0 ) | Err ( _) => {
69+ return ProjectFile {
70+ path : path. clone ( ) ,
71+ owner : None ,
72+ } ;
73+ }
74+ Ok ( _) => { }
75+ }
76+
77+ // read_line includes the newline, but .lines() doesn't, so we need to trim
78+ let first_line = first_line. trim_end ( ) ;
6979
7080 let owner = TEAM_REGEX
7181 . captures ( first_line)
You can’t perform that action at this time.
0 commit comments