comparison rust/rhg/src/commands/cat.rs @ 48073:1e00834491a5

rhg-cat: fallback when detecting `.` or `..` path segments We do not normalize paths correctly yet, so exclude the shortcuts. Differential Revision: https://phab.mercurial-scm.org/D11378
author Raphaël Gomès <rgomes@octobus.net>
date Wed, 01 Sep 2021 17:40:25 +0200
parents d919b0ca8449
children 4a6fa6b6f079
comparison
equal deleted inserted replaced
48072:d919b0ca8449 48073:1e00834491a5
44 let working_directory = repo.working_directory_path(); 44 let working_directory = repo.working_directory_path();
45 let working_directory = cwd.join(working_directory); // Make it absolute 45 let working_directory = cwd.join(working_directory); // Make it absolute
46 46
47 let mut files = vec![]; 47 let mut files = vec![];
48 for file in file_args.iter() { 48 for file in file_args.iter() {
49 let normalized = cwd.join(&file);
49 // TODO: actually normalize `..` path segments etc? 50 // TODO: actually normalize `..` path segments etc?
50 let normalized = cwd.join(&file); 51 let dotted = normalized.components().any(|c| c.as_os_str() == "..");
52 if file == &"." || dotted {
53 let message = "`..` or `.` path segment";
54 return Err(CommandError::unsupported(message));
55 }
51 let stripped = normalized 56 let stripped = normalized
52 .strip_prefix(&working_directory) 57 .strip_prefix(&working_directory)
53 // TODO: error message for path arguments outside of the repo 58 // TODO: error message for path arguments outside of the repo
54 .map_err(|_| CommandError::abort(""))?; 59 .map_err(|_| CommandError::abort(""))?;
55 let hg_file = HgPathBuf::try_from(stripped.to_path_buf()) 60 let hg_file = HgPathBuf::try_from(stripped.to_path_buf())