Created
November 16, 2015 18:14
-
-
Save craigstjean/932d479c0fcac461fbdb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'fileutils' | |
LINKED_KEGS_PATH = '/usr/local/Library/LinkedKegs' | |
class Keg | |
def initialize(linked_path) | |
@linked_path = linked_path | |
if linked_path.start_with? '.' | |
@linked_path = File.join(LINKED_KEGS_PATH, linked_path) | |
end | |
@linked_path = File.absolute_path @linked_path | |
end | |
def old_version_paths | |
paths = Array.new | |
Dir.foreach(File.dirname @linked_path) {|x| | |
if x != '.' and x != '..' | |
full_path = File.join(File.dirname(@linked_path), x) | |
paths << full_path if full_path != @linked_path | |
end | |
} | |
paths | |
end | |
end | |
kegs = Array.new | |
Dir.foreach(LINKED_KEGS_PATH) {|x| | |
full_path = File.join(LINKED_KEGS_PATH, x) | |
if File.symlink? full_path | |
kegs.push Keg.new(File.readlink(full_path)) | |
end | |
} | |
kegs.each {|k| | |
k.old_version_paths.each {|p| | |
puts "removing #{p}..." | |
FileUtils.rm_rf p | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment