aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cask/lib/hbc/container
diff options
context:
space:
mode:
authorMarkus Reiter2017-08-07 22:13:10 +0200
committerGitHub2017-08-07 22:13:10 +0200
commit6ef49d8b86e436cb37df1344019189a2f2df0bbb (patch)
treec8acbd7b6986db02f8f49b4116fe4f3d594f3d65 /Library/Homebrew/cask/lib/hbc/container
parent69799d97b1e7314912b2ee234dec2c179c5fb969 (diff)
parentdc5a2c1764b1da3cfa85d8910338eb72cd4da96c (diff)
downloadbrew-6ef49d8b86e436cb37df1344019189a2f2df0bbb.tar.bz2
Merge pull request #2848 from reitermarkus/refactoring
Refactor SVN and cURL download strategies.
Diffstat (limited to 'Library/Homebrew/cask/lib/hbc/container')
-rw-r--r--Library/Homebrew/cask/lib/hbc/container/criteria.rb6
-rw-r--r--Library/Homebrew/cask/lib/hbc/container/directory.rb24
-rw-r--r--Library/Homebrew/cask/lib/hbc/container/executable.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/container/svn_repository.rb15
4 files changed, 44 insertions, 3 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/container/criteria.rb b/Library/Homebrew/cask/lib/hbc/container/criteria.rb
index 66ecb8c87..52f171d6a 100644
--- a/Library/Homebrew/cask/lib/hbc/container/criteria.rb
+++ b/Library/Homebrew/cask/lib/hbc/container/criteria.rb
@@ -13,9 +13,11 @@ module Hbc
end
def magic_number(regex)
+ return false if path.directory?
+
# 262: length of the longest regex (currently: Hbc::Container::Tar)
- @magic_number ||= File.open(@path, "rb") { |f| f.read(262) }
- @magic_number =~ regex
+ @magic_number ||= File.open(path, "rb") { |f| f.read(262) }
+ @magic_number.match?(regex)
end
end
end
diff --git a/Library/Homebrew/cask/lib/hbc/container/directory.rb b/Library/Homebrew/cask/lib/hbc/container/directory.rb
new file mode 100644
index 000000000..e4bb1095b
--- /dev/null
+++ b/Library/Homebrew/cask/lib/hbc/container/directory.rb
@@ -0,0 +1,24 @@
+require "hbc/container/base"
+
+module Hbc
+ class Container
+ class Directory < Base
+ def self.me?(*)
+ false
+ end
+
+ def extract
+ @path.children.each do |child|
+ next if skip_path?(child)
+ FileUtils.cp child, @cask.staged_path
+ end
+ end
+
+ private
+
+ def skip_path?(*)
+ false
+ end
+ end
+ end
+end
diff --git a/Library/Homebrew/cask/lib/hbc/container/executable.rb b/Library/Homebrew/cask/lib/hbc/container/executable.rb
index 848f6d4be..af3b36fd1 100644
--- a/Library/Homebrew/cask/lib/hbc/container/executable.rb
+++ b/Library/Homebrew/cask/lib/hbc/container/executable.rb
@@ -8,7 +8,7 @@ module Hbc
return true if criteria.magic_number(/^#!\s*\S+/)
begin
- MachO.open(criteria.path).header.executable?
+ criteria.path.file? && MachO.open(criteria.path).header.executable?
rescue MachO::MagicError
false
end
diff --git a/Library/Homebrew/cask/lib/hbc/container/svn_repository.rb b/Library/Homebrew/cask/lib/hbc/container/svn_repository.rb
new file mode 100644
index 000000000..cae613b2d
--- /dev/null
+++ b/Library/Homebrew/cask/lib/hbc/container/svn_repository.rb
@@ -0,0 +1,15 @@
+require "hbc/container/directory"
+
+module Hbc
+ class Container
+ class SvnRepository < Directory
+ def self.me?(criteria)
+ criteria.path.join(".svn").directory?
+ end
+
+ def skip_path?(path)
+ path.basename.to_s == ".svn"
+ end
+ end
+ end
+end