mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Cleaner: do work in clean instead of constructor
This commit is contained in:
parent
3b24d9f0be
commit
9559e162b2
@ -1,21 +1,23 @@
|
|||||||
# Cleans a newly installed keg.
|
# Cleans a newly installed keg.
|
||||||
# By default:
|
# By default:
|
||||||
# * removes info files
|
|
||||||
# * removes .la files
|
# * removes .la files
|
||||||
# * removes empty directories
|
# * removes empty directories
|
||||||
# * sets permissions on executables
|
# * sets permissions on executables
|
||||||
class Cleaner
|
class Cleaner
|
||||||
|
|
||||||
# Create a cleaner for the given formula and clean its keg
|
# Create a cleaner for the given formula
|
||||||
def initialize f
|
def initialize f
|
||||||
ObserverPathnameExtension.reset_counts!
|
|
||||||
|
|
||||||
@f = f
|
@f = f
|
||||||
[f.bin, f.sbin, f.lib].select{ |d| d.exist? }.each{ |d| clean_dir d }
|
end
|
||||||
|
|
||||||
# Get rid of the directory file, so it no longer bother us at link stage.
|
# Clean the keg of formula @f
|
||||||
info_dir_file = f.info + 'dir'
|
def clean
|
||||||
if info_dir_file.file? and not f.skip_clean? info_dir_file
|
ObserverPathnameExtension.reset_counts!
|
||||||
|
[@f.bin, @f.sbin, @f.lib].select{ |d| d.exist? }.each{ |d| clean_dir d }
|
||||||
|
|
||||||
|
# Get rid of any info 'dir' files, so they don't conflict at the link stage
|
||||||
|
info_dir_file = @f.info + 'dir'
|
||||||
|
if info_dir_file.file? and not @f.skip_clean? info_dir_file
|
||||||
puts "rm #{info_dir_file}" if ARGV.verbose?
|
puts "rm #{info_dir_file}" if ARGV.verbose?
|
||||||
info_dir_file.unlink
|
info_dir_file.unlink
|
||||||
end
|
end
|
||||||
|
@ -490,7 +490,7 @@ class FormulaInstaller
|
|||||||
puts "in the formula."
|
puts "in the formula."
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
Cleaner.new f
|
Cleaner.new(f).clean
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
opoo "The cleaning step did not complete successfully"
|
opoo "The cleaning step did not complete successfully"
|
||||||
puts "Still, the installation was successful, so we will link it into your prefix"
|
puts "Still, the installation was successful, so we will link it into your prefix"
|
||||||
|
@ -20,7 +20,7 @@ class CleanerTests < Test::Unit::TestCase
|
|||||||
cp "#{TEST_FOLDER}/mach/a.out", @f.bin
|
cp "#{TEST_FOLDER}/mach/a.out", @f.bin
|
||||||
cp Dir["#{TEST_FOLDER}/mach/*.dylib"], @f.lib
|
cp Dir["#{TEST_FOLDER}/mach/*.dylib"], @f.lib
|
||||||
|
|
||||||
Cleaner.new @f
|
Cleaner.new(@f).clean
|
||||||
|
|
||||||
assert_equal 0100555, (@f.bin/'a.out').stat.mode
|
assert_equal 0100555, (@f.bin/'a.out').stat.mode
|
||||||
assert_equal 0100444, (@f.lib/'fat.dylib').stat.mode
|
assert_equal 0100444, (@f.lib/'fat.dylib').stat.mode
|
||||||
@ -29,7 +29,7 @@ class CleanerTests < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_prunes_prefix_if_empty
|
def test_prunes_prefix_if_empty
|
||||||
Cleaner.new @f
|
Cleaner.new(@f).clean
|
||||||
assert !@f.prefix.directory?
|
assert !@f.prefix.directory?
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ class CleanerTests < Test::Unit::TestCase
|
|||||||
subdir = @f.bin/'subdir'
|
subdir = @f.bin/'subdir'
|
||||||
subdir.mkpath
|
subdir.mkpath
|
||||||
|
|
||||||
Cleaner.new @f
|
Cleaner.new(@f).clean
|
||||||
|
|
||||||
assert !@f.bin.directory?
|
assert !@f.bin.directory?
|
||||||
assert !subdir.directory?
|
assert !subdir.directory?
|
||||||
@ -47,7 +47,7 @@ class CleanerTests < Test::Unit::TestCase
|
|||||||
@f.class.skip_clean 'bin'
|
@f.class.skip_clean 'bin'
|
||||||
@f.bin.mkpath
|
@f.bin.mkpath
|
||||||
|
|
||||||
Cleaner.new @f
|
Cleaner.new(@f).clean
|
||||||
|
|
||||||
assert @f.bin.directory?
|
assert @f.bin.directory?
|
||||||
end
|
end
|
||||||
@ -57,7 +57,7 @@ class CleanerTests < Test::Unit::TestCase
|
|||||||
subdir = @f.bin/'subdir'
|
subdir = @f.bin/'subdir'
|
||||||
subdir.mkpath
|
subdir.mkpath
|
||||||
|
|
||||||
Cleaner.new @f
|
Cleaner.new(@f).clean
|
||||||
|
|
||||||
assert @f.bin.directory?
|
assert @f.bin.directory?
|
||||||
assert subdir.directory?
|
assert subdir.directory?
|
||||||
@ -70,7 +70,7 @@ class CleanerTests < Test::Unit::TestCase
|
|||||||
dir.mkpath
|
dir.mkpath
|
||||||
ln_s dir.basename, symlink
|
ln_s dir.basename, symlink
|
||||||
|
|
||||||
Cleaner.new @f
|
Cleaner.new(@f).clean
|
||||||
|
|
||||||
assert !dir.exist?
|
assert !dir.exist?
|
||||||
assert !symlink.symlink?
|
assert !symlink.symlink?
|
||||||
@ -84,7 +84,7 @@ class CleanerTests < Test::Unit::TestCase
|
|||||||
dir.mkpath
|
dir.mkpath
|
||||||
ln_s dir.basename, symlink
|
ln_s dir.basename, symlink
|
||||||
|
|
||||||
Cleaner.new @f
|
Cleaner.new(@f).clean
|
||||||
|
|
||||||
assert !dir.exist?
|
assert !dir.exist?
|
||||||
assert !symlink.symlink?
|
assert !symlink.symlink?
|
||||||
@ -95,7 +95,7 @@ class CleanerTests < Test::Unit::TestCase
|
|||||||
symlink = @f.prefix/'symlink'
|
symlink = @f.prefix/'symlink'
|
||||||
ln_s 'target', symlink
|
ln_s 'target', symlink
|
||||||
|
|
||||||
Cleaner.new @f
|
Cleaner.new(@f).clean
|
||||||
|
|
||||||
assert !symlink.symlink?
|
assert !symlink.symlink?
|
||||||
end
|
end
|
||||||
@ -105,7 +105,7 @@ class CleanerTests < Test::Unit::TestCase
|
|||||||
symlink = @f.prefix/'symlink'
|
symlink = @f.prefix/'symlink'
|
||||||
ln_s 'target', symlink
|
ln_s 'target', symlink
|
||||||
|
|
||||||
Cleaner.new @f
|
Cleaner.new(@f).clean
|
||||||
|
|
||||||
assert symlink.symlink?
|
assert symlink.symlink?
|
||||||
end
|
end
|
||||||
@ -118,7 +118,7 @@ class CleanerTests < Test::Unit::TestCase
|
|||||||
dir.mkpath
|
dir.mkpath
|
||||||
ln_s dir.basename, symlink
|
ln_s dir.basename, symlink
|
||||||
|
|
||||||
Cleaner.new @f
|
Cleaner.new(@f).clean
|
||||||
|
|
||||||
assert !dir.exist?
|
assert !dir.exist?
|
||||||
assert symlink.symlink?
|
assert symlink.symlink?
|
||||||
@ -133,7 +133,7 @@ class CleanerTests < Test::Unit::TestCase
|
|||||||
dir.mkpath
|
dir.mkpath
|
||||||
ln_s dir.basename, symlink
|
ln_s dir.basename, symlink
|
||||||
|
|
||||||
Cleaner.new @f
|
Cleaner.new(@f).clean
|
||||||
|
|
||||||
assert !dir.exist?
|
assert !dir.exist?
|
||||||
assert symlink.symlink?
|
assert symlink.symlink?
|
||||||
@ -146,7 +146,7 @@ class CleanerTests < Test::Unit::TestCase
|
|||||||
@f.lib.mkpath
|
@f.lib.mkpath
|
||||||
touch file
|
touch file
|
||||||
|
|
||||||
Cleaner.new @f
|
Cleaner.new(@f).clean
|
||||||
|
|
||||||
assert !file.exist?
|
assert !file.exist?
|
||||||
end
|
end
|
||||||
@ -158,7 +158,7 @@ class CleanerTests < Test::Unit::TestCase
|
|||||||
@f.lib.mkpath
|
@f.lib.mkpath
|
||||||
touch file
|
touch file
|
||||||
|
|
||||||
Cleaner.new @f
|
Cleaner.new(@f).clean
|
||||||
|
|
||||||
assert file.exist?
|
assert file.exist?
|
||||||
end
|
end
|
||||||
@ -169,7 +169,7 @@ class CleanerTests < Test::Unit::TestCase
|
|||||||
@f.lib.mkpath
|
@f.lib.mkpath
|
||||||
touch file
|
touch file
|
||||||
|
|
||||||
Cleaner.new @f
|
Cleaner.new(@f).clean
|
||||||
|
|
||||||
assert !file.exist?
|
assert !file.exist?
|
||||||
end
|
end
|
||||||
@ -180,7 +180,7 @@ class CleanerTests < Test::Unit::TestCase
|
|||||||
|
|
||||||
dir.mkpath
|
dir.mkpath
|
||||||
|
|
||||||
Cleaner.new @f
|
Cleaner.new(@f).clean
|
||||||
|
|
||||||
assert dir.directory?
|
assert dir.directory?
|
||||||
end
|
end
|
||||||
@ -193,7 +193,7 @@ class CleanerTests < Test::Unit::TestCase
|
|||||||
dir1.mkpath
|
dir1.mkpath
|
||||||
dir2.mkpath
|
dir2.mkpath
|
||||||
|
|
||||||
Cleaner.new @f
|
Cleaner.new(@f).clean
|
||||||
|
|
||||||
assert dir1.exist?
|
assert dir1.exist?
|
||||||
assert !dir2.exist?
|
assert !dir2.exist?
|
||||||
|
Loading…
x
Reference in New Issue
Block a user