(path: &str)
| 155 | } |
| 156 | |
| 157 | fn maybe_pyc_file_with_magic(path: &str) -> std::io::Result<bool> { |
| 158 | let path_obj = std::path::Path::new(path); |
| 159 | if !path_obj.is_file() { |
| 160 | return Ok(false); |
| 161 | } |
| 162 | |
| 163 | let mut file = std::fs::File::open(path)?; |
| 164 | let mut buf = [0u8; 2]; |
| 165 | |
| 166 | use std::io::Read; |
| 167 | if file.read(&mut buf)? != 2 { |
| 168 | return Ok(false); |
| 169 | } |
| 170 | |
| 171 | // Read only two bytes of the magic. If the file was opened in |
| 172 | // text mode, the bytes 3 and 4 of the magic (\r\n) might not |
| 173 | // be read as they are on disk. |
| 174 | Ok(crate::import::check_pyc_magic_number_bytes(&buf)) |
| 175 | } |
| 176 | } |
no test coverage detected