fn sanitize_path(entry_path: &Path, dst: &Path) -> Result<Option<PathBuf>> {
    // We cannot call unpack_in because it errors if we try to use 2 account paths.
    // So, this code is borrowed from unpack_in
    // ref: https://docs.rs/tar/*/tar/struct.Entry.html#method.unpack_in
    let mut file_dst = dst.to_path_buf();
    const SKIP: Result<Option<PathBuf>> = Ok(None);
    {
        let path = entry_path;
        for part in path.components() {
            match part {
                // Leading '/' characters, root paths, and '.'
                // components are just ignored and treated as "empty
                // components"
                Component::Prefix(..) | Component::RootDir | Component::CurDir => continue,

                // If any part of the filename is '..', then skip over
                // unpacking the file to prevent directory traversal
                // security issues.  See, e.g.: CVE-2001-1267,
                // CVE-2002-0399, CVE-2005-1918, CVE-2007-4131
                Component::ParentDir => return SKIP,

                Component::Normal(part) => file_dst.push(part),
            }
        }
    }

    // Skip cases where only slashes or '.' parts were seen, because
    // this is effectively an empty filename.
    if *dst == *file_dst {
        return SKIP;
    }

    // Skip entries without a parent (i.e. outside of FS root)
    let parent = match file_dst.parent() {
        Some(p) => p,
        None => return SKIP,
    };

    fs::create_dir_all(parent)?;

    // Here we are different than untar_in. The code for tar::unpack_in internally calling unpack is a little different.
    // ignore return value here
    validate_inside_dst(dst, parent)?;
    let target = parent.join(entry_path.file_name().unwrap());

    Ok(Some(target))
}
// return Err on file system error
// return Some(path) if path is good
// return None if we should skip this file
return Err on file system error
return Some(path) if path is good
return None if we should skip this file
return Err on file system error return Some ( path ) if path is good return None if we should skip this file
fn sanitize_path(entry_path: &Path, dst: &Path) -> Result<Option<PathBuf>> {
    // We cannot call unpack_in because it errors if we try to use 2 account paths.
    // So, this code is borrowed from unpack_in
    // ref: https://docs.rs/tar/*/tar/struct.Entry.html#method.unpack_in
    let mut file_dst = dst.to_path_buf();
    const SKIP: Result<Option<PathBuf>> = Ok(None);
    {
        let path = entry_path;
        for part in path.components() {
            match part {
                // Leading '/' characters, root paths, and '.'
                // components are just ignored and treated as "empty
                // components"
                Component::Prefix(..) | Component::RootDir | Component::CurDir => continue,
                // If any part of the filename is '..', then skip over
                // unpacking the file to prevent directory traversal
                // security issues.  See, e.g.: CVE-2001-1267,
                // CVE-2002-0399, CVE-2005-1918, CVE-2007-4131
                Component::ParentDir => return SKIP,
                Component::Normal(part) => file_dst.push(part),
            }
        }
    }
    // Skip cases where only slashes or '.' parts were seen, because
    // this is effectively an empty filename.
    if *dst == *file_dst {
        return SKIP;
    }
    // Skip entries without a parent (i.e. outside of FS root)
    let parent = match file_dst.parent() {
        Some(p) => p,
        None => return SKIP,
    };
    fs::create_dir_all(parent)?;
    // Here we are different than untar_in. The code for tar::unpack_in internally calling unpack is a little different.
    // ignore return value here
    validate_inside_dst(dst, parent)?;
    let target = parent.join(entry_path.file_name().unwrap());
    Ok(Some(target))
}
fn sanitize_path ( entry_path : & Path , dst : & Path ) -> Result < Option < PathBuf > > { // We cannot call unpack_in because it errors if we try to use 2 account paths. // So, this code is borrowed from unpack_in // ref: https://docs.rs/tar/*/tar/struct.Entry.html#method.unpack_in let mut file_dst = dst . to_path_buf ( ) ; const SKIP : Result < Option < PathBuf > > = Ok ( None ) ; { let path = entry_path ; for part in path . components ( ) { match part { // Leading '/' characters, root paths, and '.' // components are just ignored and treated as "empty // components" Component :: Prefix ( .. ) | Component :: RootDir | Component :: CurDir => continue , // If any part of the filename is '..', then skip over // unpacking the file to prevent directory traversal // security issues.  See, e.g.: CVE-2001-1267, // CVE-2002-0399, CVE-2005-1918, CVE-2007-4131 Component :: ParentDir => return SKIP , Component :: Normal ( part ) => file_dst . push ( part ) , } } } // Skip cases where only slashes or '.' parts were seen, because // this is effectively an empty filename. if * dst == * file_dst { return SKIP ; } // Skip entries without a parent (i.e. outside of FS root) let parent = match file_dst . parent ( ) { Some ( p ) => p , None => return SKIP , } ; fs :: create_dir_all ( parent ) ? ; // Here we are different than untar_in. The code for tar::unpack_in internally calling unpack is a little different. // ignore return value here validate_inside_dst ( dst , parent ) ? ; let target = parent . join ( entry_path . file_name ( ) . unwrap ( ) ) ; Ok ( Some ( target ) ) }
return Err on file system error
return Some(path) if path is good
return None if we should skip this file
return Err on file system error return Some ( path ) if path is good return None if we should skip this file
entry_path
&Path
dst
&Path