aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorMarkus Reiter2017-10-12 19:56:06 +0200
committerGitHub2017-10-12 19:56:06 +0200
commit30b84ac6f39d2f0cd3e3993959a11888a047afd5 (patch)
treec285cfa887024e2731faa0f8cf6a13fb8b4877e6 /Library
parent04801a2824992032c1cf882729376729af16d56e (diff)
parent04363b25a3422ba1409a8853f14f16bfb7604d17 (diff)
downloadbrew-30b84ac6f39d2f0cd3e3993959a11888a047afd5.tar.bz2
Merge pull request #3303 from reitermarkus/special-file-names
Properly handle special characters in file names.
Diffstat (limited to 'Library')
-rw-r--r--Library/.rubocop.yml3
-rw-r--r--Library/Homebrew/cask/lib/hbc/container/dmg.rb24
-rw-r--r--Library/Homebrew/cask/lib/hbc/system_command.rb17
3 files changed, 26 insertions, 18 deletions
diff --git a/Library/.rubocop.yml b/Library/.rubocop.yml
index 8e45668d9..7b3bdaeb6 100644
--- a/Library/.rubocop.yml
+++ b/Library/.rubocop.yml
@@ -94,6 +94,9 @@ Performance/Caller:
Style/Alias:
EnforcedStyle: prefer_alias
+Style/AsciiComments:
+ Enabled: false
+
Style/AutoResourceCleanup:
Enabled: true
diff --git a/Library/Homebrew/cask/lib/hbc/container/dmg.rb b/Library/Homebrew/cask/lib/hbc/container/dmg.rb
index 1d172a4b7..c0e43f68a 100644
--- a/Library/Homebrew/cask/lib/hbc/container/dmg.rb
+++ b/Library/Homebrew/cask/lib/hbc/container/dmg.rb
@@ -88,7 +88,7 @@ module Hbc
bomfile.close
Tempfile.open(["", ".list"]) do |filelist|
- filelist.write(bom_filelist_from_path(mount))
+ filelist.puts(bom_filelist_from_path(mount))
filelist.close
@command.run!("/usr/bin/mkbom", args: ["-s", "-i", filelist.path, "--", bomfile.path])
@@ -98,16 +98,17 @@ module Hbc
end
def bom_filelist_from_path(mount)
- Dir.chdir(mount) do
- Dir.glob("**/*", File::FNM_DOTMATCH).map do |path|
- next if skip_path?(Pathname(path))
- (path == ".") ? path : path.prepend("./")
- end.compact.join("\n").concat("\n")
- end
+ # We need to use `find` here instead of Ruby in order to properly handle
+ # file names containing special characters, such as โ€œeโ€ + โ€œยดโ€ vs. โ€œรฉโ€.
+ @command.run("/usr/bin/find", args: [".", "-print0"], chdir: mount, print_stderr: false).stdout
+ .split("\0")
+ .reject { |path| skip_path?(mount, path) }
+ .join("\n")
end
- def skip_path?(path)
- dmg_metadata?(path) || system_dir_symlink?(path)
+ def skip_path?(mount, path)
+ path = Pathname(path.sub(%r{^\./}, ""))
+ dmg_metadata?(path) || system_dir_symlink?(mount, path)
end
# unnecessary DMG metadata
@@ -130,9 +131,10 @@ module Hbc
DMG_METADATA_FILES.include?(relative_root.basename.to_s)
end
- def system_dir_symlink?(path)
+ def system_dir_symlink?(mount, path)
+ full_path = Pathname(mount).join(path)
# symlinks to system directories (commonly to /Applications)
- path.symlink? && MacOS.system_dir?(path.readlink)
+ full_path.symlink? && MacOS.system_dir?(full_path.readlink)
end
def mounts_from_plist(plist)
diff --git a/Library/Homebrew/cask/lib/hbc/system_command.rb b/Library/Homebrew/cask/lib/hbc/system_command.rb
index be083c29e..6b9a28ab2 100644
--- a/Library/Homebrew/cask/lib/hbc/system_command.rb
+++ b/Library/Homebrew/cask/lib/hbc/system_command.rb
@@ -10,12 +10,12 @@ module Hbc
class SystemCommand
attr_reader :command
- def self.run(executable, options = {})
- new(executable, options).run!
+ def self.run(executable, **options)
+ new(executable, **options).run!
end
- def self.run!(command, options = {})
- run(command, options.merge(must_succeed: true))
+ def self.run!(command, **options)
+ run(command, **options.merge(must_succeed: true))
end
def run!
@@ -37,7 +37,7 @@ module Hbc
result
end
- def initialize(executable, options)
+ def initialize(executable, **options)
@executable = executable
@options = options
process_options!
@@ -49,7 +49,7 @@ module Hbc
def process_options!
options.extend(HashValidator)
- .assert_valid_keys :input, :print_stdout, :print_stderr, :args, :must_succeed, :sudo
+ .assert_valid_keys :input, :print_stdout, :print_stderr, :args, :must_succeed, :sudo, :chdir
sudo_prefix = %w[/usr/bin/sudo -E --]
sudo_prefix = sudo_prefix.insert(1, "-A") unless ENV["SUDO_ASKPASS"].nil?
@command = [executable]
@@ -76,8 +76,11 @@ module Hbc
end
def each_output_line(&b)
+ opts = {}
+ opts[:chdir] = options[:chdir] if options[:chdir]
+
raw_stdin, raw_stdout, raw_stderr, raw_wait_thr =
- Open3.popen3(*expanded_command)
+ Open3.popen3(*expanded_command, **opts)
write_input_to(raw_stdin)
raw_stdin.close_write