rm homebrew-fork extend Pathname#rmdir_if_possible

integrate a modified version into our codebase as a utility
method (no longer a monkeypatch)
This commit is contained in:
Roland Walker
2014-12-26 09:59:24 -05:00
parent a5f3f34e65
commit f6f225127f
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
@@ -134,6 +134,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
def version
require 'version'