Commit 81aff23d authored by Wohlgemuth, Jason's avatar Wohlgemuth, Jason
Browse files

feat: Refactor read_file to use BufReader and not arbitrarily return Ok

parent 470cfa30
Loading
Loading
Loading
Loading
Loading
+14 −8
Original line number Diff line number Diff line
@@ -865,18 +865,24 @@ pub fn read_file<P>(path: P) -> Result<String, io::Error>
where
    P: Into<PathBuf> + Clone,
{
    let mut content = String::new();
    let _ = match File::open(path.clone().into()) {
        | Ok(mut file) => {
            debug!(path = path.into().to_absolute_string(), "=> {}", Label::read());
            file.read_to_string(&mut content)
    let path_buf = path.into();
    let filename = path_buf.file_name().unwrap_or_default().to_string_lossy().to_string();
    let file = match File::open(&path_buf) {
        | Ok(file) => file,
        | Err(why) => {
            error!(filename, "=> {} Read file", Label::fail());
            return Err(why);
        }
    };
    let mut reader = BufReader::new(file);
    let mut content = String::new();
    match reader.read_to_string(&mut content) {
        | Ok(_) => Ok(content),
        | Err(why) => {
            error!(path = path.into().to_absolute_string(), "=> {} Read file", Label::fail());
            error!(filename, "=> {} Read file content", Label::fail());
            Err(why)
        }
    };
    Ok(content)
    }
}
/// Returns path to a folder in the operating system's cache directory that is unique to the given
/// `namespace` with a random UUID as the name of the final folder.
+1 −2
Original line number Diff line number Diff line
@@ -223,8 +223,7 @@ fn test_read() {
    assert_eq!(content.unwrap(), "Hello world!");
    let path = PathBuf::from(FIXTURES).join("does-not-exist");
    let content = read_file(path);
    assert!(content.is_ok());
    assert_eq!(content.unwrap(), "");
    assert!(content.is_err());
}
#[test]
fn test_regex_capture_lookup() {
+79 −74
Original line number Diff line number Diff line
@@ -2918,14 +2918,14 @@ FN:815,sync_post
FN:822,sync_put
FN:829,parent
FN:864,read_file
FN:896,standard_project_folder
FN:923,to_absolute_string
FN:944,write_file
FN:902,standard_project_folder
FN:929,to_absolute_string
FN:950,write_file
FNF:39
FNDA:0,InputOutput::read_markdown
FNDA:0,InputOutput::write_markdown
FNDA:1729382256910270464,<impl FromCommand for SemanticVersion>::from_command
FNDA:1585267068834414592,<impl FromPath for MimeType>::from_path
FNDA:1729382256910270464,<impl FromPath for MimeType>::from_path
FNDA:288230376151711744,<impl ToStrings for Vec<P>>::to_strings
FNDA:0,<impl ToStrings for Vec<P>>::to_absolute_strings
FNDA:5836665117072162818,<impl ToAbsoluteString for PathBuf>::to_absolute_string
@@ -2976,8 +2976,8 @@ DA:169,1152921504606846976
DA:170,0
DA:173,432345564227567616
DA:176,720575940379279360
DA:192,1585267068834414592
DA:196,4755801206503243776
DA:192,1729382256910270464
DA:196,5188146770730811392
DA:200,288230376151711744
DA:201,288230376151711744
DA:202,2233785415175766016
@@ -3206,7 +3206,7 @@ DA:610,432345564227567616
DA:611,432345564227567616
DA:612,864691128455135232
DA:615,432345564227567616
DA:616,6557241057451442176
DA:616,7277816997830721536
DA:618,0
DA:632,0
DA:633,0
@@ -3301,42 +3301,47 @@ DA:846,0
DA:847,72057594037927936
DA:848,72057594037927936
DA:864,1224979098644774912
DA:868,2449958197289549824
DA:868,3674937295934324736
DA:869,3674937295934324736
DA:870,1152921504606846976
DA:871,1152921504606846976
DA:872,3458764513820540928
DA:870,2377900603251621888
DA:871,2305843009213693952
DA:872,72057594037927936
DA:873,72057594037927936
DA:874,72057594037927936
DA:875,72057594037927936
DA:876,72057594037927936
DA:879,1224979098644774912
DA:896,72057594037927936
DA:897,144115188075855872
DA:898,0
DA:899,216172782113783808
DA:900,216172782113783808
DA:901,0
DA:904,144115188075855872
DA:905,72057594037927936
DA:906,0
DA:908,144115188075855872
DA:923,6052837899185946624
DA:927,5764607523034234880
DA:928,11673330234144325632
DA:929,432345564227567616
DA:931,12105675798371893248
DA:944,360287970189639680
DA:948,720575940379279360
DA:949,1441151880758558720
DA:950,720575940379279360
DA:951,0
DA:952,0
DA:953,0
DA:956,0
DA:877,3458764513820540928
DA:878,2305843009213693952
DA:879,2305843009213693952
DA:880,1152921504606846976
DA:881,0
DA:882,0
DA:883,0
DA:902,72057594037927936
DA:903,144115188075855872
DA:904,0
DA:905,216172782113783808
DA:906,216172782113783808
DA:907,0
DA:910,144115188075855872
DA:911,72057594037927936
DA:912,0
DA:914,144115188075855872
DA:929,6052837899185946624
DA:933,5764607523034234880
DA:934,11673330234144325632
DA:935,432345564227567616
DA:937,12105675798371893248
DA:950,360287970189639680
DA:954,720575940379279360
DA:955,1441151880758558720
DA:956,720575940379279360
DA:957,0
DA:958,0
LF:374
LH:178
DA:959,0
DA:962,0
DA:963,0
DA:964,0
LF:379
LH:180
end_of_record
TN:
SF:C:\Users\jason\dev\acorn\acorn-lib\src\lib.rs
@@ -5621,8 +5626,8 @@ FNDA:216172782113783808,Label::fmt_using
FNDA:504403158265495552,<impl From for License>::from
FNDA:144115188075855872,License::from_technology
FNDA:288230376151711744,License::is_open_source
FNDA:1801439850948198400,<impl From for MimeType>::from
FNDA:1369094286720630784,MimeType::file_type
FNDA:1945555039024054272,<impl From for MimeType>::from
FNDA:1513209474796486656,MimeType::file_type
FNDA:0,<impl Default for SemanticVersion>::default
FNDA:1080863910568919040,<impl From for SemanticVersion>::from
FNDA:216172782113783808,<impl StringInterpolation for T>::replace_placeholder_with_string
@@ -5636,7 +5641,7 @@ FNDA:13763000461244235776,crockford_digit
FNDA:72057594037927936,current_date
FNDA:1585267068834414592,detect_json
FNDA:1369094286720630784,detect_xml
FNDA:2666130979403333632,file_extension
FNDA:2810246167479189504,file_extension
FNDA:216172782113783808,find_first
FNDA:0,format_bytes
FNDA:360287970189639680,frontmatter_and_body
@@ -5767,44 +5772,44 @@ DA:557,14411518807585587200
DA:558,288230376151711744
DA:559,432345564227567616
DA:560,72057594037927936
DA:591,1801439850948198400
DA:592,3602879701896396800
DA:593,1801439850948198400
DA:594,3314649325744685056
DA:595,2089670227099910144
DA:596,2449958197289549824
DA:597,1513209474796486656
DA:591,1945555039024054272
DA:592,3891110078048108544
DA:593,1945555039024054272
DA:594,3602879701896396800
DA:595,2233785415175766016
DA:596,2738188573441261568
DA:597,1801439850948198400
DA:598,1873497444986126336
DA:599,1873497444986126336
DA:600,1008806316530991104
DA:601,864691128455135232
DA:602,1729382256910270464
DA:603,1441151880758558720
DA:604,288230376151711744
DA:605,288230376151711744
DA:606,360287970189639680
DA:607,720575940379279360
DA:608,72057594037927936
DA:600,936748722493063168
DA:601,792633534417207296
DA:602,1585267068834414592
DA:603,1224979098644774912
DA:604,360287970189639680
DA:605,360287970189639680
DA:606,432345564227567616
DA:607,936748722493063168
DA:608,144115188075855872
DA:610,144115188075855872
DA:623,1369094286720630784
DA:624,1369094286720630784
DA:623,1513209474796486656
DA:624,1513209474796486656
DA:625,0
DA:626,432345564227567616
DA:627,0
DA:628,72057594037927936
DA:628,216172782113783808
DA:629,0
DA:630,0
DA:630,72057594037927936
DA:631,0
DA:632,0
DA:633,0
DA:634,0
DA:635,576460752303423488
DA:635,432345564227567616
DA:636,0
DA:637,0
DA:638,0
DA:639,72057594037927936
DA:640,0
DA:641,216172782113783808
DA:641,288230376151711744
DA:647,0
DA:648,0
DA:661,1080863910568919040
@@ -5886,15 +5891,15 @@ DA:838,720575940379279360
DA:839,216172782113783808
DA:840,5476377146882523136
DA:844,432345564227567616
DA:858,2666130979403333632
DA:862,7998392938210000896
DA:863,3458764513820540928
DA:864,2666130979403333632
DA:865,7566047373982433280
DA:866,7421932185906577408
DA:867,9511602413006487552
DA:868,4683743612465315840
DA:869,2017612633061982208
DA:858,2810246167479189504
DA:862,8430738502437568512
DA:863,4755801206503243776
DA:864,2810246167479189504
DA:865,7998392938210000896
DA:866,7854277750134145024
DA:867,10088063165309911040
DA:868,4971973988617027584
DA:869,2161727821137838080
DA:871,504403158265495552
DA:874,144115188075855872
DA:887,216172782113783808
@@ -5973,7 +5978,7 @@ DA:1091,0
DA:1096,7061644215716937728
DA:1097,288230376151711744
LF:324
LH:200
LH:201
end_of_record
TN:
SF:C:\Users\jason\dev\acorn\acorn-py\target\release\build\glutin_wgl_sys-7bf65d050f60911f\out\wgl_extra_bindings.rs
+1 −1

File changed.

Contains only whitespace changes.