Skip to content

Commit

Permalink
Merge pull request #8427 from rolandwalker/homebrew_remove_extend_pat…
Browse files Browse the repository at this point in the history
…hname_rmdir_if_possible

rm homebrew-fork extend Pathname#rmdir_if_possible
  • Loading branch information
rolandwalker committed Dec 26, 2014
2 parents be4f975 + f6f2251 commit d1116d7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
10 changes: 3 additions & 7 deletions lib/cask/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -316,15 +316,11 @@ def purge_versioned_files
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
Expand Down
21 changes: 21 additions & 0 deletions lib/cask/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,27 @@ def self.stringify_columns items, star_items=[]
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)
Expand Down
16 changes: 0 additions & 16 deletions lib/homebrew-fork/Library/Homebrew/extend/pathname.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit d1116d7

Please sign in to comment.