From da2efa46aaf4600e5c4e1fbfa83f0973dbac55e3 Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Sat, 28 Sep 2013 18:00:09 -0500 Subject: [PATCH] SubversionDownloadStrategy: handle corrupt checkouts --- Library/Homebrew/download_strategy.rb | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index a5c2f10811..b01dbe63ba 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -311,9 +311,19 @@ class SubversionDownloadStrategy < AbstractDownloadStrategy @co end + def repo_valid? + @co.join(".svn").directory? + end + def fetch @url.sub!(/^svn\+/, '') if @url =~ %r[^svn\+http://] ohai "Checking out #{@url}" + + if @co.exist? and not repo_valid? + puts "Removing invalid SVN repo from cache" + @co.rmtree + end + if @spec == :revision fetch_repo @co, @url, @ref elsif @spec == :revisions @@ -350,11 +360,11 @@ class SubversionDownloadStrategy < AbstractDownloadStrategy # 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.exist? ? 'up' : 'checkout' + svncommand = target.directory? ? 'up' : 'checkout' args = [@@svn, svncommand] # SVN shipped with XCode 3.1.4 can't force a checkout. args << '--force' unless MacOS.version == :leopard and @@svn == '/usr/bin/svn' - args << url if !target.exist? + args << url unless target.directory? args << target args << '-r' << revision if revision args << '--ignore-externals' if ignore_externals @@ -386,9 +396,9 @@ class UnsafeSubversionDownloadStrategy < SubversionDownloadStrategy # 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.exist? ? 'up' : 'checkout' + svncommand = target.directory? ? 'up' : 'checkout' args = [@@svn, svncommand, '--non-interactive', '--trust-server-cert', '--force'] - args << url if !target.exist? + args << url unless target.directory? args << target args << '-r' << revision if revision args << '--ignore-externals' if ignore_externals