fn build_ar_list(
    ws: &Workspace<'_>,
    pkg: &Package,
    src_files: Vec<PathBuf>,
    vcs_info: Option<String>,
) -> CargoResult<Vec<ArchiveFile>> {
    let mut result = Vec::new();
    let root = pkg.root();
    for src_file in src_files {
        let rel_path = src_file.strip_prefix(&root)?.to_path_buf();
        check_filename(&rel_path, &mut ws.config().shell())?;
        let rel_str = rel_path
            .to_str()
            .ok_or_else(|| {
                anyhow::format_err!("non-utf8 path in source directory: {}", rel_path.display())
            })?
            .to_string();
        match rel_str.as_ref() {
            "Cargo.toml" => {
                result.push(ArchiveFile {
                    rel_path: PathBuf::from("Cargo.toml.orig"),
                    rel_str: "Cargo.toml.orig".to_string(),
                    contents: FileContents::OnDisk(src_file),
                });
                let generated = pkg.to_registry_toml(ws.config())?;
                result.push(ArchiveFile {
                    rel_path,
                    rel_str,
                    contents: FileContents::Generated(generated),
                });
            }
            "Cargo.lock" => continue,
            VCS_INFO_FILE => anyhow::bail!(
                "invalid inclusion of reserved file name \
                     {} in package source",
                VCS_INFO_FILE
            ),
            _ => {
                result.push(ArchiveFile {
                    rel_path,
                    rel_str,
                    contents: FileContents::OnDisk(src_file),
                });
            }
        }
    }
    if pkg.include_lockfile() {
        let new_lock = build_lock(ws)?;
        result.push(ArchiveFile {
            rel_path: PathBuf::from("Cargo.lock"),
            rel_str: "Cargo.lock".to_string(),
            contents: FileContents::Generated(new_lock),
        });
    }
    if let Some(vcs_info) = vcs_info {
        result.push(ArchiveFile {
            rel_path: PathBuf::from(VCS_INFO_FILE),
            rel_str: VCS_INFO_FILE.to_string(),
            contents: FileContents::Generated(vcs_info),
        });
    }
    if let Some(license_file) = &pkg.manifest().metadata().license_file {
        let license_path = Path::new(license_file);
        let abs_license_path = paths::normalize_path(&pkg.root().join(license_path));
        if abs_license_path.exists() {
            match abs_license_path.strip_prefix(&pkg.root()) {
                Ok(rel_license_path) => {
                    if !result.iter().any(|ar| ar.rel_path == rel_license_path) {
                        result.push(ArchiveFile {
                            rel_path: rel_license_path.to_path_buf(),
                            rel_str: rel_license_path
                                .to_str()
                                .expect("everything was utf8")
                                .to_string(),
                            contents: FileContents::OnDisk(abs_license_path),
                        });
                    }
                }
                Err(_) => {
                    // The license exists somewhere outside of the package.
                    let license_name = license_path.file_name().unwrap();
                    if result
                        .iter()
                        .any(|ar| ar.rel_path.file_name().unwrap() == license_name)
                    {
                        ws.config().shell().warn(&format!(
                            "license-file `{}` appears to be a path outside of the package, \
                            but there is already a file named `{}` in the root of the package. \
                            The archived crate will contain the copy in the root of the package. \
                            Update the license-file to point to the path relative \
                            to the root of the package to remove this warning.",
                            license_file,
                            license_name.to_str().unwrap()
                        ))?;
                    } else {
                        result.push(ArchiveFile {
                            rel_path: PathBuf::from(license_name),
                            rel_str: license_name.to_str().unwrap().to_string(),
                            contents: FileContents::OnDisk(abs_license_path),
                        });
                    }
                }
            }
        } else {
            let rel_msg = if license_path.is_absolute() {
                "".to_string()
            } else {
                format!(" (relative to `{}`)", pkg.root().display())
            };
            ws.config().shell().warn(&format!(
                "license-file `{}` does not appear to exist{}.\n\
                Please update the license-file setting in the manifest at `{}`\n\
                This may become a hard error in the future.",
                license_path.display(),
                rel_msg,
                pkg.manifest_path().display()
            ))?;
        }
    }
    result.sort_unstable_by(|a, b| a.rel_path.cmp(&b.rel_path));

    Ok(result)
}
/// Builds list of files to archive.
Builds list of files to archive.
Builds list of files to archive .
fn build_ar_list(
    ws: &Workspace<'_>,
    pkg: &Package,
    src_files: Vec<PathBuf>,
    vcs_info: Option<String>,
) -> CargoResult<Vec<ArchiveFile>> {
    let mut result = Vec::new();
    let root = pkg.root();
    for src_file in src_files {
        let rel_path = src_file.strip_prefix(&root)?.to_path_buf();
        check_filename(&rel_path, &mut ws.config().shell())?;
        let rel_str = rel_path
            .to_str()
            .ok_or_else(|| {
                anyhow::format_err!("non-utf8 path in source directory: {}", rel_path.display())
            })?
            .to_string();
        match rel_str.as_ref() {
            "Cargo.toml" => {
                result.push(ArchiveFile {
                    rel_path: PathBuf::from("Cargo.toml.orig"),
                    rel_str: "Cargo.toml.orig".to_string(),
                    contents: FileContents::OnDisk(src_file),
                });
                let generated = pkg.to_registry_toml(ws.config())?;
                result.push(ArchiveFile {
                    rel_path,
                    rel_str,
                    contents: FileContents::Generated(generated),
                });
            }
            "Cargo.lock" => continue,
            VCS_INFO_FILE => anyhow::bail!(
                "invalid inclusion of reserved file name \
                     {} in package source",
                VCS_INFO_FILE
            ),
            _ => {
                result.push(ArchiveFile {
                    rel_path,
                    rel_str,
                    contents: FileContents::OnDisk(src_file),
                });
            }
        }
    }
    if pkg.include_lockfile() {
        let new_lock = build_lock(ws)?;
        result.push(ArchiveFile {
            rel_path: PathBuf::from("Cargo.lock"),
            rel_str: "Cargo.lock".to_string(),
            contents: FileContents::Generated(new_lock),
        });
    }
    if let Some(vcs_info) = vcs_info {
        result.push(ArchiveFile {
            rel_path: PathBuf::from(VCS_INFO_FILE),
            rel_str: VCS_INFO_FILE.to_string(),
            contents: FileContents::Generated(vcs_info),
        });
    }
    if let Some(license_file) = &pkg.manifest().metadata().license_file {
        let license_path = Path::new(license_file);
        let abs_license_path = paths::normalize_path(&pkg.root().join(license_path));
        if abs_license_path.exists() {
            match abs_license_path.strip_prefix(&pkg.root()) {
                Ok(rel_license_path) => {
                    if !result.iter().any(|ar| ar.rel_path == rel_license_path) {
                        result.push(ArchiveFile {
                            rel_path: rel_license_path.to_path_buf(),
                            rel_str: rel_license_path
                                .to_str()
                                .expect("everything was utf8")
                                .to_string(),
                            contents: FileContents::OnDisk(abs_license_path),
                        });
                    }
                }
                Err(_) => {
                    // The license exists somewhere outside of the package.
                    let license_name = license_path.file_name().unwrap();
                    if result
                        .iter()
                        .any(|ar| ar.rel_path.file_name().unwrap() == license_name)
                    {
                        ws.config().shell().warn(&format!(
                            "license-file `{}` appears to be a path outside of the package, \
                            but there is already a file named `{}` in the root of the package. \
                            The archived crate will contain the copy in the root of the package. \
                            Update the license-file to point to the path relative \
                            to the root of the package to remove this warning.",
                            license_file,
                            license_name.to_str().unwrap()
                        ))?;
                    } else {
                        result.push(ArchiveFile {
                            rel_path: PathBuf::from(license_name),
                            rel_str: license_name.to_str().unwrap().to_string(),
                            contents: FileContents::OnDisk(abs_license_path),
                        });
                    }
                }
            }
        } else {
            let rel_msg = if license_path.is_absolute() {
                "".to_string()
            } else {
                format!(" (relative to `{}`)", pkg.root().display())
            };
            ws.config().shell().warn(&format!(
                "license-file `{}` does not appear to exist{}.\n\
                Please update the license-file setting in the manifest at `{}`\n\
                This may become a hard error in the future.",
                license_path.display(),
                rel_msg,
                pkg.manifest_path().display()
            ))?;
        }
    }
    result.sort_unstable_by(|a, b| a.rel_path.cmp(&b.rel_path));
    Ok(result)
}
fn build_ar_list ( ws : & Workspace < ' _ > , pkg : & Package , src_files : Vec < PathBuf > , vcs_info : Option < String > , ) -> CargoResult < Vec < ArchiveFile > > { let mut result = Vec :: new ( ) ; let root = pkg . root ( ) ; for src_file in src_files { let rel_path = src_file . strip_prefix ( & root ) ? . to_path_buf ( ) ; check_filename ( & rel_path , & mut ws . config ( ) . shell ( ) ) ? ; let rel_str = rel_path . to_str ( ) . ok_or_else ( | | { anyhow :: format_err ! ( " " rel_path display ( ) ) } ) ? . to_string ( ) ; match rel_str . as_ref ( ) { " " => { result . push ( ArchiveFile { rel_path : PathBuf :: from ( " " ) , rel_str : " " . to_string ( ) , contents : FileContents :: OnDisk ( src_file ) , } ) ; let generated = pkg . to_registry_toml ( ws . config ( ) ) ? ; result . push ( ArchiveFile { rel_path , rel_str , contents : FileContents :: Generated ( generated ) , } ) ; } " " => continue , VCS_INFO_FILE => anyhow :: bail ! ( " \
 " VCS_INFO_FILE ) , _ => { result . push ( ArchiveFile { rel_path , rel_str , contents : FileContents :: OnDisk ( src_file ) , } ) ; } } } if pkg . include_lockfile ( ) { let new_lock = build_lock ( ws ) ? ; result . push ( ArchiveFile { rel_path : PathBuf :: from ( " " ) , rel_str : " " . to_string ( ) , contents : FileContents :: Generated ( new_lock ) , } ) ; } if let Some ( vcs_info ) = vcs_info { result . push ( ArchiveFile { rel_path : PathBuf :: from ( VCS_INFO_FILE ) , rel_str : VCS_INFO_FILE . to_string ( ) , contents : FileContents :: Generated ( vcs_info ) , } ) ; } if let Some ( license_file ) = & pkg . manifest ( ) . metadata ( ) . license_file { let license_path = Path :: new ( license_file ) ; let abs_license_path = paths :: normalize_path ( & pkg . root ( ) . join ( license_path ) ) ; if abs_license_path . exists ( ) { match abs_license_path . strip_prefix ( & pkg . root ( ) ) { Ok ( rel_license_path ) => { if ! result . iter ( ) . any ( | ar | ar . rel_path == rel_license_path ) { result . push ( ArchiveFile { rel_path : rel_license_path . to_path_buf ( ) , rel_str : rel_license_path . to_str ( ) . expect ( " " ) . to_string ( ) , contents : FileContents :: OnDisk ( abs_license_path ) , } ) ; } } Err ( _ ) => { // The license exists somewhere outside of the package. let license_name = license_path . file_name ( ) . unwrap ( ) ; if result . iter ( ) . any ( | ar | ar . rel_path . file_name ( ) . unwrap ( ) == license_name ) { ws . config ( ) . shell ( ) . warn ( & format ! ( " \
 \
 \
 \
 " license_file license_name to_str ( ) unwrap ( ) ) ) ? ; } else { result . push ( ArchiveFile { rel_path : PathBuf :: from ( license_name ) , rel_str : license_name . to_str ( ) . unwrap ( ) . to_string ( ) , contents : FileContents :: OnDisk ( abs_license_path ) , } ) ; } } } } else { let rel_msg = if license_path . is_absolute ( ) { " " . to_string ( ) } else { format ! ( " " pkg root ( ) display ( ) ) } ; ws . config ( ) . shell ( ) . warn ( & format ! ( " \n \
 \n \
 " license_path display ( ) rel_msg pkg manifest_path ( ) display ( ) ) ) ? ; } } result . sort_unstable_by ( | a , b | a . rel_path . cmp ( & b . rel_path ) ) ; Ok ( result ) }
Builds list of files to archive.
Builds list of files to archive .
ws
&Workspace<'_>
pkg
&Package
src_files
Vec<PathBuf>
vcs_info
Option<String>
ws
&Workspace<'_>
pkg
&Package
src_files
Vec<PathBuf>
vcs_info
Option<String>