lib/vex/base/filesystem/fast_copy.rb in vex-0.4.2 vs lib/vex/base/filesystem/fast_copy.rb in vex-0.4.4
- old
+ new
@@ -2,11 +2,11 @@
# fast_copy a file: This hardlinks the source file to the destfile,
# if possible. src must refer to a file; dest must refer to a file
# or not exist at all.
def fast_copy(src, dest)
src_stat = File.stat(src)
- invalid_argument!(src) unless src_stat.file?
+ invalid_argument!(src, "This is not a file") unless src_stat.file?
dest_stat = begin
File.stat(dest)
rescue Errno::ENOENT
end
@@ -29,11 +29,10 @@
FileUtils.extend FileUtils::FastCopy
module FileUtils::FastCopy::Etest
def test_fast_copy
- assert File.exist?(__FILE__)
File.unlink("tmp/somedata.dat") if File.exist?("tmp/somedata.dat")
assert !File.exist?("tmp/somedata.dat")
FileUtils.fast_copy __FILE__, "tmp/somedata.dat"
assert_equal File.read("tmp/somedata.dat"), File.read(__FILE__)
@@ -56,6 +55,20 @@
assert_raise(Errno::ENOENT) {
FileUtils.fast_copy __FILE__, "tmp/nonexisting/dir"
}
end
+
+ def test_fast_copy_slow
+ File.touch("tmp/somedata.dat")
+ assert File.exist?("tmp/somedata.dat")
+
+ File.stubs(:stat).with(__FILE__).returns({ :file => true, :dev => 1 }.slop)
+ File.stubs(:stat).with("tmp/somedata.dat").returns({ :file => true, :dev => 2 }.slop)
+
+ FileUtils.expects(:copy).with(__FILE__, "tmp/somedata.dat")
+ FileUtils.fast_copy __FILE__, "tmp/somedata.dat"
+
+ File.unlink("tmp/somedata.dat")
+ end
+
end if VEX_TEST == "base"