Class: Dependabot::Cargo::FileUpdater::LockfileUpdater

Inherits:
Object
  • Object
show all
Defined in:
lib/dependabot/cargo/file_updater/lockfile_updater.rb

Constant Summary collapse

LOCKFILE_ENTRY_REGEX =
/
  \[\[package\]\]\n
  (?:(?!^\[(\[package|metadata)).)+
/mx
LOCKFILE_CHECKSUM_REGEX =
/^"checksum .*$/

Instance Method Summary collapse

Constructor Details

#initialize(dependencies:, dependency_files:, credentials:) ⇒ LockfileUpdater

Returns a new instance of LockfileUpdater.



23
24
25
26
27
# File 'lib/dependabot/cargo/file_updater/lockfile_updater.rb', line 23

def initialize(dependencies:, dependency_files:, credentials:)
  @dependencies = dependencies
  @dependency_files = dependency_files
  @credentials = credentials
end

Instance Method Details

#updated_lockfile_contentObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/dependabot/cargo/file_updater/lockfile_updater.rb', line 29

def updated_lockfile_content
  base_directory = dependency_files.first.directory
  SharedHelpers.in_a_temporary_directory(base_directory) do
    write_temporary_dependency_files

    SharedHelpers.with_git_configured(credentials: credentials) do
      # Shell out to Cargo, which handles everything for us, and does
      # so without doing an install (so it's fast).
      run_cargo_command("cargo update -p #{dependency_spec}", fingerprint: "cargo update -p <dependency_spec>")
    end

    updated_lockfile = File.read("Cargo.lock")
    updated_lockfile = post_process_lockfile(updated_lockfile)

    next updated_lockfile if updated_lockfile.include?(desired_lockfile_content)

    raise "Failed to update #{dependency.name}!"
  end
rescue Dependabot::SharedHelpers::HelperSubprocessFailed => e
  retry if better_specification_needed?(e)
  handle_cargo_error(e)
end