cleanup: also consider ctime on prunes.
If this is an old tarball then we may end up removing it otherwise if we've respected the `mtime` from the server on download.
This commit is contained in:
parent
9519df379d
commit
79f3ff0a4e
@ -52,7 +52,7 @@ module CleanupRefinement
|
|||||||
|
|
||||||
return true if symlink? && !exist?
|
return true if symlink? && !exist?
|
||||||
|
|
||||||
mtime < days.days.ago
|
mtime < days.days.ago && ctime < days.days.ago
|
||||||
end
|
end
|
||||||
|
|
||||||
def stale?(scrub = false)
|
def stale?(scrub = false)
|
||||||
@ -124,7 +124,10 @@ module CleanupRefinement
|
|||||||
|
|
||||||
return true if scrub && !cask.versions.include?(cask.version)
|
return true if scrub && !cask.versions.include?(cask.version)
|
||||||
|
|
||||||
return mtime < CLEANUP_DEFAULT_DAYS.days.ago if cask.version.latest?
|
if cask.version.latest?
|
||||||
|
return mtime < CLEANUP_DEFAULT_DAYS.days.ago &&
|
||||||
|
ctime < CLEANUP_DEFAULT_DAYS.days.ago
|
||||||
|
end
|
||||||
|
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
@ -15,12 +15,13 @@ describe CleanupRefinement do
|
|||||||
path.mkpath
|
path.mkpath
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns true when path_modified_time < days_default" do
|
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)
|
allow_any_instance_of(Pathname).to receive(:mtime).and_return(2.days.ago)
|
||||||
expect(path.prune?(1)).to be true
|
expect(path.prune?(1)).to be true
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns false when path_modified_time >= days_default" do
|
it "returns false when ctime and mtime >= days_default" do
|
||||||
expect(path.prune?(2)).to be false
|
expect(path.prune?(2)).to be false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -181,7 +182,8 @@ describe Homebrew::Cleanup do
|
|||||||
it "removes the download for the latest version after 30 days" do
|
it "removes the download for the latest version after 30 days" do
|
||||||
download = Cask::Cache.path/"#{cask.token}--#{cask.version}"
|
download = Cask::Cache.path/"#{cask.token}--#{cask.version}"
|
||||||
|
|
||||||
FileUtils.touch download, mtime: 30.days.ago - 1.hour
|
allow(download).to receive(:ctime).and_return(30.days.ago - 1.hour)
|
||||||
|
allow(download).to receive(:mtime).and_return(30.days.ago - 1.hour)
|
||||||
|
|
||||||
subject.cleanup_cask(cask)
|
subject.cleanup_cask(cask)
|
||||||
|
|
||||||
@ -203,12 +205,14 @@ describe Homebrew::Cleanup do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "cleans up logs if older than 30 days" do
|
it "cleans up logs if older than 30 days" do
|
||||||
|
allow_any_instance_of(Pathname).to receive(:ctime).and_return(31.days.ago)
|
||||||
allow_any_instance_of(Pathname).to receive(:mtime).and_return(31.days.ago)
|
allow_any_instance_of(Pathname).to receive(:mtime).and_return(31.days.ago)
|
||||||
subject.cleanup_logs
|
subject.cleanup_logs
|
||||||
expect(path).not_to exist
|
expect(path).not_to exist
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not clean up logs less than 30 days old" do
|
it "does not clean up logs less than 30 days old" do
|
||||||
|
allow_any_instance_of(Pathname).to receive(:ctime).and_return(15.days.ago)
|
||||||
allow_any_instance_of(Pathname).to receive(:mtime).and_return(15.days.ago)
|
allow_any_instance_of(Pathname).to receive(:mtime).and_return(15.days.ago)
|
||||||
subject.cleanup_logs
|
subject.cleanup_logs
|
||||||
expect(path).to exist
|
expect(path).to exist
|
||||||
@ -307,6 +311,7 @@ describe Homebrew::Cleanup do
|
|||||||
it "cleans up VCS checkout directories with modified time < prune time" do
|
it "cleans up VCS checkout directories with modified time < prune time" do
|
||||||
foo = (HOMEBREW_CACHE/"--foo")
|
foo = (HOMEBREW_CACHE/"--foo")
|
||||||
foo.mkpath
|
foo.mkpath
|
||||||
|
allow_any_instance_of(Pathname).to receive(:ctime).and_return(Time.now - 2 * 60 * 60 * 24)
|
||||||
allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - 2 * 60 * 60 * 24)
|
allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - 2 * 60 * 60 * 24)
|
||||||
described_class.new(days: 1).cleanup_cache
|
described_class.new(days: 1).cleanup_cache
|
||||||
expect(foo).not_to exist
|
expect(foo).not_to exist
|
||||||
|
Loading…
x
Reference in New Issue
Block a user