Class: DownloadLock Private

Inherits:
LockFile show all
Defined in:
lock_file/download_lock.rb

Overview

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

A lock file for a download.

Constant Summary collapse

MAX_WAIT_SECONDS =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

180

Instance Attribute Summary

Attributes inherited from LockFile

#locked_path, #path

Instance Method Summary collapse

Methods inherited from LockFile

#lock, #unlock, #with_lock

Methods included from Utils::Output::Mixin

#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning

Constructor Details

#initialize(download_path) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:



9
10
11
# File 'lock_file/download_lock.rb', line 9

def initialize(download_path)
  super(:download, download_path)
end

Instance Method Details

#lock_or_wait(quiet: false, timeout: nil) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Waits for another process's download to finish instead of failing immediately. quiet: suppresses the warning when the caller is already rendering its own progress, since an unscheduled write desyncs DownloadQueue's redraw.

Parameters:

  • quiet (Boolean) (defaults to: false)
  • timeout (Integer, Float, nil) (defaults to: nil)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lock_file/download_lock.rb', line 17

def lock_or_wait(quiet: false, timeout: nil)
  max_wait = MAX_WAIT_SECONDS
  max_wait = timeout if timeout && timeout < max_wait
  waiting_since = T.let(nil, T.nilable(Time))
  begin
    lock
  rescue OperationInProgressError
    if waiting_since.nil?
      waiting_since = Time.now
      opoo "Waiting for another Homebrew process to finish downloading #{locked_path}..." unless quiet
    end

    waited = Time.now - waiting_since
    raise OperationInProgressError.new(locked_path, waited: waited.round) if waited >= max_wait

    sleep 0.1
    retry
  end
end