fn update_package_versions()

in eng/scripts/update-pathversions.rs [112:138]


fn update_package_versions(toml: &mut Table, package_versions: &Vec<(String, String, bool)>, add: bool) {
    // for each dependency table, for each package in package_versions
    // if the package is in the dependency table
    //   if the dependency has both path and version properties, update the version property
    //   if the dependency has has path, but not version, add the version property only if
    //     1. the table name is not "dev-dependencies"
    //     2. the package is not publish disabled
    //     3. the add flag is true

    let dependency_tables = get_dependency_tables(toml);

    for (table_name, table) in dependency_tables {
        for (package, version, is_publish_disabled) in package_versions {
            if let Some(dependency) = table.get_mut(package) {
                // azure_idenentity will only be a transitive dev-dependency
                let should_add = add && table_name != "dev-dependencies" && !is_publish_disabled && package != "azure_identity";

                let has_path_property = dependency.get("path").is_some();
                let has_version_property = dependency.get("version").is_some();

                if has_path_property && (has_version_property || should_add) {
                    dependency["version"] = value(version);
                }
            }
        }
    }
}