|
3 | 3 | * Licensed under the MIT License. See License.txt in the project root for license information. |
4 | 4 | *--------------------------------------------------------------------------------------------*/ |
5 | 5 |
|
6 | | - |
7 | 6 | const FILE_HEADER: &str = "/*---------------------------------------------------------------------------------------------\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License. See License.txt in the project root for license information.\n *--------------------------------------------------------------------------------------------*/"; |
8 | 7 |
|
9 | 8 | use std::{env, fs, io, path::PathBuf, process}; |
10 | 9 |
|
11 | 10 | fn main() { |
12 | | - let files = enumerate_source_files().expect("expected to enumerate files"); |
13 | | - ensure_file_headers(&files).expect("expected to ensure file headers"); |
| 11 | + let files = enumerate_source_files().expect("expected to enumerate files"); |
| 12 | + ensure_file_headers(&files).expect("expected to ensure file headers"); |
14 | 13 | } |
15 | 14 |
|
16 | 15 | fn ensure_file_headers(files: &[PathBuf]) -> Result<(), io::Error> { |
17 | | - let mut ok = true; |
| 16 | + let mut ok = true; |
18 | 17 |
|
19 | 18 | let crlf_header_str = str::replace(FILE_HEADER, "\n", "\r\n"); |
20 | 19 | let crlf_header = crlf_header_str.as_bytes(); |
21 | 20 | let lf_header = FILE_HEADER.as_bytes(); |
22 | | - for file in files { |
23 | | - let contents = fs::read(file)?; |
| 21 | + for file in files { |
| 22 | + let contents = fs::read(file)?; |
24 | 23 |
|
25 | | - if !(contents.starts_with(lf_header) || contents.starts_with(crlf_header)) { |
26 | | - eprintln!("File missing copyright header: {}", file.display()); |
27 | | - ok = false; |
28 | | - } |
29 | | - } |
| 24 | + if !(contents.starts_with(lf_header) || contents.starts_with(crlf_header)) { |
| 25 | + eprintln!("File missing copyright header: {}", file.display()); |
| 26 | + ok = false; |
| 27 | + } |
| 28 | + } |
30 | 29 |
|
31 | | - if !ok { |
32 | | - process::exit(1); |
33 | | - } |
| 30 | + if !ok { |
| 31 | + process::exit(1); |
| 32 | + } |
34 | 33 |
|
35 | | - Ok(()) |
| 34 | + Ok(()) |
36 | 35 | } |
37 | 36 |
|
38 | 37 | /// Gets all "rs" files in the source directory |
39 | 38 | fn enumerate_source_files() -> Result<Vec<PathBuf>, io::Error> { |
40 | | - let mut files = vec![]; |
41 | | - let mut queue = vec![]; |
42 | | - |
43 | | - let current_dir = env::current_dir()?.join("src"); |
44 | | - queue.push(current_dir); |
45 | | - |
46 | | - while !queue.is_empty() { |
47 | | - for entry in fs::read_dir(queue.pop().unwrap())? { |
48 | | - let entry = entry?; |
49 | | - let ftype = entry.file_type()?; |
50 | | - if ftype.is_dir() { |
51 | | - queue.push(entry.path()); |
52 | | - } else if ftype.is_file() && entry.file_name().to_string_lossy().ends_with(".rs") { |
53 | | - files.push(entry.path()); |
54 | | - } |
55 | | - } |
56 | | - } |
57 | | - |
58 | | - Ok(files) |
| 39 | + let mut files = vec![]; |
| 40 | + let mut queue = vec![]; |
| 41 | + |
| 42 | + let current_dir = env::current_dir()?.join("src"); |
| 43 | + queue.push(current_dir); |
| 44 | + |
| 45 | + while !queue.is_empty() { |
| 46 | + for entry in fs::read_dir(queue.pop().unwrap())? { |
| 47 | + let entry = entry?; |
| 48 | + let ftype = entry.file_type()?; |
| 49 | + if ftype.is_dir() { |
| 50 | + queue.push(entry.path()); |
| 51 | + } else if ftype.is_file() && entry.file_name().to_string_lossy().ends_with(".rs") { |
| 52 | + files.push(entry.path()); |
| 53 | + } |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + Ok(files) |
59 | 58 | } |
0 commit comments