diff options
| author | Mike McQuaid | 2013-10-06 22:04:46 +0100 | 
|---|---|---|
| committer | Mike McQuaid | 2013-10-10 16:46:47 +0100 | 
| commit | 8db4a6c18d3f69a1aa41b9db17b63ae751ef1ff8 (patch) | |
| tree | 2523a2b1a98554651f7e145ac3c4e1202eed4e62 | |
| parent | e39703be8ee4df3f55a9e583cd62439297063eed (diff) | |
| download | homebrew-8db4a6c18d3f69a1aa41b9db17b63ae751ef1ff8.tar.bz2 | |
InstallRenamed: don't overwrite etc files; rename.
If an etc file exists on installation instead of overwriting it (or
requiring all the manual checks in formula) simply copy it with the
extension `.default` appended.
| -rw-r--r-- | Library/Homebrew/extend/pathname.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/formula.rb | 10 | ||||
| -rw-r--r-- | Library/Homebrew/install_renamed.rb | 17 | 
3 files changed, 27 insertions, 2 deletions
| diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb index 0edd1bd06..fd5cf67f1 100644 --- a/Library/Homebrew/extend/pathname.rb +++ b/Library/Homebrew/extend/pathname.rb @@ -50,6 +50,8 @@ class Pathname      # and also broken symlinks are not the end of the world      raise "#{src} does not exist" unless File.symlink? src or File.exist? src +    dst = yield(src, dst) if block_given? +      mkpath      if File.symlink? src        # we use the BSD mv command because FileUtils copies the target and diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 391b3b322..9fc54bef1 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -9,7 +9,7 @@ require 'build_environment'  require 'build_options'  require 'formulary'  require 'software_spec' - +require 'install_renamed'  class Formula    include FileUtils @@ -165,7 +165,13 @@ class Formula    def kext_prefix; prefix+'Library/Extensions' end    # configuration needs to be preserved past upgrades -  def etc; HOMEBREW_GIT_ETC ? prefix+'etc' : HOMEBREW_PREFIX+'etc' end +  def etc +    etc = HOMEBREW_PREFIX+'etc' +    etc = prefix+etc if HOMEBREW_GIT_ETC +    etc.extend(InstallRenamed) +    etc +  end +    # generally we don't want var stuff inside the keg    def var; HOMEBREW_PREFIX+'var' end diff --git a/Library/Homebrew/install_renamed.rb b/Library/Homebrew/install_renamed.rb new file mode 100644 index 000000000..e0a69beec --- /dev/null +++ b/Library/Homebrew/install_renamed.rb @@ -0,0 +1,17 @@ +module InstallRenamed +  def install_p src, new_basename = nil +    super do |src, dst| +      dst += "/#{File.basename(src)}" if File.directory? dst +      append_default_if_different(src, dst) +    end +  end + +  private + +  def append_default_if_different src, dst +    if File.file? dst and !FileUtils.identical?(src, dst) and !HOMEBREW_GIT_ETC +      dst += ".default" +    end +    dst +  end +end | 
