|
9 | 9 |
|
10 | 10 | use clap::Parser;
|
11 | 11 | use gettextrs::{bind_textdomain_codeset, setlocale, textdomain, LocaleCategory};
|
12 |
| -use std::collections::HashSet; |
13 | 12 | use std::error::Error;
|
14 |
| -use std::ffi::OsString; |
15 | 13 | use std::fs;
|
16 | 14 | use std::io::Write;
|
17 | 15 | use std::io::{stderr, stdout, ErrorKind};
|
@@ -204,31 +202,34 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
204 | 202 | fn recursive_resolve(starting_path_buf: PathBuf) -> Result<PathBuf, String> {
|
205 | 203 | let mut current_path_buf = starting_path_buf;
|
206 | 204 |
|
207 |
| - let mut encountered_paths = HashSet::<OsString>::new(); |
| 205 | + let mut recursion_level = 0_usize; |
208 | 206 |
|
209 | 207 | #[allow(clippy::while_let_loop)]
|
210 | 208 | loop {
|
211 | 209 | match fs::read_link(current_path_buf.as_path()) {
|
212 | 210 | Ok(pa) => {
|
| 211 | + recursion_level += 1_usize; |
| 212 | + |
| 213 | + // https://unix.stackexchange.com/questions/53087/how-do-you-increase-maxsymlinks |
| 214 | + if recursion_level == 40_usize { |
| 215 | + return Err(format!( |
| 216 | + "Symbolic link chain is circular or just too long, gave up at \"{}\"", |
| 217 | + current_path_buf.to_string_lossy() |
| 218 | + )); |
| 219 | + } |
| 220 | + |
213 | 221 | if pa.is_absolute() {
|
214 | 222 | current_path_buf = pa;
|
215 | 223 | } else {
|
216 | 224 | if !current_path_buf.pop() {
|
217 | 225 | return Err(format!(
|
218 |
| - "Could not remove last path segment from path \"{}\")", |
| 226 | + "Could not remove last path segment from path \"{}\"", |
219 | 227 | current_path_buf.to_string_lossy()
|
220 | 228 | ));
|
221 | 229 | }
|
222 | 230 |
|
223 | 231 | current_path_buf.push(pa);
|
224 | 232 | }
|
225 |
| - |
226 |
| - if !encountered_paths.insert(current_path_buf.as_os_str().to_owned()) { |
227 |
| - return Err(format!( |
228 |
| - "Infinite symbolic link loop detected at \"{}\")", |
229 |
| - current_path_buf.to_string_lossy() |
230 |
| - )); |
231 |
| - } |
232 | 233 | }
|
233 | 234 | Err(_) => {
|
234 | 235 | break;
|
|
0 commit comments