mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Merge pull request #3714 from niyaznigmatullin/canonicalize_windows_symlink_loop_looking
canonicalize: Loop looking in windows
This commit is contained in:
commit
db2e5fc6ec
1 changed files with 8 additions and 18 deletions
|
@ -17,7 +17,6 @@ use libc::{
|
||||||
S_IXUSR,
|
S_IXUSR,
|
||||||
};
|
};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
#[cfg(unix)]
|
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use std::env;
|
use std::env;
|
||||||
|
@ -314,7 +313,7 @@ pub fn canonicalize<P: AsRef<Path>>(
|
||||||
miss_mode: MissingHandling,
|
miss_mode: MissingHandling,
|
||||||
res_mode: ResolveMode,
|
res_mode: ResolveMode,
|
||||||
) -> IOResult<PathBuf> {
|
) -> IOResult<PathBuf> {
|
||||||
const SYMLINKS_TO_LOOK_FOR_LOOPS: i32 = 256;
|
const SYMLINKS_TO_LOOK_FOR_LOOPS: i32 = 20;
|
||||||
let original = original.as_ref();
|
let original = original.as_ref();
|
||||||
let original = if original.is_absolute() {
|
let original = if original.is_absolute() {
|
||||||
original.to_path_buf()
|
original.to_path_buf()
|
||||||
|
@ -330,7 +329,6 @@ pub fn canonicalize<P: AsRef<Path>>(
|
||||||
let mut parts: VecDeque<OwningComponent> = path.components().map(|part| part.into()).collect();
|
let mut parts: VecDeque<OwningComponent> = path.components().map(|part| part.into()).collect();
|
||||||
let mut result = PathBuf::new();
|
let mut result = PathBuf::new();
|
||||||
let mut followed_symlinks = 0;
|
let mut followed_symlinks = 0;
|
||||||
#[cfg(unix)]
|
|
||||||
let mut visited_files = HashSet::new();
|
let mut visited_files = HashSet::new();
|
||||||
while let Some(part) = parts.pop_front() {
|
while let Some(part) = parts.pop_front() {
|
||||||
match part {
|
match part {
|
||||||
|
@ -357,21 +355,13 @@ pub fn canonicalize<P: AsRef<Path>>(
|
||||||
if followed_symlinks < SYMLINKS_TO_LOOK_FOR_LOOPS {
|
if followed_symlinks < SYMLINKS_TO_LOOK_FOR_LOOPS {
|
||||||
followed_symlinks += 1;
|
followed_symlinks += 1;
|
||||||
} else {
|
} else {
|
||||||
#[cfg(unix)]
|
let file_info =
|
||||||
let has_loop = {
|
FileInformation::from_path(&result.parent().unwrap(), false).unwrap();
|
||||||
let file_info =
|
let mut path_to_follow = PathBuf::new();
|
||||||
FileInformation::from_path(&result.parent().unwrap(), false).unwrap();
|
for part in &parts {
|
||||||
let mut path_to_follow = PathBuf::new();
|
path_to_follow.push(part.as_os_str());
|
||||||
for part in &parts {
|
}
|
||||||
path_to_follow.push(part.as_os_str());
|
if !visited_files.insert((file_info, path_to_follow)) {
|
||||||
}
|
|
||||||
!visited_files.insert((file_info, path_to_follow))
|
|
||||||
};
|
|
||||||
|
|
||||||
#[cfg(not(unix))]
|
|
||||||
let has_loop = true;
|
|
||||||
|
|
||||||
if has_loop {
|
|
||||||
return Err(Error::new(
|
return Err(Error::new(
|
||||||
ErrorKind::InvalidInput,
|
ErrorKind::InvalidInput,
|
||||||
"Too many levels of symbolic links",
|
"Too many levels of symbolic links",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue