comparison rust/hg-core/src/utils/files.rs @ 51117:532e74ad3ff6

rust: run a clippy pass with the latest stable version Our current version of clippy is older than the latest stable. The newest version has new lints that are moslty good advice, so let's apply them ahead of time. This has the added benefit of reducing the noise for developpers like myself that use clippy as an IDE helper, as well as being more prepared for a future clippy upgrade.
author Rapha?l Gom?s <rgomes@octobus.net>
date Mon, 06 Nov 2023 11:06:08 +0100
parents e98fd81bb151
children 529a655874fb
comparison
equal deleted inserted replaced
51116:d58e754f2db0 51117:532e74ad3ff6
190 let root = root.as_ref(); 190 let root = root.as_ref();
191 let cwd = cwd.as_ref(); 191 let cwd = cwd.as_ref();
192 let name = name.as_ref(); 192 let name = name.as_ref();
193 193
194 let name = if !name.is_absolute() { 194 let name = if !name.is_absolute() {
195 root.join(&cwd).join(&name) 195 root.join(cwd).join(name)
196 } else { 196 } else {
197 name.to_owned() 197 name.to_owned()
198 }; 198 };
199 let auditor = PathAuditor::new(&root); 199 let auditor = PathAuditor::new(root);
200 if name != root && name.starts_with(&root) { 200 if name != root && name.starts_with(root) {
201 let name = name.strip_prefix(&root).unwrap(); 201 let name = name.strip_prefix(root).unwrap();
202 auditor.audit_path(path_to_hg_path_buf(name)?)?; 202 auditor.audit_path(path_to_hg_path_buf(name)?)?;
203 Ok(name.to_owned()) 203 Ok(name.to_owned())
204 } else if name == root { 204 } else if name == root {
205 Ok("".into()) 205 Ok("".into())
206 } else { 206 } else {
208 // by iterating name=name.parent() until it returns `None` (can't 208 // by iterating name=name.parent() until it returns `None` (can't
209 // check name == '/', because that doesn't work on windows). 209 // check name == '/', because that doesn't work on windows).
210 let mut name = name.deref(); 210 let mut name = name.deref();
211 let original_name = name.to_owned(); 211 let original_name = name.to_owned();
212 loop { 212 loop {
213 let same = is_same_file(&name, &root).unwrap_or(false); 213 let same = is_same_file(name, root).unwrap_or(false);
214 if same { 214 if same {
215 if name == original_name { 215 if name == original_name {
216 // `name` was actually the same as root (maybe a symlink) 216 // `name` was actually the same as root (maybe a symlink)
217 return Ok("".into()); 217 return Ok("".into());
218 } 218 }
219 // `name` is a symlink to root, so `original_name` is under 219 // `name` is a symlink to root, so `original_name` is under
220 // root 220 // root
221 let rel_path = original_name.strip_prefix(&name).unwrap(); 221 let rel_path = original_name.strip_prefix(name).unwrap();
222 auditor.audit_path(path_to_hg_path_buf(&rel_path)?)?; 222 auditor.audit_path(path_to_hg_path_buf(rel_path)?)?;
223 return Ok(rel_path.to_owned()); 223 return Ok(rel_path.to_owned());
224 } 224 }
225 name = match name.parent() { 225 name = match name.parent() {
226 None => break, 226 None => break,
227 Some(p) => p, 227 Some(p) => p,
427 path: beneath_repo, 427 path: beneath_repo,
428 root: root.to_owned() 428 root: root.to_owned()
429 }) 429 })
430 ); 430 );
431 assert_eq!( 431 assert_eq!(
432 canonical_path(&root, Path::new(""), &under_repo_symlink), 432 canonical_path(&root, Path::new(""), under_repo_symlink),
433 Ok(PathBuf::from("d")) 433 Ok(PathBuf::from("d"))
434 ); 434 );
435 } 435 }
436 } 436 }