aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
Diffstat (limited to 'Library')
-rw-r--r--Library/Formula/flac.rb2
-rw-r--r--Library/Homebrew/download_strategy.rb5
-rw-r--r--Library/Homebrew/pathname+yeast.rb23
-rwxr-xr-xLibrary/Homebrew/unittest.rb43
4 files changed, 57 insertions, 16 deletions
diff --git a/Library/Formula/flac.rb b/Library/Formula/flac.rb
index 1c8fc4b1a..eaca70344 100644
--- a/Library/Formula/flac.rb
+++ b/Library/Formula/flac.rb
@@ -21,8 +21,6 @@ class Flac <Formula
ENV['OBJ_FORMAT']='macho'
system "make install"
- (doc.parent+"#{@name}-#{@version}").mv doc
-
Flac2Mp3.new.brew {|f| bin.install 'flac2mp3'}
end
diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb
index 75dd60d36..341bdb765 100644
--- a/Library/Homebrew/download_strategy.rb
+++ b/Library/Homebrew/download_strategy.rb
@@ -55,7 +55,10 @@ class HttpDownloadStrategy <AbstractDownloadStrategy
else
# we are assuming it is not an archive, use original filename
# this behaviour is due to ScriptFileFormula expectations
- @dl.mv File.basename(@url)
+ # So I guess we should cp, but we mv, for this historic reason
+ # HOWEVER if this breaks some expectation you had we *will* change the
+ # behaviour, just open an issue at github
+ FileUtils.mv @dl, File.basename(@url)
end
end
private
diff --git a/Library/Homebrew/pathname+yeast.rb b/Library/Homebrew/pathname+yeast.rb
index a24532db1..091b0379f 100644
--- a/Library/Homebrew/pathname+yeast.rb
+++ b/Library/Homebrew/pathname+yeast.rb
@@ -25,16 +25,6 @@ require 'pathname'
# we enhance pathname to make our code more readable
class Pathname
- def mv dst
- FileUtils.mv to_s, dst
- end
-
- def rename newname
- dst=dirname+newname
- dst.unlink if dst.exist? and file?
- mv dst
- end
-
def install src
if src.is_a? Array
src.collect {|src| install src }
@@ -50,13 +40,14 @@ class Pathname
# this function when installing from the temporary build directory
FileUtils.mv src, to_s
end
- return self+src
+ src=Pathname.new src
+ return self+src.basename
end
end
# we assume this pathname object is a file obviously
def write content
- raise "Will not overwrite #{f}" if exist? and not ARGV.force?
+ raise "Will not overwrite #{to_s}" if exist? and not ARGV.force?
dirname.mkpath
File.open(self, 'w') {|f| f.write content }
end
@@ -67,6 +58,7 @@ class Pathname
else
FileUtils.cp_r to_s, dst
end
+ return dst
end
# extended to support the double extensions .tar.gz and .tar.bz2
@@ -86,8 +78,10 @@ class Pathname
# instead rely on good ol' libc and the filesystem
def rmdir_if_possible
rmdir
+ true
rescue SystemCallError => e
raise unless e.errno == Errno::ENOTEMPTY::Errno or e.errno == Errno::EACCES::Errno
+ false
end
def chmod_R perms
@@ -96,7 +90,10 @@ class Pathname
end
def abv
- `find #{to_s} -type f | wc -l`.strip+' files, '+`du -hd0 #{to_s} | cut -d"\t" -f1`.strip
+ out=''
+ n=`find #{to_s} -type f | wc -l`.to_i
+ out<<"#{n} files, " if n > 1
+ out<<`du -hd0 #{to_s} | cut -d"\t" -f1`.strip
end
def version
diff --git a/Library/Homebrew/unittest.rb b/Library/Homebrew/unittest.rb
index 7a3d70ac5..7943640fd 100755
--- a/Library/Homebrew/unittest.rb
+++ b/Library/Homebrew/unittest.rb
@@ -362,4 +362,47 @@ class BeerTasting <Test::Unit::TestCase
assert_equal 10.5, f-0.1
assert_equal 10.7, f+0.1
end
+
+ def test_pathname_plus_yeast
+ nostdout do
+ assert_nothing_raised do
+ assert !Pathname.getwd.rmdir_if_possible
+ assert !Pathname.getwd.abv.empty?
+
+ abcd=orig_abcd=HOMEBREW_CACHE+'abcd'
+ FileUtils.cp ABS__FILE__, abcd
+ abcd=HOMEBREW_PREFIX.install abcd
+ assert (HOMEBREW_PREFIX+orig_abcd.basename).exist?
+ assert abcd.exist?
+ assert_equal HOMEBREW_PREFIX+'abcd', abcd
+
+ assert_raises(RuntimeError) {abcd.write 'CONTENT'}
+ abcd.unlink
+ abcd.write 'HELLOWORLD'
+ assert_equal 'HELLOWORLD', File.read(abcd)
+
+ assert !orig_abcd.exist?
+ rv=abcd.cp orig_abcd
+ assert orig_abcd.exist?
+ assert_equal rv, orig_abcd
+
+ orig_abcd.unlink
+ assert !orig_abcd.exist?
+ abcd.cp HOMEBREW_CACHE
+ assert orig_abcd.exist?
+
+ foo1=HOMEBREW_CACHE+'foo-0.1.tar.gz'
+ FileUtils.cp ABS__FILE__, foo1
+ assert foo1.file?
+
+ assert_equal '.tar.gz', foo1.extname
+ assert_equal 'foo-0.1', foo1.stem
+ assert_equal '0.1', foo1.version
+
+ HOMEBREW_CACHE.chmod_R 0777
+ end
+ end
+
+ assert_raises(RuntimeError) {Pathname.getwd.install 'non_existant_file'}
+ end
end