Class: Hbc::SubversionDownloadStrategy

Inherits:
HbVCSDownloadStrategy show all
Defined in:
Library/Homebrew/cask/lib/hbc/download_strategy.rb

Constant Summary

Constants inherited from HbVCSDownloadStrategy

HbVCSDownloadStrategy::REF_TYPES

Instance Attribute Summary

Attributes inherited from AbstractDownloadStrategy

#cask, #name, #uri_object, #url, #version

Instance Method Summary collapse

Methods inherited from HbVCSDownloadStrategy

#cache_filename, #cached_location, #clear_cache, #extract_ref, #initialize

Methods inherited from AbstractDownloadStrategy

#cached_location, #clear_cache, #initialize

Constructor Details

This class inherits a constructor from Hbc::HbVCSDownloadStrategy

Instance Method Details

#cache_tagObject



181
182
183
184
# File 'Library/Homebrew/cask/lib/hbc/download_strategy.rb', line 181

def cache_tag
  # TODO: pass versions as symbols, support :head here
  (version == "head") ? "svn-HEAD" : "svn"
end

#fetchObject

super does not provide checks for already-existing downloads



195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'Library/Homebrew/cask/lib/hbc/download_strategy.rb', line 195

def fetch
  if cached_location.directory?
    puts "Already downloaded: #{cached_location}"
  else
    @url = @url.sub(/^svn\+/, "") if @url =~ %r{^svn\+http://}
    ohai "Checking out #{@url}"

    clear_cache unless @url.chomp("/") == repo_url || quiet_system("svn", "switch", @url, @clone)

    if @clone.exist? && !repo_valid?
      puts "Removing invalid SVN repo from cache"
      clear_cache
    end

    case @ref_type
    when :revision
      fetch_repo @clone, @url, @ref
    when :revisions
      # nil is OK for main_revision, as fetch_repo will then get latest
      main_revision = @ref[:trunk]
      fetch_repo @clone, @url, main_revision, true

      fetch_externals do |external_name, external_url|
        fetch_repo @clone + external_name, external_url, @ref[external_name], true
      end
    else
      fetch_repo @clone, @url
    end
  end
  cached_location
end

#fetch_externalsObject



264
265
266
267
268
269
# File 'Library/Homebrew/cask/lib/hbc/download_strategy.rb', line 264

def fetch_externals
  `svn propget svn:externals '#{shell_quote(@url)}'`.chomp.each_line do |line|
    name, url = line.split(/\s+/)
    yield name, url
  end
end

#fetch_repo(target, url, revision = uri_object.revision, ignore_externals = false) ⇒ Object

This primary reason for redefining this method is the trust_cert option, controllable from the Cask definition. We also force consistent timestamps. The rest of this method is similar to Homebrew's, but translated to local idiom.



231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# File 'Library/Homebrew/cask/lib/hbc/download_strategy.rb', line 231

def fetch_repo(target, url, revision = uri_object.revision, ignore_externals = false)
  # Use "svn up" when the repository already exists locally.
  # This saves on bandwidth and will have a similar effect to verifying the
  # cache as it will make any changes to get the right revision.
  svncommand = target.directory? ? "up" : "checkout"
  args = [svncommand]

  # SVN shipped with XCode 3.1.4 can't force a checkout.
  args << "--force" unless MacOS.version == :leopard

  # make timestamps consistent for checksumming
  args.concat(%w[--config-option config:miscellany:use-commit-times=yes])

  if uri_object.trust_cert
    args << "--trust-server-cert"
    args << "--non-interactive"
  end

  args << url unless target.directory?
  args << target
  args << "-r" << revision if revision
  args << "--ignore-externals" if ignore_externals
  @command.run!("/usr/bin/svn",
                args:         args,
                print_stderr: false)
end

#repo_urlObject



190
191
192
# File 'Library/Homebrew/cask/lib/hbc/download_strategy.rb', line 190

def repo_url
  `svn info '#{@clone}' 2>/dev/null`.strip[/^URL: (.+)$/, 1]
end

#repo_valid?Boolean

Returns:

  • (Boolean)


186
187
188
# File 'Library/Homebrew/cask/lib/hbc/download_strategy.rb', line 186

def repo_valid?
  (@clone/".svn").directory?
end

#shell_quote(str) ⇒ Object



258
259
260
261
262
# File 'Library/Homebrew/cask/lib/hbc/download_strategy.rb', line 258

def shell_quote(str)
  # Oh god escaping shell args.
  # See http://notetoself.vrensk.com/2008/08/escaping-single-quotes-in-ruby-harder-than-expected/
  str.gsub(/\\|'/) { |c| "\\#{c}" }
end