Skip to content

Instantly share code, notes, and snippets.

@hsbt
Created July 25, 2019 22:49
Show Gist options
  • Save hsbt/71acec37139fab53b93abbb1c3a06b36 to your computer and use it in GitHub Desktop.
Save hsbt/71acec37139fab53b93abbb1c3a06b36 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require "find"
require "pathname"
require "parallel"
RB_EXT_NAMES = %w[.rb .ru .gemspec .rake .cmd .gemfile .thor]
C_EXT_NAMES = %w[.c .h .cpp .hpp]
Parallel.map(Dir.glob("latest-gem/*").shuffle) do |dir|
Find.find(dir) {|fn|
st = File.lstat(fn)
if st.file?
if C_EXT_NAMES.any?{|ext| fn.end_with?(ext)}
next
elsif !(RB_EXT_NAMES.any?{|ext| fn.end_with?(ext)} || Pathname(fn).extname.empty?) ||
fn =~ /vendor\/bundle/ || fn =~ /vendor\/ruby\// || fn =~ /bundle\/ruby/
File.unlink fn
puts "removed: #{fn}"
next
end
end
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment