director/lib/director/jobs/update_release.rb
def process_packages
        logger.info("Checking for new packages in release")

        new_packages = []
        existing_packages = []

        @manifest["packages"].each do |package_meta|
          filter = {:sha1 => package_meta["sha1"]}
          if package_meta["fingerprint"]
            filter[:fingerprint] = package_meta["fingerprint"]
            filter = filter.sql_or
          end

          # Checking whether we might have the same bits somewhere
          packages = Models::Package.where(filter).all

          if packages.empty?
            new_packages << package_meta
            next
          end

          # Rebase is an interesting use case: we don't really care about
          # preserving the original package/job versions, so if we have a
          # checksum/fingerprint match, we can just substitute the original
          # package/job version with an existing one.
          if @rebase
            substitutes = packages.select do |package|
              package.release_id == @release_model.id &&
              package.name == package_meta["name"] &&
              package.dependency_set == Set.new(package_meta["dependencies"])
            end

            substitute = pick_best(substitutes, package_meta["version"])

            if substitute
              package_meta["version"] = substitute.version
              package_meta["sha1"] = substitute.sha1
              existing_packages << [substitute, package_meta]
              next
            end
          end

          # We can reuse an existing package as long as it
          # belongs to the same release and has the same name and version.
          existing_package = packages.find do |package|
            package.release_id == @release_model.id &&
            package.name == package_meta["name"] &&
            package.version == package_meta["version"]
            # NOT checking dependencies here b/c dependency change would
            # bump the package version anyway.
          end

          if existing_package
            existing_packages << [existing_package, package_meta]
          else
            # We found a package with the same checksum but different
            # (release, name, version) tuple, so we need to make a copy
            # of the package blob and create a new db entry for it
            package = packages.first
            package_meta["blobstore_id"] = package.blobstore_id
            new_packages << package_meta
          end
        end

        create_packages(new_packages)
        use_existing_packages(existing_packages)
      end
# Finds all package definitions in the manifest and sorts them into two
# buckets: new and existing packages, then creates new packages and points
# current release version to the existing packages.
# @return [void]
Finds all package definitions in the manifest and sorts them into two
buckets: new and existing packages, then creates new packages and points
current release version to the existing packages.
Finds all package definitions in the manifest and sorts them into two buckets : new and existing packages then creates new packages and points current release version to the existing packages .
def process_packages
        logger.info("Checking for new packages in release")
        new_packages = []
        existing_packages = []
        @manifest["packages"].each do |package_meta|
          filter = {:sha1 => package_meta["sha1"]}
          if package_meta["fingerprint"]
            filter[:fingerprint] = package_meta["fingerprint"]
            filter = filter.sql_or
          end
          packages = Models::Package.where(filter).all
          if packages.empty?
            new_packages << package_meta
            next
          end
          if @rebase
            substitutes = packages.select do |package|
              package.release_id == @release_model.id &&
              package.name == package_meta["name"] &&
              package.dependency_set == Set.new(package_meta["dependencies"])
            end
            substitute = pick_best(substitutes, package_meta["version"])
            if substitute
              package_meta["version"] = substitute.version
              package_meta["sha1"] = substitute.sha1
              existing_packages << [substitute, package_meta]
              next
            end
          end
          existing_package = packages.find do |package|
            package.release_id == @release_model.id &&
            package.name == package_meta["name"] &&
            package.version == package_meta["version"]
          end
          if existing_package
            existing_packages << [existing_package, package_meta]
          else
            package = packages.first
            package_meta["blobstore_id"] = package.blobstore_id
            new_packages << package_meta
          end
        end
        create_packages(new_packages)
        use_existing_packages(existing_packages)
      end
def process_packages logger . info ( "Checking for new packages in release" ) new_packages = [ ] existing_packages = [ ] @manifest [ "packages" ] . each do | package_meta | filter = { :sha1 => package_meta [ "sha1" ] } if package_meta [ "fingerprint" ] filter [ :fingerprint ] = package_meta [ "fingerprint" ] filter = filter . sql_or end packages = Models :: Package . where ( filter ) . all if packages . empty? new_packages << package_meta next end if @rebase substitutes = packages . select do | package | package . release_id == @release_model . id && package . name == package_meta [ "name" ] && package . dependency_set == Set . new ( package_meta [ "dependencies" ] ) end substitute = pick_best ( substitutes , package_meta [ "version" ] ) if substitute package_meta [ "version" ] = substitute . version package_meta [ "sha1" ] = substitute . sha1 existing_packages << [ substitute , package_meta ] next end end existing_package = packages . find do | package | package . release_id == @release_model . id && package . name == package_meta [ "name" ] && package . version == package_meta [ "version" ] end if existing_package existing_packages << [ existing_package , package_meta ] else package = packages . first package_meta [ "blobstore_id" ] = package . blobstore_id new_packages << package_meta end end create_packages ( new_packages ) use_existing_packages ( existing_packages ) end
Finds all package definitions in the manifest and sorts them into two
buckets: new and existing packages, then creates new packages and points
current release version to the existing packages.
Finds all package definitions in the manifest and sorts them into two buckets : new and existing packages then creates new packages and points current release version to the existing packages .
# Checking whether we might have the same bits somewhere # Rebase is an interesting use case: we don't really care about # preserving the original package/job versions, so if we have a # checksum/fingerprint match, we can just substitute the original # package/job version with an existing one. # We can reuse an existing package as long as it # belongs to the same release and has the same name and version. # NOT checking dependencies here b/c dependency change would # bump the package version anyway. # We found a package with the same checksum but different # (release, name, version) tuple, so we need to make a copy # of the package blob and create a new db entry for it
None
void