Merge pull request #8427 from rolandwalker/homebrew_remove_extend_pathname_rmdir_if_possible

rm homebrew-fork extend Pathname#rmdir_if_possible
This commit is contained in:
Roland Walker
2014-12-26 14:29:08 -05:00
3 changed files with 24 additions and 23 deletions
+3 -7
View File
@@ -316,15 +316,11 @@ class Cask::Installer
permissions_rmtree subdir unless PERSISTENT_METADATA_SUBDIRS.include?(subdir.basename)
end
end
if @cask.metadata_versioned_container_path.respond_to?(:rmdir_if_possible)
@cask.metadata_versioned_container_path.rmdir_if_possible
end
if @cask.metadata_master_container_path.respond_to?(:rmdir_if_possible)
@cask.metadata_master_container_path.rmdir_if_possible
end
Cask::Utils.rmdir_if_possible(@cask.metadata_versioned_container_path)
Cask::Utils.rmdir_if_possible(@cask.metadata_master_container_path)
# toplevel staged distribution
@cask.caskroom_path.rmdir_if_possible
Cask::Utils.rmdir_if_possible(@cask.caskroom_path)
end
def purge_caskroom_path
+21
View File
@@ -148,6 +148,27 @@ module Cask::Utils
end
end
# from Homebrew
# children.length == 0 is slow to enumerate the whole directory just
# to see if it is empty
def self.rmdir_if_possible(dir)
dirpath = Pathname(dir)
begin
dirpath.rmdir
true
rescue Errno::ENOTEMPTY
if (ds_store = dirpath.join('.DS_Store')).exist? and
dirpath.children.length == 1
ds_store.unlink
retry
else
false
end
rescue Errno::EACCES, Errno::ENOENT
false
end
end
# paths that "look" descendant (textually) will still
# return false unless both the given paths exist
def self.file_is_descendant(file, dir)
@@ -1,22 +1,6 @@
require 'pathname'
class Pathname
# I don't trust the children.length == 0 check particularly, not to mention
# it is slow to enumerate the whole directory just to see if it is empty,
# instead rely on good ol' libc and the filesystem
def rmdir_if_possible
rmdir
true
rescue Errno::ENOTEMPTY
if (ds_store = self+'.DS_Store').exist? && children.length == 1
ds_store.unlink
retry
else
false
end
rescue Errno::EACCES, Errno::ENOENT
false
end
# FIXME eliminate the places where we rely on this method
alias_method :to_str, :to_s unless method_defined?(:to_str)