| 
									
										
										
										
											2020-10-10 14:16:11 +02:00
										 |  |  | # typed: false | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-27 17:01:22 +01:00
										 |  |  | require "test/support/fixtures/testball" | 
					
						
							|  |  |  | require "cleanup" | 
					
						
							| 
									
										
										
										
											2018-09-03 19:39:07 +01:00
										 |  |  | require "cask/cache" | 
					
						
							| 
									
										
										
										
											2017-02-27 17:01:22 +01:00
										 |  |  | require "fileutils" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-17 03:52:17 +02:00
										 |  |  | using Homebrew::Cleanup::CleanupRefinement | 
					
						
							| 
									
										
										
										
											2018-08-08 09:43:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-27 17:01:22 +01:00
										 |  |  | describe Homebrew::Cleanup do | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |   subject(:cleanup) { described_class.new } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-06 18:38:43 +01:00
										 |  |  |   let(:ds_store) { Pathname.new("#{HOMEBREW_CELLAR}/.DS_Store") } | 
					
						
							|  |  |  |   let(:lock_file) { Pathname.new("#{HOMEBREW_LOCKS}/foo") } | 
					
						
							| 
									
										
										
										
											2017-02-27 17:01:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  |   around do |example| | 
					
						
							| 
									
										
										
										
											2019-10-13 10:03:26 +01:00
										 |  |  |     FileUtils.touch ds_store | 
					
						
							|  |  |  |     FileUtils.touch lock_file | 
					
						
							| 
									
										
										
										
											2020-09-03 09:43:41 +01:00
										 |  |  |     FileUtils.mkdir_p HOMEBREW_LIBRARY/"Homebrew/vendor" | 
					
						
							|  |  |  |     FileUtils.touch HOMEBREW_LIBRARY/"Homebrew/vendor/portable-ruby-version" | 
					
						
							| 
									
										
										
										
											2019-10-13 10:03:26 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     example.run | 
					
						
							|  |  |  |   ensure | 
					
						
							|  |  |  |     FileUtils.rm_f ds_store | 
					
						
							|  |  |  |     FileUtils.rm_f lock_file | 
					
						
							| 
									
										
										
										
											2020-09-03 09:43:41 +01:00
										 |  |  |     FileUtils.rm_rf HOMEBREW_LIBRARY/"Homebrew" | 
					
						
							| 
									
										
										
										
											2017-02-27 17:01:22 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-31 14:50:29 -05:00
										 |  |  |   describe "::CleanupRefinement::prune?" do | 
					
						
							|  |  |  |     alias_matcher :be_pruned, :be_prune | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     subject(:path) { HOMEBREW_CACHE/"foo" } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     before do | 
					
						
							|  |  |  |       path.mkpath | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "returns true when ctime and mtime < days_default" do | 
					
						
							|  |  |  |       allow_any_instance_of(Pathname).to receive(:ctime).and_return(2.days.ago) | 
					
						
							|  |  |  |       allow_any_instance_of(Pathname).to receive(:mtime).and_return(2.days.ago) | 
					
						
							|  |  |  |       expect(path.prune?(1)).to be true | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "returns false when ctime and mtime >= days_default" do | 
					
						
							|  |  |  |       expect(path.prune?(2)).to be false | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-27 17:01:22 +01:00
										 |  |  |   describe "::cleanup" do | 
					
						
							| 
									
										
										
										
											2018-03-14 21:50:53 +08:00
										 |  |  |     it "removes .DS_Store and lock files" do | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       cleanup.clean! | 
					
						
							| 
									
										
										
										
											2017-02-27 17:01:22 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect(ds_store).not_to exist | 
					
						
							| 
									
										
										
										
											2018-03-14 21:50:53 +08:00
										 |  |  |       expect(lock_file).not_to exist | 
					
						
							| 
									
										
										
										
											2017-02-27 17:01:22 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-08 11:20:53 +02:00
										 |  |  |     it "doesn't remove anything if `dry_run` is true" do | 
					
						
							|  |  |  |       described_class.new(dry_run: true).clean! | 
					
						
							| 
									
										
										
										
											2017-02-27 17:01:22 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect(ds_store).to exist | 
					
						
							| 
									
										
										
										
											2018-03-14 21:50:53 +08:00
										 |  |  |       expect(lock_file).to exist | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "doesn't remove the lock file if it is locked" do | 
					
						
							|  |  |  |       lock_file.open(File::RDWR | File::CREAT).flock(File::LOCK_EX | File::LOCK_NB) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       cleanup.clean! | 
					
						
							| 
									
										
										
										
											2018-03-14 21:50:53 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect(lock_file).to exist | 
					
						
							| 
									
										
										
										
											2017-02-27 17:01:22 +01:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-03-21 04:13:13 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     context "when it can't remove a keg" do | 
					
						
							|  |  |  |       let(:f1) { Class.new(Testball) { version "0.1" }.new } | 
					
						
							|  |  |  |       let(:f2) { Class.new(Testball) { version "0.2" }.new } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  |       before do | 
					
						
							| 
									
										
										
										
											2017-07-29 19:55:05 +02:00
										 |  |  |         [f1, f2].each do |f| | 
					
						
							|  |  |  |           f.brew do | 
					
						
							|  |  |  |             f.install | 
					
						
							| 
									
										
										
										
											2017-03-21 04:13:13 -05:00
										 |  |  |           end | 
					
						
							| 
									
										
										
										
											2017-07-29 19:55:05 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |           Tab.create(f, DevelopmentTools.default_compiler, :libcxx).write | 
					
						
							| 
									
										
										
										
											2017-03-21 04:13:13 -05:00
										 |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         allow_any_instance_of(Keg) | 
					
						
							|  |  |  |           .to receive(:uninstall) | 
					
						
							|  |  |  |           .and_raise(Errno::EACCES) | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it "doesn't remove any kegs" do | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |         cleanup.cleanup_formula f2 | 
					
						
							| 
									
										
										
										
											2017-03-21 04:13:13 -05:00
										 |  |  |         expect(f1.installed_kegs.size).to eq(2) | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it "lists the unremovable kegs" do | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |         cleanup.cleanup_formula f2 | 
					
						
							|  |  |  |         expect(cleanup.unremovable_kegs).to contain_exactly(f1.installed_kegs[0]) | 
					
						
							| 
									
										
										
										
											2017-03-21 04:13:13 -05:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-02-27 17:01:22 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   specify "::cleanup_formula" do | 
					
						
							|  |  |  |     f1 = Class.new(Testball) do | 
					
						
							|  |  |  |       version "1.0" | 
					
						
							|  |  |  |     end.new | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     f2 = Class.new(Testball) do | 
					
						
							|  |  |  |       version "0.2" | 
					
						
							|  |  |  |       version_scheme 1
 | 
					
						
							|  |  |  |     end.new | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     f3 = Class.new(Testball) do | 
					
						
							|  |  |  |       version "0.3" | 
					
						
							|  |  |  |       version_scheme 1
 | 
					
						
							|  |  |  |     end.new | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     f4 = Class.new(Testball) do | 
					
						
							|  |  |  |       version "0.1" | 
					
						
							|  |  |  |       version_scheme 2
 | 
					
						
							|  |  |  |     end.new | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-29 19:55:05 +02:00
										 |  |  |     [f1, f2, f3, f4].each do |f| | 
					
						
							|  |  |  |       f.brew do | 
					
						
							|  |  |  |         f.install | 
					
						
							| 
									
										
										
										
											2017-02-27 17:01:22 +01:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2017-07-29 19:55:05 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       Tab.create(f, DevelopmentTools.default_compiler, :libcxx).write | 
					
						
							| 
									
										
										
										
											2017-02-27 17:01:22 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-03 11:42:09 +00:00
										 |  |  |     expect(f1).to be_latest_version_installed | 
					
						
							|  |  |  |     expect(f2).to be_latest_version_installed | 
					
						
							|  |  |  |     expect(f3).to be_latest_version_installed | 
					
						
							|  |  |  |     expect(f4).to be_latest_version_installed | 
					
						
							| 
									
										
										
										
											2017-02-27 17:01:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |     cleanup.cleanup_formula f3 | 
					
						
							| 
									
										
										
										
											2017-02-27 17:01:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-03 11:42:09 +00:00
										 |  |  |     expect(f1).not_to be_latest_version_installed | 
					
						
							|  |  |  |     expect(f2).not_to be_latest_version_installed | 
					
						
							|  |  |  |     expect(f3).to be_latest_version_installed | 
					
						
							|  |  |  |     expect(f4).to be_latest_version_installed | 
					
						
							| 
									
										
										
										
											2017-02-27 17:01:22 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-09 15:00:19 +02:00
										 |  |  |   describe "#cleanup_cask", :cask do | 
					
						
							| 
									
										
										
										
											2018-09-20 09:07:56 +01:00
										 |  |  |     before do | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       Cask::Cache.path.mkpath | 
					
						
							| 
									
										
										
										
											2018-08-09 15:00:19 +02:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     context "when given a versioned cask" do | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       let(:cask) { Cask::CaskLoader.load("local-transmission") } | 
					
						
							| 
									
										
										
										
											2018-08-09 15:00:19 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it "removes the download if it is not for the latest version" do | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |         download = Cask::Cache.path/"#{cask.token}--7.8.9" | 
					
						
							| 
									
										
										
										
											2018-08-09 15:00:19 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         FileUtils.touch download | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |         cleanup.cleanup_cask(cask) | 
					
						
							| 
									
										
										
										
											2018-08-09 15:00:19 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         expect(download).not_to exist | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it "does not remove downloads for the latest version" do | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |         download = Cask::Cache.path/"#{cask.token}--#{cask.version}" | 
					
						
							| 
									
										
										
										
											2018-08-09 15:00:19 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         FileUtils.touch download | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |         cleanup.cleanup_cask(cask) | 
					
						
							| 
									
										
										
										
											2018-08-09 15:00:19 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         expect(download).to exist | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     context "when given a `:latest` cask" do | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |       let(:cask) { Cask::CaskLoader.load("latest-with-appcast") } | 
					
						
							| 
									
										
										
										
											2018-08-09 15:00:19 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it "does not remove the download for the latest version" do | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |         download = Cask::Cache.path/"#{cask.token}--#{cask.version}" | 
					
						
							| 
									
										
										
										
											2018-08-09 15:00:19 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         FileUtils.touch download | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |         cleanup.cleanup_cask(cask) | 
					
						
							| 
									
										
										
										
											2018-08-09 15:00:19 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         expect(download).to exist | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-03 16:23:44 +00:00
										 |  |  |       it "removes the download for the latest version after 30 days" do | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |         download = Cask::Cache.path/"#{cask.token}--#{cask.version}" | 
					
						
							| 
									
										
										
										
											2018-08-09 15:00:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-21 21:35:24 +00:00
										 |  |  |         allow(download).to receive(:ctime).and_return(30.days.ago - 1.hour) | 
					
						
							|  |  |  |         allow(download).to receive(:mtime).and_return(30.days.ago - 1.hour) | 
					
						
							| 
									
										
										
										
											2018-08-09 15:00:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |         cleanup.cleanup_cask(cask) | 
					
						
							| 
									
										
										
										
											2018-08-09 15:00:19 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         expect(download).not_to exist | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-13 04:21:26 +05:30
										 |  |  |   describe "::cleanup_logs" do | 
					
						
							| 
									
										
										
										
											2017-08-19 17:17:38 +05:30
										 |  |  |     let(:path) { (HOMEBREW_LOGS/"delete_me") } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-28 08:13:08 +00:00
										 |  |  |     before do | 
					
						
							| 
									
										
										
										
											2021-01-27 15:06:06 +00:00
										 |  |  |       path.mkpath | 
					
						
							| 
									
										
										
										
											2021-01-28 08:13:08 +00:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "cleans all logs if prune is 0" do | 
					
						
							| 
									
										
										
										
											2018-08-08 11:20:53 +02:00
										 |  |  |       described_class.new(days: 0).cleanup_logs | 
					
						
							| 
									
										
										
										
											2017-08-13 04:21:26 +05:30
										 |  |  |       expect(path).not_to exist | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-02-27 17:01:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-03 16:23:44 +00:00
										 |  |  |     it "cleans up logs if older than 30 days" do | 
					
						
							| 
									
										
										
										
											2019-01-21 21:35:24 +00:00
										 |  |  |       allow_any_instance_of(Pathname).to receive(:ctime).and_return(31.days.ago) | 
					
						
							| 
									
										
										
										
											2019-01-03 16:23:44 +00:00
										 |  |  |       allow_any_instance_of(Pathname).to receive(:mtime).and_return(31.days.ago) | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       cleanup.cleanup_logs | 
					
						
							| 
									
										
										
										
											2017-08-13 04:21:26 +05:30
										 |  |  |       expect(path).not_to exist | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-02-27 17:01:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-03 16:23:44 +00:00
										 |  |  |     it "does not clean up logs less than 30 days old" do | 
					
						
							| 
									
										
										
										
											2019-01-21 21:35:24 +00:00
										 |  |  |       allow_any_instance_of(Pathname).to receive(:ctime).and_return(15.days.ago) | 
					
						
							| 
									
										
										
										
											2019-01-03 16:23:44 +00:00
										 |  |  |       allow_any_instance_of(Pathname).to receive(:mtime).and_return(15.days.ago) | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       cleanup.cleanup_logs | 
					
						
							| 
									
										
										
										
											2017-08-13 04:21:26 +05:30
										 |  |  |       expect(path).to exist | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-02-27 17:01:22 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe "::cleanup_cache" do | 
					
						
							|  |  |  |     it "cleans up incomplete downloads" do | 
					
						
							|  |  |  |       incomplete = (HOMEBREW_CACHE/"something.incomplete") | 
					
						
							|  |  |  |       incomplete.mkpath | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       cleanup.cleanup_cache | 
					
						
							| 
									
										
										
										
											2017-02-27 17:01:22 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect(incomplete).not_to exist | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-03 18:59:53 +10:00
										 |  |  |     it "cleans up 'cargo_cache'" do | 
					
						
							|  |  |  |       cargo_cache = (HOMEBREW_CACHE/"cargo_cache") | 
					
						
							|  |  |  |       cargo_cache.mkpath | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       cleanup.cleanup_cache | 
					
						
							| 
									
										
										
										
											2018-09-03 18:59:53 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect(cargo_cache).not_to exist | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-29 11:31:41 +01:00
										 |  |  |     it "cleans up 'go_cache'" do | 
					
						
							|  |  |  |       go_cache = (HOMEBREW_CACHE/"go_cache") | 
					
						
							|  |  |  |       go_cache.mkpath | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       cleanup.cleanup_cache | 
					
						
							| 
									
										
										
										
											2018-08-29 11:31:41 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect(go_cache).not_to exist | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-13 04:21:26 +05:30
										 |  |  |     it "cleans up 'glide_home'" do | 
					
						
							|  |  |  |       glide_home = (HOMEBREW_CACHE/"glide_home") | 
					
						
							|  |  |  |       glide_home.mkpath | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       cleanup.cleanup_cache | 
					
						
							| 
									
										
										
										
											2017-08-13 04:21:26 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |       expect(glide_home).not_to exist | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-27 17:01:22 +01:00
										 |  |  |     it "cleans up 'java_cache'" do | 
					
						
							|  |  |  |       java_cache = (HOMEBREW_CACHE/"java_cache") | 
					
						
							|  |  |  |       java_cache.mkpath | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       cleanup.cleanup_cache | 
					
						
							| 
									
										
										
										
											2017-02-27 17:01:22 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect(java_cache).not_to exist | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "cleans up 'npm_cache'" do | 
					
						
							|  |  |  |       npm_cache = (HOMEBREW_CACHE/"npm_cache") | 
					
						
							|  |  |  |       npm_cache.mkpath | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       cleanup.cleanup_cache | 
					
						
							| 
									
										
										
										
											2017-02-27 17:01:22 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect(npm_cache).not_to exist | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-07-19 02:46:45 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-09 00:35:04 +02:00
										 |  |  |     it "cleans up 'gclient_cache'" do | 
					
						
							|  |  |  |       gclient_cache = (HOMEBREW_CACHE/"gclient_cache") | 
					
						
							|  |  |  |       gclient_cache.mkpath | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |       cleanup.cleanup_cache | 
					
						
							| 
									
										
										
										
											2018-08-09 00:35:04 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect(gclient_cache).not_to exist | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-04 05:47:05 +05:30
										 |  |  |     it "cleans up all files and directories" do | 
					
						
							|  |  |  |       git = (HOMEBREW_CACHE/"gist--git") | 
					
						
							|  |  |  |       gist = (HOMEBREW_CACHE/"gist") | 
					
						
							|  |  |  |       svn = (HOMEBREW_CACHE/"gist--svn") | 
					
						
							| 
									
										
										
										
											2017-08-13 04:21:26 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-04 05:47:05 +05:30
										 |  |  |       git.mkpath | 
					
						
							|  |  |  |       gist.mkpath | 
					
						
							|  |  |  |       FileUtils.touch svn | 
					
						
							| 
									
										
										
										
											2017-08-13 04:21:26 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-08 11:20:53 +02:00
										 |  |  |       described_class.new(days: 0).cleanup_cache | 
					
						
							| 
									
										
										
										
											2017-08-13 04:21:26 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |       expect(git).not_to exist | 
					
						
							|  |  |  |       expect(gist).to exist | 
					
						
							|  |  |  |       expect(svn).not_to exist | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "does not clean up directories that are not VCS checkouts" do | 
					
						
							|  |  |  |       git = (HOMEBREW_CACHE/"git") | 
					
						
							|  |  |  |       git.mkpath | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-08 11:20:53 +02:00
										 |  |  |       described_class.new(days: 0).cleanup_cache | 
					
						
							| 
									
										
										
										
											2017-08-13 04:21:26 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |       expect(git).to exist | 
					
						
							| 
									
										
										
										
											2017-08-04 05:47:05 +05:30
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-05 19:36:35 +05:30
										 |  |  |     it "cleans up VCS checkout directories with modified time < prune time" do | 
					
						
							|  |  |  |       foo = (HOMEBREW_CACHE/"--foo") | 
					
						
							|  |  |  |       foo.mkpath | 
					
						
							| 
									
										
										
										
											2019-01-21 21:35:24 +00:00
										 |  |  |       allow_any_instance_of(Pathname).to receive(:ctime).and_return(Time.now - 2 * 60 * 60 * 24) | 
					
						
							| 
									
										
										
										
											2018-08-08 09:43:38 +02:00
										 |  |  |       allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - 2 * 60 * 60 * 24) | 
					
						
							| 
									
										
										
										
											2018-08-08 11:20:53 +02:00
										 |  |  |       described_class.new(days: 1).cleanup_cache | 
					
						
							| 
									
										
										
										
											2017-08-13 04:21:26 +05:30
										 |  |  |       expect(foo).not_to exist | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "does not clean up VCS checkout directories with modified time >= prune time" do | 
					
						
							|  |  |  |       foo = (HOMEBREW_CACHE/"--foo") | 
					
						
							|  |  |  |       foo.mkpath | 
					
						
							| 
									
										
										
										
											2018-08-08 11:20:53 +02:00
										 |  |  |       described_class.new(days: 1).cleanup_cache | 
					
						
							| 
									
										
										
										
											2017-08-13 04:21:26 +05:30
										 |  |  |       expect(foo).to exist | 
					
						
							| 
									
										
										
										
											2017-08-05 19:36:35 +05:30
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-19 23:15:33 +00:00
										 |  |  |     context "when cleaning old files in HOMEBREW_CACHE" do | 
					
						
							| 
									
										
										
										
											2018-08-10 00:54:03 +02:00
										 |  |  |       let(:bottle) { (HOMEBREW_CACHE/"testball--0.0.1.tag.bottle.tar.gz") } | 
					
						
							| 
									
										
										
										
											2018-08-06 15:39:52 +02:00
										 |  |  |       let(:testball) { (HOMEBREW_CACHE/"testball--0.0.1") } | 
					
						
							| 
									
										
										
										
											2018-08-10 00:54:03 +02:00
										 |  |  |       let(:testball_resource) { (HOMEBREW_CACHE/"testball--rsrc--0.0.1.txt") } | 
					
						
							| 
									
										
										
										
											2017-08-08 00:25:01 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  |       before do | 
					
						
							| 
									
										
										
										
											2018-08-10 00:54:03 +02:00
										 |  |  |         FileUtils.touch bottle | 
					
						
							|  |  |  |         FileUtils.touch testball | 
					
						
							|  |  |  |         FileUtils.touch testball_resource | 
					
						
							| 
									
										
										
										
											2017-08-05 06:06:33 +05:30
										 |  |  |         (HOMEBREW_CELLAR/"testball"/"0.0.1").mkpath | 
					
						
							|  |  |  |         FileUtils.touch(CoreTap.instance.formula_dir/"testball.rb") | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it "cleans up file if outdated" do | 
					
						
							|  |  |  |         allow(Utils::Bottles).to receive(:file_outdated?).with(any_args).and_return(true) | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |         cleanup.cleanup_cache | 
					
						
							| 
									
										
										
										
											2017-08-08 00:25:01 +05:30
										 |  |  |         expect(bottle).not_to exist | 
					
						
							|  |  |  |         expect(testball).not_to exist | 
					
						
							| 
									
										
										
										
											2018-08-10 00:54:03 +02:00
										 |  |  |         expect(testball_resource).not_to exist | 
					
						
							| 
									
										
										
										
											2017-08-05 06:06:33 +05:30
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-08 11:20:53 +02:00
										 |  |  |       it "cleans up file if `scrub` is true and formula not installed" do | 
					
						
							|  |  |  |         described_class.new(scrub: true).cleanup_cache | 
					
						
							| 
									
										
										
										
											2017-08-08 00:25:01 +05:30
										 |  |  |         expect(bottle).not_to exist | 
					
						
							|  |  |  |         expect(testball).not_to exist | 
					
						
							| 
									
										
										
										
											2018-08-10 00:54:03 +02:00
										 |  |  |         expect(testball_resource).not_to exist | 
					
						
							| 
									
										
										
										
											2017-08-05 06:06:33 +05:30
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it "cleans up file if stale" do | 
					
						
							| 
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 |  |  |         cleanup.cleanup_cache | 
					
						
							| 
									
										
										
										
											2017-08-08 00:25:01 +05:30
										 |  |  |         expect(bottle).not_to exist | 
					
						
							|  |  |  |         expect(testball).not_to exist | 
					
						
							| 
									
										
										
										
											2018-08-10 00:54:03 +02:00
										 |  |  |         expect(testball_resource).not_to exist | 
					
						
							| 
									
										
										
										
											2017-07-19 02:46:45 +05:30
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-02-27 17:01:22 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | end |