download_package

in lib/gdk/package_helper.rb [85:119]


    def download_package
      if platform_specific && !GDK::PackageHelper.supported_os_arch?
        GDK::Output.info("Unsupported OS or architecture detected in #{GDK::Machine.package_platform}.
          To continue, please enable local compilation and then update by running `gdk config set #{package_basename}.skip_compile false && gdk update`.
        ")
        return
      end

      return GDK::Output.success("No changes detected in #{project_path}, skipping package download and extraction.") if current_commit_sha == stored_commit_sha

      uri = URI.parse("#{API_V4_URL}/projects/#{project_id}/packages/generic/#{package_name}/#{package_version}/#{File.basename(package_path)}")
      GDK::Output.info("Downloading package from #{uri}")

      response = Net::HTTP.get_response(uri)

      if response.is_a?(Net::HTTPNotFound)
        GDK::Output.warn("Package not found for version '#{package_version}', trying 'latest' instead.")

        uri = URI.parse("#{API_V4_URL}/projects/#{project_id}/packages/generic/#{package_name}/latest/#{File.basename(package_path)}")
        GDK::Output.info("Retrying download from #{uri}")

        response = Net::HTTP.get_response(uri)
      end

      raise "Download failed: #{response.body}" unless response.is_a?(Net::HTTPSuccess)

      File.write(package_path, response.body)
      GDK::Output.success("Package downloaded successfully to #{package_path}")

      @download_paths.each { |path| extract_package(path) }

      FileUtils.rm_f(package_path)
      store_commit_sha(current_commit_sha)
    end