2004-08-08 17:35:11 -04:00
|
|
|
# $Id$
|
2003-09-17 05:52:50 -04:00
|
|
|
|
|
|
|
require 'fileutils'
|
2009-09-11 05:53:50 -04:00
|
|
|
require_relative 'fileasserts'
|
2003-12-02 06:03:37 -05:00
|
|
|
require 'pathname'
|
2003-11-25 04:13:58 -05:00
|
|
|
require 'tmpdir'
|
|
|
|
require 'test/unit'
|
2003-09-17 05:52:50 -04:00
|
|
|
|
2003-12-23 21:26:44 -05:00
|
|
|
class TestFileUtils < Test::Unit::TestCase
|
|
|
|
TMPROOT = "#{Dir.tmpdir}/fileutils.rb.#{$$}"
|
2011-02-05 22:13:08 -05:00
|
|
|
include Test::Unit::FileAssertions
|
2003-12-23 21:26:44 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
prevdir = Dir.pwd
|
|
|
|
tmproot = TestFileUtils::TMPROOT
|
|
|
|
Dir.mkdir tmproot unless File.directory?(tmproot)
|
|
|
|
Dir.chdir tmproot
|
|
|
|
|
2003-11-20 05:16:27 -05:00
|
|
|
def have_drive_letter?
|
2008-10-04 09:25:12 -04:00
|
|
|
/mswin(?!ce)|mingw|bcc|emx/ =~ RUBY_PLATFORM
|
2003-09-26 20:44:50 -04:00
|
|
|
end
|
|
|
|
|
2003-11-20 05:16:27 -05:00
|
|
|
def have_file_perm?
|
2008-10-04 09:48:20 -04:00
|
|
|
/mswin|mingw|bcc|emx/ !~ RUBY_PLATFORM
|
2003-11-20 05:16:27 -05:00
|
|
|
end
|
|
|
|
|
2005-05-25 18:41:32 -04:00
|
|
|
$fileutils_rb_have_symlink = nil
|
|
|
|
|
2003-09-26 20:44:50 -04:00
|
|
|
def have_symlink?
|
2005-05-25 18:41:32 -04:00
|
|
|
if $fileutils_rb_have_symlink == nil
|
|
|
|
$fileutils_rb_have_symlink = check_have_symlink?
|
|
|
|
end
|
|
|
|
$fileutils_rb_have_symlink
|
2003-09-26 20:44:50 -04:00
|
|
|
end
|
|
|
|
|
2005-05-25 18:41:32 -04:00
|
|
|
def check_have_symlink?
|
|
|
|
File.symlink nil, nil
|
|
|
|
rescue NotImplementedError
|
|
|
|
return false
|
|
|
|
rescue
|
|
|
|
return true
|
2003-12-02 06:03:37 -05:00
|
|
|
end
|
2005-05-25 18:41:32 -04:00
|
|
|
|
|
|
|
$fileutils_rb_have_hardlink = nil
|
|
|
|
|
2003-12-02 06:03:37 -05:00
|
|
|
def have_hardlink?
|
2005-05-25 18:41:32 -04:00
|
|
|
if $fileutils_rb_have_hardlink == nil
|
|
|
|
$fileutils_rb_have_hardlink = check_have_hardlink?
|
|
|
|
end
|
|
|
|
$fileutils_rb_have_hardlink
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_have_hardlink?
|
|
|
|
File.link nil, nil
|
|
|
|
rescue NotImplementedError
|
|
|
|
return false
|
|
|
|
rescue
|
|
|
|
return true
|
2003-12-02 06:03:37 -05:00
|
|
|
end
|
|
|
|
|
2004-05-07 08:04:19 -04:00
|
|
|
begin
|
|
|
|
Dir.mkdir("\n")
|
|
|
|
Dir.rmdir("\n")
|
|
|
|
def lf_in_path_allowed?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
rescue
|
|
|
|
def lf_in_path_allowed?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2003-12-23 21:26:44 -05:00
|
|
|
Dir.chdir prevdir
|
|
|
|
Dir.rmdir tmproot
|
|
|
|
|
|
|
|
class TestFileUtils
|
2003-09-17 05:52:50 -04:00
|
|
|
|
|
|
|
include FileUtils
|
|
|
|
|
2005-09-18 16:59:29 -04:00
|
|
|
def check_singleton(name)
|
2010-05-04 05:38:21 -04:00
|
|
|
assert_respond_to ::FileUtils, name
|
2005-09-18 16:59:29 -04:00
|
|
|
end
|
|
|
|
|
2004-12-27 01:29:34 -05:00
|
|
|
def my_rm_rf(path)
|
2003-09-17 05:52:50 -04:00
|
|
|
if File.exist?('/bin/rm')
|
2003-11-25 06:02:30 -05:00
|
|
|
system %Q[/bin/rm -rf "#{path}"]
|
2003-09-17 05:52:50 -04:00
|
|
|
else
|
2003-09-26 20:44:50 -04:00
|
|
|
FileUtils.rm_rf path
|
2003-09-17 05:52:50 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-01-26 10:03:37 -05:00
|
|
|
def mymkdir(path)
|
|
|
|
Dir.mkdir path
|
|
|
|
File.chown nil, Process.gid, path if have_file_perm?
|
|
|
|
end
|
|
|
|
|
2003-09-17 05:52:50 -04:00
|
|
|
def setup
|
2003-11-25 04:13:58 -05:00
|
|
|
@prevdir = Dir.pwd
|
2004-02-12 15:21:24 -05:00
|
|
|
tmproot = TMPROOT
|
2005-01-26 10:03:37 -05:00
|
|
|
mymkdir tmproot unless File.directory?(tmproot)
|
2003-11-25 06:02:30 -05:00
|
|
|
Dir.chdir tmproot
|
2005-01-26 10:13:03 -05:00
|
|
|
my_rm_rf 'data'; mymkdir 'data'
|
|
|
|
my_rm_rf 'tmp'; mymkdir 'tmp'
|
2003-09-17 05:52:50 -04:00
|
|
|
prepare_data_file
|
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
2003-11-25 04:13:58 -05:00
|
|
|
Dir.chdir @prevdir
|
2012-08-21 07:32:18 -04:00
|
|
|
my_rm_rf TMPROOT
|
2003-09-17 05:52:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2004-08-08 17:35:11 -04:00
|
|
|
TARGETS = %w( data/a data/all data/random data/zero )
|
2003-09-17 05:52:50 -04:00
|
|
|
|
|
|
|
def prepare_data_file
|
2004-08-08 17:35:11 -04:00
|
|
|
File.open('data/a', 'w') {|f|
|
2003-09-17 05:52:50 -04:00
|
|
|
32.times do
|
2004-08-08 17:35:11 -04:00
|
|
|
f.puts 'a' * 50
|
2003-09-17 05:52:50 -04:00
|
|
|
end
|
|
|
|
}
|
|
|
|
|
|
|
|
all_chars = (0..255).map {|n| n.chr }.join('')
|
|
|
|
File.open('data/all', 'w') {|f|
|
|
|
|
32.times do
|
|
|
|
f.puts all_chars
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
|
|
|
random_chars = (0...50).map { rand(256).chr }.join('')
|
|
|
|
File.open('data/random', 'w') {|f|
|
|
|
|
32.times do
|
|
|
|
f.puts random_chars
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
|
|
|
File.open('data/zero', 'w') {|f|
|
|
|
|
;
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
BIGFILE = 'data/big'
|
|
|
|
|
|
|
|
def prepare_big_file
|
|
|
|
File.open('data/big', 'w') {|f|
|
|
|
|
(4 * 1024 * 1024 / 256).times do # 4MB
|
|
|
|
f.print "aaaa aaaa aaaa aaaa aaaa aaaa aaaa aaaa aaaa aaaa\n"
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def prepare_time_data
|
|
|
|
File.open('data/old', 'w') {|f| f.puts 'dummy' }
|
|
|
|
File.open('data/newer', 'w') {|f| f.puts 'dummy' }
|
|
|
|
File.open('data/newest', 'w') {|f| f.puts 'dummy' }
|
|
|
|
t = Time.now
|
|
|
|
File.utime t-8, t-8, 'data/old'
|
|
|
|
File.utime t-4, t-4, 'data/newer'
|
|
|
|
end
|
|
|
|
|
2005-04-14 06:00:52 -04:00
|
|
|
def each_srcdest
|
|
|
|
TARGETS.each do |path|
|
|
|
|
yield path, "tmp/#{File.basename(path)}"
|
2005-01-01 02:22:04 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Test Cases
|
|
|
|
#
|
|
|
|
|
2003-09-17 05:52:50 -04:00
|
|
|
def test_pwd
|
2005-09-18 16:59:29 -04:00
|
|
|
check_singleton :pwd
|
|
|
|
|
2003-09-17 05:52:50 -04:00
|
|
|
assert_equal Dir.pwd, pwd()
|
2003-09-26 20:44:50 -04:00
|
|
|
|
|
|
|
cwd = Dir.pwd
|
2009-09-17 22:20:39 -04:00
|
|
|
root = have_drive_letter? ? 'C:/' : '/'
|
|
|
|
cd(root) {
|
|
|
|
assert_equal root, pwd()
|
2003-09-26 20:44:50 -04:00
|
|
|
}
|
|
|
|
assert_equal cwd, pwd()
|
2003-09-17 05:52:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_cmp
|
2005-09-18 16:59:29 -04:00
|
|
|
check_singleton :cmp
|
|
|
|
|
2003-09-17 05:52:50 -04:00
|
|
|
TARGETS.each do |fname|
|
|
|
|
assert cmp(fname, fname), 'not same?'
|
|
|
|
end
|
2008-09-24 13:44:39 -04:00
|
|
|
assert_raise(ArgumentError) {
|
2003-09-17 05:52:50 -04:00
|
|
|
cmp TARGETS[0], TARGETS[0], :undefinedoption => true
|
|
|
|
}
|
2003-12-02 06:03:37 -05:00
|
|
|
|
|
|
|
# pathname
|
|
|
|
touch 'tmp/cmptmp'
|
|
|
|
assert_nothing_raised {
|
|
|
|
cmp Pathname.new('tmp/cmptmp'), 'tmp/cmptmp'
|
|
|
|
cmp 'tmp/cmptmp', Pathname.new('tmp/cmptmp')
|
|
|
|
cmp Pathname.new('tmp/cmptmp'), Pathname.new('tmp/cmptmp')
|
|
|
|
}
|
2003-09-17 05:52:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_cp
|
2005-09-18 16:59:29 -04:00
|
|
|
check_singleton :cp
|
|
|
|
|
2005-04-14 06:00:52 -04:00
|
|
|
each_srcdest do |srcpath, destpath|
|
2005-01-01 02:22:04 -05:00
|
|
|
cp srcpath, destpath
|
|
|
|
assert_same_file srcpath, destpath
|
2003-09-17 05:52:50 -04:00
|
|
|
|
2005-01-01 02:22:04 -05:00
|
|
|
cp srcpath, File.dirname(destpath)
|
|
|
|
assert_same_file srcpath, destpath
|
2003-09-17 05:52:50 -04:00
|
|
|
|
2005-01-01 02:22:04 -05:00
|
|
|
cp srcpath, File.dirname(destpath) + '/'
|
|
|
|
assert_same_file srcpath, destpath
|
2003-12-12 05:33:24 -05:00
|
|
|
|
2005-01-01 02:22:04 -05:00
|
|
|
cp srcpath, destpath, :preserve => true
|
|
|
|
assert_same_file srcpath, destpath
|
|
|
|
assert_same_entry srcpath, destpath
|
2003-09-17 05:52:50 -04:00
|
|
|
end
|
2003-11-18 00:09:20 -05:00
|
|
|
|
2009-09-09 09:02:04 -04:00
|
|
|
assert_raise(Errno::ENOENT) {
|
|
|
|
cp 'tmp/cptmp', 'tmp/cptmp_new'
|
|
|
|
}
|
|
|
|
assert_file_not_exist('tmp/cptmp_new')
|
|
|
|
|
2003-12-01 00:18:46 -05:00
|
|
|
# src==dest (1) same path
|
2003-11-18 00:09:20 -05:00
|
|
|
touch 'tmp/cptmp'
|
2008-09-24 13:44:39 -04:00
|
|
|
assert_raise(ArgumentError) {
|
2003-11-18 00:09:20 -05:00
|
|
|
cp 'tmp/cptmp', 'tmp/cptmp'
|
|
|
|
}
|
2009-09-17 22:20:39 -04:00
|
|
|
end
|
|
|
|
|
2011-03-17 19:48:13 -04:00
|
|
|
def test_cp_preserve_permissions
|
|
|
|
bug4507 = '[ruby-core:35518]'
|
|
|
|
touch 'tmp/cptmp'
|
|
|
|
chmod 0755, 'tmp/cptmp'
|
|
|
|
cp 'tmp/cptmp', 'tmp/cptmp2'
|
|
|
|
assert_equal(File.stat('tmp/cptmp').mode,
|
|
|
|
File.stat('tmp/cptmp2').mode,
|
|
|
|
bug4507)
|
|
|
|
end
|
|
|
|
|
2013-02-01 22:54:00 -05:00
|
|
|
def test_cp_preserve_permissions_dir
|
|
|
|
bug7246 = '[ruby-core:48603]'
|
|
|
|
mkdir 'tmp/cptmp'
|
|
|
|
mkdir 'tmp/cptmp/d1'
|
|
|
|
chmod 0745, 'tmp/cptmp/d1'
|
|
|
|
mkdir 'tmp/cptmp/d2'
|
|
|
|
chmod 0700, 'tmp/cptmp/d2'
|
|
|
|
cp_r 'tmp/cptmp', 'tmp/cptmp2', :preserve => true
|
|
|
|
assert_equal(File.stat('tmp/cptmp/d1').mode,
|
|
|
|
File.stat('tmp/cptmp2/d1').mode,
|
|
|
|
bug7246)
|
|
|
|
assert_equal(File.stat('tmp/cptmp/d2').mode,
|
|
|
|
File.stat('tmp/cptmp2/d2').mode,
|
|
|
|
bug7246)
|
|
|
|
end
|
|
|
|
|
2009-09-17 22:20:39 -04:00
|
|
|
def test_cp_symlink
|
|
|
|
touch 'tmp/cptmp'
|
2003-12-01 00:18:46 -05:00
|
|
|
# src==dest (2) symlink and its target
|
2003-11-18 05:05:21 -05:00
|
|
|
File.symlink 'cptmp', 'tmp/cptmp_symlink'
|
2008-09-24 13:44:39 -04:00
|
|
|
assert_raise(ArgumentError) {
|
2003-11-18 00:09:20 -05:00
|
|
|
cp 'tmp/cptmp', 'tmp/cptmp_symlink'
|
|
|
|
}
|
2008-09-24 13:44:39 -04:00
|
|
|
assert_raise(ArgumentError) {
|
2003-12-01 00:18:46 -05:00
|
|
|
cp 'tmp/cptmp_symlink', 'tmp/cptmp'
|
|
|
|
}
|
|
|
|
# src==dest (3) looped symlink
|
2003-11-18 05:05:21 -05:00
|
|
|
File.symlink 'symlink', 'tmp/symlink'
|
2008-09-24 13:44:39 -04:00
|
|
|
assert_raise(Errno::ELOOP) {
|
2003-11-18 00:09:20 -05:00
|
|
|
cp 'tmp/symlink', 'tmp/symlink'
|
|
|
|
}
|
2009-09-17 22:20:39 -04:00
|
|
|
end if have_symlink?
|
2003-12-02 06:03:37 -05:00
|
|
|
|
2009-09-17 22:20:39 -04:00
|
|
|
def test_cp_pathname
|
2003-12-02 06:03:37 -05:00
|
|
|
# pathname
|
2009-09-17 22:20:39 -04:00
|
|
|
touch 'tmp/cptmp'
|
2003-12-02 06:03:37 -05:00
|
|
|
assert_nothing_raised {
|
|
|
|
cp 'tmp/cptmp', Pathname.new('tmp/tmpdest')
|
|
|
|
cp Pathname.new('tmp/cptmp'), 'tmp/tmpdest'
|
|
|
|
cp Pathname.new('tmp/cptmp'), Pathname.new('tmp/tmpdest')
|
|
|
|
mkdir 'tmp/tmpdir'
|
|
|
|
cp ['tmp/cptmp', 'tmp/tmpdest'], Pathname.new('tmp/tmpdir')
|
|
|
|
}
|
2003-09-17 05:52:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_cp_r
|
2005-09-18 16:59:29 -04:00
|
|
|
check_singleton :cp_r
|
|
|
|
|
2003-09-17 05:52:50 -04:00
|
|
|
cp_r 'data', 'tmp'
|
|
|
|
TARGETS.each do |fname|
|
|
|
|
assert_same_file fname, "tmp/#{fname}"
|
|
|
|
end
|
2003-12-02 06:03:37 -05:00
|
|
|
|
2004-08-08 17:35:11 -04:00
|
|
|
cp_r 'data', 'tmp2', :preserve => true
|
|
|
|
TARGETS.each do |fname|
|
2004-12-27 01:29:34 -05:00
|
|
|
assert_same_entry fname, "tmp2/#{File.basename(fname)}"
|
|
|
|
assert_same_file fname, "tmp2/#{File.basename(fname)}"
|
2004-08-08 17:35:11 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
# a/* -> b/*
|
|
|
|
mkdir 'tmp/cpr_src'
|
|
|
|
mkdir 'tmp/cpr_dest'
|
|
|
|
File.open('tmp/cpr_src/a', 'w') {|f| f.puts 'a' }
|
|
|
|
File.open('tmp/cpr_src/b', 'w') {|f| f.puts 'b' }
|
|
|
|
File.open('tmp/cpr_src/c', 'w') {|f| f.puts 'c' }
|
|
|
|
mkdir 'tmp/cpr_src/d'
|
|
|
|
cp_r 'tmp/cpr_src/.', 'tmp/cpr_dest'
|
|
|
|
assert_same_file 'tmp/cpr_src/a', 'tmp/cpr_dest/a'
|
|
|
|
assert_same_file 'tmp/cpr_src/b', 'tmp/cpr_dest/b'
|
|
|
|
assert_same_file 'tmp/cpr_src/c', 'tmp/cpr_dest/c'
|
|
|
|
assert_directory 'tmp/cpr_dest/d'
|
2005-05-25 18:41:32 -04:00
|
|
|
my_rm_rf 'tmp/cpr_src'
|
|
|
|
my_rm_rf 'tmp/cpr_dest'
|
2010-07-19 23:27:59 -04:00
|
|
|
|
|
|
|
bug3588 = '[ruby-core:31360]'
|
|
|
|
assert_nothing_raised(ArgumentError, bug3588) do
|
|
|
|
cp_r 'tmp', 'tmp2'
|
|
|
|
end
|
|
|
|
assert_directory 'tmp2/tmp'
|
|
|
|
assert_raise(ArgumentError, bug3588) do
|
|
|
|
cp_r 'tmp2', 'tmp2/new_tmp2'
|
|
|
|
end
|
2009-09-17 22:20:39 -04:00
|
|
|
end
|
2004-08-08 17:35:11 -04:00
|
|
|
|
2009-09-17 22:20:39 -04:00
|
|
|
def test_cp_r_symlink
|
2004-08-08 17:35:11 -04:00
|
|
|
# symlink in a directory
|
|
|
|
mkdir 'tmp/cpr_src'
|
|
|
|
ln_s 'SLdest', 'tmp/cpr_src/symlink'
|
|
|
|
cp_r 'tmp/cpr_src', 'tmp/cpr_dest'
|
|
|
|
assert_symlink 'tmp/cpr_dest/symlink'
|
|
|
|
assert_equal 'SLdest', File.readlink('tmp/cpr_dest/symlink')
|
|
|
|
|
|
|
|
# root is a symlink
|
|
|
|
ln_s 'cpr_src', 'tmp/cpr_src2'
|
|
|
|
cp_r 'tmp/cpr_src2', 'tmp/cpr_dest2'
|
|
|
|
assert_directory 'tmp/cpr_dest2'
|
2010-04-29 08:56:41 -04:00
|
|
|
assert_not_symlink 'tmp/cpr_dest2'
|
2004-08-08 17:35:11 -04:00
|
|
|
assert_symlink 'tmp/cpr_dest2/symlink'
|
|
|
|
assert_equal 'SLdest', File.readlink('tmp/cpr_dest2/symlink')
|
2009-09-17 22:20:39 -04:00
|
|
|
end if have_symlink?
|
2004-08-08 17:35:11 -04:00
|
|
|
|
2012-04-30 10:37:54 -04:00
|
|
|
def test_cp_r_symlink_preserve
|
|
|
|
mkdir 'tmp/cross'
|
|
|
|
mkdir 'tmp/cross/a'
|
|
|
|
mkdir 'tmp/cross/b'
|
|
|
|
touch 'tmp/cross/a/f'
|
|
|
|
touch 'tmp/cross/b/f'
|
|
|
|
ln_s '../a/f', 'tmp/cross/b/l'
|
|
|
|
ln_s '../b/f', 'tmp/cross/a/l'
|
2012-04-30 10:45:31 -04:00
|
|
|
assert_nothing_raised {
|
|
|
|
cp_r 'tmp/cross', 'tmp/cross2', :preserve => true
|
|
|
|
}
|
2012-04-30 10:37:54 -04:00
|
|
|
end if have_symlink?
|
|
|
|
|
2009-09-17 22:20:39 -04:00
|
|
|
def test_cp_r_pathname
|
2003-12-02 06:03:37 -05:00
|
|
|
# pathname
|
|
|
|
touch 'tmp/cprtmp'
|
|
|
|
assert_nothing_raised {
|
|
|
|
cp_r Pathname.new('tmp/cprtmp'), 'tmp/tmpdest'
|
|
|
|
cp_r 'tmp/cprtmp', Pathname.new('tmp/tmpdest')
|
|
|
|
cp_r Pathname.new('tmp/cprtmp'), Pathname.new('tmp/tmpdest')
|
|
|
|
}
|
2003-09-17 05:52:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_mv
|
2005-09-18 16:59:29 -04:00
|
|
|
check_singleton :mv
|
|
|
|
|
2003-12-12 05:33:24 -05:00
|
|
|
mkdir 'tmp/dest'
|
2003-09-17 05:52:50 -04:00
|
|
|
TARGETS.each do |fname|
|
|
|
|
cp fname, 'tmp/mvsrc'
|
|
|
|
mv 'tmp/mvsrc', 'tmp/mvdest'
|
|
|
|
assert_same_file fname, 'tmp/mvdest'
|
2003-12-12 05:33:24 -05:00
|
|
|
|
|
|
|
mv 'tmp/mvdest', 'tmp/dest/'
|
|
|
|
assert_same_file fname, 'tmp/dest/mvdest'
|
|
|
|
|
|
|
|
mv 'tmp/dest/mvdest', 'tmp'
|
|
|
|
assert_same_file fname, 'tmp/mvdest'
|
2003-09-17 05:52:50 -04:00
|
|
|
end
|
2003-11-18 00:09:20 -05:00
|
|
|
|
2004-12-27 01:29:34 -05:00
|
|
|
mkdir 'tmp/tmpdir'
|
|
|
|
mkdir_p 'tmp/dest2/tmpdir'
|
2008-09-24 13:44:39 -04:00
|
|
|
assert_raise(Errno::EEXIST) {
|
2004-12-27 01:29:34 -05:00
|
|
|
mv 'tmp/tmpdir', 'tmp/dest2'
|
|
|
|
}
|
|
|
|
mkdir 'tmp/dest2/tmpdir/junk'
|
2008-09-24 13:44:39 -04:00
|
|
|
assert_raise(Errno::EEXIST, "[ruby-talk:124368]") {
|
2004-12-27 01:29:34 -05:00
|
|
|
mv 'tmp/tmpdir', 'tmp/dest2'
|
|
|
|
}
|
|
|
|
|
2003-12-01 00:18:46 -05:00
|
|
|
# src==dest (1) same path
|
2003-11-18 00:09:20 -05:00
|
|
|
touch 'tmp/cptmp'
|
2008-09-24 13:44:39 -04:00
|
|
|
assert_raise(ArgumentError) {
|
2003-11-18 00:09:20 -05:00
|
|
|
mv 'tmp/cptmp', 'tmp/cptmp'
|
|
|
|
}
|
2009-09-17 22:20:39 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_mv_symlink
|
|
|
|
touch 'tmp/cptmp'
|
2003-12-01 00:18:46 -05:00
|
|
|
# src==dest (2) symlink and its target
|
2003-11-18 05:05:21 -05:00
|
|
|
File.symlink 'cptmp', 'tmp/cptmp_symlink'
|
2008-09-24 13:44:39 -04:00
|
|
|
assert_raise(ArgumentError) {
|
2003-11-18 00:09:20 -05:00
|
|
|
mv 'tmp/cptmp', 'tmp/cptmp_symlink'
|
|
|
|
}
|
2008-09-24 13:44:39 -04:00
|
|
|
assert_raise(ArgumentError) {
|
2003-12-01 00:18:46 -05:00
|
|
|
mv 'tmp/cptmp_symlink', 'tmp/cptmp'
|
|
|
|
}
|
|
|
|
# src==dest (3) looped symlink
|
2003-11-18 05:05:21 -05:00
|
|
|
File.symlink 'symlink', 'tmp/symlink'
|
2008-09-24 13:44:39 -04:00
|
|
|
assert_raise(Errno::ELOOP) {
|
2003-11-18 00:09:20 -05:00
|
|
|
mv 'tmp/symlink', 'tmp/symlink'
|
|
|
|
}
|
2009-09-17 22:20:39 -04:00
|
|
|
end if have_symlink?
|
2003-12-02 06:03:37 -05:00
|
|
|
|
2009-09-17 22:20:39 -04:00
|
|
|
def test_mv_pathname
|
2003-12-02 06:03:37 -05:00
|
|
|
# pathname
|
|
|
|
assert_nothing_raised {
|
|
|
|
touch 'tmp/mvtmpsrc'
|
|
|
|
mv Pathname.new('tmp/mvtmpsrc'), 'tmp/mvtmpdest'
|
|
|
|
touch 'tmp/mvtmpsrc'
|
|
|
|
mv 'tmp/mvtmpsrc', Pathname.new('tmp/mvtmpdest')
|
|
|
|
touch 'tmp/mvtmpsrc'
|
|
|
|
mv Pathname.new('tmp/mvtmpsrc'), Pathname.new('tmp/mvtmpdest')
|
|
|
|
}
|
2003-09-17 05:52:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_rm
|
2005-09-18 16:59:29 -04:00
|
|
|
check_singleton :rm
|
|
|
|
|
2003-09-17 05:52:50 -04:00
|
|
|
TARGETS.each do |fname|
|
|
|
|
cp fname, 'tmp/rmsrc'
|
|
|
|
rm 'tmp/rmsrc'
|
|
|
|
assert_file_not_exist 'tmp/rmsrc'
|
|
|
|
end
|
2003-12-02 06:03:37 -05:00
|
|
|
|
|
|
|
# pathname
|
|
|
|
touch 'tmp/rmtmp1'
|
|
|
|
touch 'tmp/rmtmp2'
|
|
|
|
touch 'tmp/rmtmp3'
|
|
|
|
assert_nothing_raised {
|
|
|
|
rm Pathname.new('tmp/rmtmp1')
|
|
|
|
rm [Pathname.new('tmp/rmtmp2'), Pathname.new('tmp/rmtmp3')]
|
|
|
|
}
|
|
|
|
assert_file_not_exist 'tmp/rmtmp1'
|
|
|
|
assert_file_not_exist 'tmp/rmtmp2'
|
|
|
|
assert_file_not_exist 'tmp/rmtmp3'
|
2003-09-17 05:52:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_rm_f
|
2005-09-18 16:59:29 -04:00
|
|
|
check_singleton :rm_f
|
|
|
|
|
2003-09-17 05:52:50 -04:00
|
|
|
TARGETS.each do |fname|
|
|
|
|
cp fname, 'tmp/rmsrc'
|
|
|
|
rm_f 'tmp/rmsrc'
|
|
|
|
assert_file_not_exist 'tmp/rmsrc'
|
|
|
|
end
|
2009-09-17 22:20:39 -04:00
|
|
|
end
|
2003-09-17 05:52:50 -04:00
|
|
|
|
2009-09-17 22:20:39 -04:00
|
|
|
def test_rm_symlink
|
2003-09-17 05:52:50 -04:00
|
|
|
File.open('tmp/lnf_symlink_src', 'w') {|f| f.puts 'dummy' }
|
|
|
|
File.symlink 'tmp/lnf_symlink_src', 'tmp/lnf_symlink_dest'
|
|
|
|
rm_f 'tmp/lnf_symlink_dest'
|
|
|
|
assert_file_not_exist 'tmp/lnf_symlink_dest'
|
|
|
|
assert_file_exist 'tmp/lnf_symlink_src'
|
|
|
|
|
|
|
|
rm_f 'notexistdatafile'
|
|
|
|
rm_f 'tmp/notexistdatafile'
|
|
|
|
my_rm_rf 'tmpdatadir'
|
|
|
|
Dir.mkdir 'tmpdatadir'
|
|
|
|
# rm_f 'tmpdatadir'
|
|
|
|
Dir.rmdir 'tmpdatadir'
|
2009-09-17 22:20:39 -04:00
|
|
|
end if have_symlink?
|
2003-12-02 06:03:37 -05:00
|
|
|
|
2009-09-17 22:20:39 -04:00
|
|
|
def test_rm_f_2
|
2004-05-02 08:57:31 -04:00
|
|
|
Dir.mkdir 'tmp/tmpdir'
|
|
|
|
File.open('tmp/tmpdir/a', 'w') {|f| f.puts 'dummy' }
|
|
|
|
File.open('tmp/tmpdir/c', 'w') {|f| f.puts 'dummy' }
|
|
|
|
rm_f ['tmp/tmpdir/a', 'tmp/tmpdir/b', 'tmp/tmpdir/c']
|
|
|
|
assert_file_not_exist 'tmp/tmpdir/a'
|
|
|
|
assert_file_not_exist 'tmp/tmpdir/c'
|
|
|
|
Dir.rmdir 'tmp/tmpdir'
|
2009-09-17 22:20:39 -04:00
|
|
|
end
|
2004-05-02 08:57:31 -04:00
|
|
|
|
2009-09-17 22:20:39 -04:00
|
|
|
def test_rm_pathname
|
2003-12-02 06:03:37 -05:00
|
|
|
# pathname
|
|
|
|
touch 'tmp/rmtmp1'
|
|
|
|
touch 'tmp/rmtmp2'
|
|
|
|
touch 'tmp/rmtmp3'
|
|
|
|
touch 'tmp/rmtmp4'
|
|
|
|
assert_nothing_raised {
|
|
|
|
rm_f Pathname.new('tmp/rmtmp1')
|
|
|
|
rm_f [Pathname.new('tmp/rmtmp2'), Pathname.new('tmp/rmtmp3')]
|
|
|
|
}
|
|
|
|
assert_file_not_exist 'tmp/rmtmp1'
|
|
|
|
assert_file_not_exist 'tmp/rmtmp2'
|
|
|
|
assert_file_not_exist 'tmp/rmtmp3'
|
|
|
|
assert_file_exist 'tmp/rmtmp4'
|
2009-09-17 18:08:32 -04:00
|
|
|
|
|
|
|
# [ruby-dev:39345]
|
|
|
|
touch 'tmp/[rmtmp]'
|
2009-12-13 22:19:51 -05:00
|
|
|
FileUtils.rm_f 'tmp/[rmtmp]'
|
2009-09-17 18:08:32 -04:00
|
|
|
assert_file_not_exist 'tmp/[rmtmp]'
|
2003-09-17 05:52:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_rm_r
|
2005-09-18 16:59:29 -04:00
|
|
|
check_singleton :rm_r
|
|
|
|
|
2003-09-17 05:52:50 -04:00
|
|
|
my_rm_rf 'tmpdatadir'
|
|
|
|
|
|
|
|
Dir.mkdir 'tmpdatadir'
|
|
|
|
rm_r 'tmpdatadir'
|
|
|
|
assert_file_not_exist 'tmpdatadir'
|
|
|
|
|
|
|
|
Dir.mkdir 'tmpdatadir'
|
|
|
|
rm_r 'tmpdatadir/'
|
|
|
|
assert_file_not_exist 'tmpdatadir'
|
|
|
|
|
|
|
|
Dir.mkdir 'tmp/tmpdir'
|
|
|
|
rm_r 'tmp/tmpdir/'
|
|
|
|
assert_file_not_exist 'tmp/tmpdir'
|
|
|
|
assert_file_exist 'tmp'
|
|
|
|
|
|
|
|
Dir.mkdir 'tmp/tmpdir'
|
|
|
|
rm_r 'tmp/tmpdir'
|
|
|
|
assert_file_not_exist 'tmp/tmpdir'
|
|
|
|
assert_file_exist 'tmp'
|
|
|
|
|
|
|
|
Dir.mkdir 'tmp/tmpdir'
|
|
|
|
File.open('tmp/tmpdir/a', 'w') {|f| f.puts 'dummy' }
|
|
|
|
File.open('tmp/tmpdir/b', 'w') {|f| f.puts 'dummy' }
|
|
|
|
File.open('tmp/tmpdir/c', 'w') {|f| f.puts 'dummy' }
|
|
|
|
rm_r 'tmp/tmpdir'
|
|
|
|
assert_file_not_exist 'tmp/tmpdir'
|
|
|
|
assert_file_exist 'tmp'
|
2003-12-02 06:03:37 -05:00
|
|
|
|
2004-05-02 08:57:31 -04:00
|
|
|
Dir.mkdir 'tmp/tmpdir'
|
|
|
|
File.open('tmp/tmpdir/a', 'w') {|f| f.puts 'dummy' }
|
|
|
|
File.open('tmp/tmpdir/c', 'w') {|f| f.puts 'dummy' }
|
|
|
|
rm_r ['tmp/tmpdir/a', 'tmp/tmpdir/b', 'tmp/tmpdir/c'], :force => true
|
|
|
|
assert_file_not_exist 'tmp/tmpdir/a'
|
|
|
|
assert_file_not_exist 'tmp/tmpdir/c'
|
|
|
|
Dir.rmdir 'tmp/tmpdir'
|
2009-09-17 22:20:39 -04:00
|
|
|
end
|
2004-05-02 08:57:31 -04:00
|
|
|
|
2009-09-17 22:20:39 -04:00
|
|
|
def test_rm_r_symlink
|
2004-03-10 08:41:43 -05:00
|
|
|
# [ruby-talk:94635] a symlink to the directory
|
|
|
|
Dir.mkdir 'tmp/tmpdir'
|
|
|
|
File.symlink '..', 'tmp/tmpdir/symlink_to_dir'
|
|
|
|
rm_r 'tmp/tmpdir'
|
|
|
|
assert_file_not_exist 'tmp/tmpdir'
|
|
|
|
assert_file_exist 'tmp'
|
2009-09-17 22:20:39 -04:00
|
|
|
end if have_symlink?
|
2004-03-10 08:41:43 -05:00
|
|
|
|
2009-09-17 22:20:39 -04:00
|
|
|
def test_rm_r_pathname
|
2003-12-02 06:03:37 -05:00
|
|
|
# pathname
|
|
|
|
Dir.mkdir 'tmp/tmpdir1'; touch 'tmp/tmpdir1/tmp'
|
|
|
|
Dir.mkdir 'tmp/tmpdir2'; touch 'tmp/tmpdir2/tmp'
|
|
|
|
Dir.mkdir 'tmp/tmpdir3'; touch 'tmp/tmpdir3/tmp'
|
|
|
|
assert_nothing_raised {
|
|
|
|
rm_r Pathname.new('tmp/tmpdir1')
|
|
|
|
rm_r [Pathname.new('tmp/tmpdir2'), Pathname.new('tmp/tmpdir3')]
|
|
|
|
}
|
|
|
|
assert_file_not_exist 'tmp/tmpdir1'
|
|
|
|
assert_file_not_exist 'tmp/tmpdir2'
|
|
|
|
assert_file_not_exist 'tmp/tmpdir3'
|
2003-09-17 05:52:50 -04:00
|
|
|
end
|
|
|
|
|
2005-09-18 16:59:29 -04:00
|
|
|
def test_remove_entry_secure
|
|
|
|
check_singleton :remove_entry_secure
|
|
|
|
|
|
|
|
my_rm_rf 'tmpdatadir'
|
|
|
|
|
|
|
|
Dir.mkdir 'tmpdatadir'
|
|
|
|
remove_entry_secure 'tmpdatadir'
|
|
|
|
assert_file_not_exist 'tmpdatadir'
|
|
|
|
|
|
|
|
Dir.mkdir 'tmpdatadir'
|
|
|
|
remove_entry_secure 'tmpdatadir/'
|
|
|
|
assert_file_not_exist 'tmpdatadir'
|
|
|
|
|
|
|
|
Dir.mkdir 'tmp/tmpdir'
|
|
|
|
remove_entry_secure 'tmp/tmpdir/'
|
|
|
|
assert_file_not_exist 'tmp/tmpdir'
|
|
|
|
assert_file_exist 'tmp'
|
|
|
|
|
|
|
|
Dir.mkdir 'tmp/tmpdir'
|
|
|
|
remove_entry_secure 'tmp/tmpdir'
|
|
|
|
assert_file_not_exist 'tmp/tmpdir'
|
|
|
|
assert_file_exist 'tmp'
|
|
|
|
|
|
|
|
Dir.mkdir 'tmp/tmpdir'
|
|
|
|
File.open('tmp/tmpdir/a', 'w') {|f| f.puts 'dummy' }
|
|
|
|
File.open('tmp/tmpdir/b', 'w') {|f| f.puts 'dummy' }
|
|
|
|
File.open('tmp/tmpdir/c', 'w') {|f| f.puts 'dummy' }
|
|
|
|
remove_entry_secure 'tmp/tmpdir'
|
|
|
|
assert_file_not_exist 'tmp/tmpdir'
|
|
|
|
assert_file_exist 'tmp'
|
|
|
|
|
|
|
|
Dir.mkdir 'tmp/tmpdir'
|
|
|
|
File.open('tmp/tmpdir/a', 'w') {|f| f.puts 'dummy' }
|
|
|
|
File.open('tmp/tmpdir/c', 'w') {|f| f.puts 'dummy' }
|
|
|
|
remove_entry_secure 'tmp/tmpdir/a', true
|
|
|
|
remove_entry_secure 'tmp/tmpdir/b', true
|
|
|
|
remove_entry_secure 'tmp/tmpdir/c', true
|
|
|
|
assert_file_not_exist 'tmp/tmpdir/a'
|
|
|
|
assert_file_not_exist 'tmp/tmpdir/c'
|
|
|
|
Dir.rmdir 'tmp/tmpdir'
|
2009-09-17 22:20:39 -04:00
|
|
|
end
|
2005-09-18 16:59:29 -04:00
|
|
|
|
2009-09-17 22:20:39 -04:00
|
|
|
def test_remove_entry_secure_symlink
|
2005-09-18 16:59:29 -04:00
|
|
|
# [ruby-talk:94635] a symlink to the directory
|
|
|
|
Dir.mkdir 'tmp/tmpdir'
|
|
|
|
File.symlink '..', 'tmp/tmpdir/symlink_to_dir'
|
|
|
|
remove_entry_secure 'tmp/tmpdir'
|
|
|
|
assert_file_not_exist 'tmp/tmpdir'
|
|
|
|
assert_file_exist 'tmp'
|
2009-09-17 22:20:39 -04:00
|
|
|
end if have_symlink?
|
2005-09-18 16:59:29 -04:00
|
|
|
|
2009-09-17 22:20:39 -04:00
|
|
|
def test_remove_entry_secure_pathname
|
2005-09-18 16:59:29 -04:00
|
|
|
# pathname
|
|
|
|
Dir.mkdir 'tmp/tmpdir1'; touch 'tmp/tmpdir1/tmp'
|
|
|
|
assert_nothing_raised {
|
|
|
|
remove_entry_secure Pathname.new('tmp/tmpdir1')
|
|
|
|
}
|
|
|
|
assert_file_not_exist 'tmp/tmpdir1'
|
|
|
|
end
|
|
|
|
|
2003-09-17 05:52:50 -04:00
|
|
|
def test_with_big_file
|
|
|
|
prepare_big_file
|
|
|
|
|
|
|
|
cp BIGFILE, 'tmp/cpdest'
|
|
|
|
assert_same_file BIGFILE, 'tmp/cpdest'
|
|
|
|
assert cmp(BIGFILE, 'tmp/cpdest'), 'orig != copied'
|
|
|
|
|
|
|
|
mv 'tmp/cpdest', 'tmp/mvdest'
|
|
|
|
assert_same_file BIGFILE, 'tmp/mvdest'
|
|
|
|
assert_file_not_exist 'tmp/cpdest'
|
|
|
|
|
|
|
|
rm 'tmp/mvdest'
|
|
|
|
assert_file_not_exist 'tmp/mvdest'
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_ln
|
|
|
|
TARGETS.each do |fname|
|
|
|
|
ln fname, 'tmp/lndest'
|
|
|
|
assert_same_file fname, 'tmp/lndest'
|
|
|
|
File.unlink 'tmp/lndest'
|
|
|
|
end
|
|
|
|
|
|
|
|
ln TARGETS, 'tmp'
|
|
|
|
TARGETS.each do |fname|
|
|
|
|
assert_same_file fname, 'tmp/' + File.basename(fname)
|
|
|
|
end
|
|
|
|
TARGETS.each do |fname|
|
|
|
|
File.unlink 'tmp/' + File.basename(fname)
|
|
|
|
end
|
2003-11-18 00:09:20 -05:00
|
|
|
|
2003-12-01 00:18:46 -05:00
|
|
|
# src==dest (1) same path
|
2003-11-18 00:09:20 -05:00
|
|
|
touch 'tmp/cptmp'
|
2008-09-24 13:44:39 -04:00
|
|
|
assert_raise(Errno::EEXIST) {
|
2003-11-18 00:09:20 -05:00
|
|
|
ln 'tmp/cptmp', 'tmp/cptmp'
|
|
|
|
}
|
2009-09-17 22:20:39 -04:00
|
|
|
end if have_hardlink?
|
|
|
|
|
|
|
|
def test_ln_symlink
|
|
|
|
touch 'tmp/cptmp'
|
2003-12-01 00:18:46 -05:00
|
|
|
# src==dest (2) symlink and its target
|
|
|
|
File.symlink 'cptmp', 'tmp/symlink'
|
2008-09-24 13:44:39 -04:00
|
|
|
assert_raise(Errno::EEXIST) {
|
2003-12-01 00:18:46 -05:00
|
|
|
ln 'tmp/cptmp', 'tmp/symlink' # normal file -> symlink
|
2003-11-18 00:09:20 -05:00
|
|
|
}
|
2008-09-24 13:44:39 -04:00
|
|
|
assert_raise(Errno::EEXIST) {
|
2003-12-01 00:18:46 -05:00
|
|
|
ln 'tmp/symlink', 'tmp/cptmp' # symlink -> normal file
|
|
|
|
}
|
|
|
|
# src==dest (3) looped symlink
|
|
|
|
File.symlink 'cptmp_symlink', 'tmp/cptmp_symlink'
|
2003-12-04 00:09:47 -05:00
|
|
|
begin
|
2003-12-01 00:18:46 -05:00
|
|
|
ln 'tmp/cptmp_symlink', 'tmp/cptmp_symlink'
|
2003-12-04 00:09:47 -05:00
|
|
|
rescue => err
|
|
|
|
assert_kind_of SystemCallError, err
|
|
|
|
end
|
2009-09-17 22:20:39 -04:00
|
|
|
end if have_symlink?
|
2003-12-02 06:03:37 -05:00
|
|
|
|
2009-09-17 22:20:39 -04:00
|
|
|
def test_ln_pathname
|
2003-12-02 06:03:37 -05:00
|
|
|
# pathname
|
|
|
|
touch 'tmp/lntmp'
|
|
|
|
assert_nothing_raised {
|
|
|
|
ln Pathname.new('tmp/lntmp'), 'tmp/lndesttmp1'
|
|
|
|
ln 'tmp/lntmp', Pathname.new('tmp/lndesttmp2')
|
|
|
|
ln Pathname.new('tmp/lntmp'), Pathname.new('tmp/lndesttmp3')
|
|
|
|
}
|
2009-09-17 22:20:39 -04:00
|
|
|
end if have_hardlink?
|
2003-09-17 05:52:50 -04:00
|
|
|
|
|
|
|
def test_ln_s
|
2005-09-18 16:59:29 -04:00
|
|
|
check_singleton :ln_s
|
|
|
|
|
2003-09-17 05:52:50 -04:00
|
|
|
TARGETS.each do |fname|
|
|
|
|
ln_s fname, 'tmp/lnsdest'
|
|
|
|
assert FileTest.symlink?('tmp/lnsdest'), 'not symlink'
|
|
|
|
assert_equal fname, File.readlink('tmp/lnsdest')
|
|
|
|
rm_f 'tmp/lnsdest'
|
|
|
|
end
|
2003-11-18 00:09:20 -05:00
|
|
|
assert_nothing_raised {
|
2003-12-01 00:18:46 -05:00
|
|
|
ln_s 'symlink', 'tmp/symlink'
|
2003-11-18 00:09:20 -05:00
|
|
|
}
|
|
|
|
assert_symlink 'tmp/symlink'
|
2003-12-02 06:03:37 -05:00
|
|
|
|
|
|
|
# pathname
|
|
|
|
touch 'tmp/lnsdest'
|
|
|
|
assert_nothing_raised {
|
|
|
|
ln_s Pathname.new('lnsdest'), 'tmp/symlink_tmp1'
|
|
|
|
ln_s 'lnsdest', Pathname.new('tmp/symlink_tmp2')
|
|
|
|
ln_s Pathname.new('lnsdest'), Pathname.new('tmp/symlink_tmp3')
|
|
|
|
}
|
2009-09-17 22:20:39 -04:00
|
|
|
end if have_symlink?
|
2003-09-17 05:52:50 -04:00
|
|
|
|
|
|
|
def test_ln_sf
|
2005-09-18 16:59:29 -04:00
|
|
|
check_singleton :ln_sf
|
|
|
|
|
2003-09-17 05:52:50 -04:00
|
|
|
TARGETS.each do |fname|
|
|
|
|
ln_sf fname, 'tmp/lnsdest'
|
|
|
|
assert FileTest.symlink?('tmp/lnsdest'), 'not symlink'
|
|
|
|
assert_equal fname, File.readlink('tmp/lnsdest')
|
|
|
|
ln_sf fname, 'tmp/lnsdest'
|
|
|
|
ln_sf fname, 'tmp/lnsdest'
|
|
|
|
end
|
2003-12-01 00:18:46 -05:00
|
|
|
assert_nothing_raised {
|
|
|
|
ln_sf 'symlink', 'tmp/symlink'
|
|
|
|
}
|
2003-12-02 06:03:37 -05:00
|
|
|
|
|
|
|
# pathname
|
|
|
|
touch 'tmp/lns_dest'
|
|
|
|
assert_nothing_raised {
|
|
|
|
ln_sf Pathname.new('lns_dest'), 'tmp/symlink_tmp1'
|
|
|
|
ln_sf 'lns_dest', Pathname.new('tmp/symlink_tmp2')
|
|
|
|
ln_sf Pathname.new('lns_dest'), Pathname.new('tmp/symlink_tmp3')
|
|
|
|
}
|
2009-09-17 22:20:39 -04:00
|
|
|
end if have_symlink?
|
2003-09-17 05:52:50 -04:00
|
|
|
|
|
|
|
def test_mkdir
|
2005-09-18 16:59:29 -04:00
|
|
|
check_singleton :mkdir
|
|
|
|
|
2003-09-17 05:52:50 -04:00
|
|
|
my_rm_rf 'tmpdatadir'
|
|
|
|
mkdir 'tmpdatadir'
|
2003-11-18 00:09:20 -05:00
|
|
|
assert_directory 'tmpdatadir'
|
2003-09-17 05:52:50 -04:00
|
|
|
Dir.rmdir 'tmpdatadir'
|
|
|
|
|
2003-12-12 05:33:24 -05:00
|
|
|
mkdir 'tmpdatadir/'
|
|
|
|
assert_directory 'tmpdatadir'
|
|
|
|
Dir.rmdir 'tmpdatadir'
|
|
|
|
|
2003-09-17 05:52:50 -04:00
|
|
|
mkdir 'tmp/mkdirdest'
|
2003-11-18 00:09:20 -05:00
|
|
|
assert_directory 'tmp/mkdirdest'
|
2003-09-17 05:52:50 -04:00
|
|
|
Dir.rmdir 'tmp/mkdirdest'
|
|
|
|
|
|
|
|
mkdir 'tmp/tmp', :mode => 0700
|
2003-11-18 00:09:20 -05:00
|
|
|
assert_directory 'tmp/tmp'
|
2003-11-20 05:16:27 -05:00
|
|
|
assert_equal 0700, (File.stat('tmp/tmp').mode & 0777) if have_file_perm?
|
2003-09-17 05:52:50 -04:00
|
|
|
Dir.rmdir 'tmp/tmp'
|
2013-06-03 10:20:15 -04:00
|
|
|
|
2013-06-04 20:48:24 -04:00
|
|
|
# EISDIR on OS X, FreeBSD; EEXIST on Linux; Errno::EACCES on Windows
|
|
|
|
assert_raise(Errno::EISDIR, Errno::EEXIST, Errno::EACCES) {
|
2013-06-03 10:20:15 -04:00
|
|
|
mkdir '/'
|
|
|
|
}
|
2009-09-17 22:20:39 -04:00
|
|
|
end
|
2003-12-02 06:03:37 -05:00
|
|
|
|
2009-09-17 22:20:39 -04:00
|
|
|
def test_mkdir_file_perm
|
2004-12-04 06:46:24 -05:00
|
|
|
mkdir 'tmp/tmp', :mode => 07777
|
|
|
|
assert_directory 'tmp/tmp'
|
|
|
|
assert_equal 07777, (File.stat('tmp/tmp').mode & 07777)
|
|
|
|
Dir.rmdir 'tmp/tmp'
|
2009-09-17 22:20:39 -04:00
|
|
|
end if have_file_perm?
|
2004-12-04 06:46:24 -05:00
|
|
|
|
2009-09-17 22:20:39 -04:00
|
|
|
def test_mkdir_lf_in_path
|
2004-12-04 06:46:24 -05:00
|
|
|
mkdir "tmp-first-line\ntmp-second-line"
|
|
|
|
assert_directory "tmp-first-line\ntmp-second-line"
|
|
|
|
Dir.rmdir "tmp-first-line\ntmp-second-line"
|
2009-09-17 22:20:39 -04:00
|
|
|
end if lf_in_path_allowed?
|
2004-05-07 08:04:19 -04:00
|
|
|
|
2010-01-25 17:08:29 -05:00
|
|
|
def test_mkdir_pathname
|
2003-12-02 06:03:37 -05:00
|
|
|
# pathname
|
|
|
|
assert_nothing_raised {
|
2003-12-12 05:33:24 -05:00
|
|
|
mkdir Pathname.new('tmp/tmpdirtmp')
|
|
|
|
mkdir [Pathname.new('tmp/tmpdirtmp2'), Pathname.new('tmp/tmpdirtmp3')]
|
2003-12-02 06:03:37 -05:00
|
|
|
}
|
2003-09-17 05:52:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_mkdir_p
|
2005-09-18 16:59:29 -04:00
|
|
|
check_singleton :mkdir_p
|
|
|
|
|
2003-09-17 05:52:50 -04:00
|
|
|
dirs = %w(
|
|
|
|
tmpdir/dir/
|
|
|
|
tmpdir/dir/./
|
|
|
|
tmpdir/dir/./.././dir/
|
|
|
|
tmpdir/a
|
|
|
|
tmpdir/a/
|
|
|
|
tmpdir/a/b
|
|
|
|
tmpdir/a/b/
|
|
|
|
tmpdir/a/b/c/
|
|
|
|
tmpdir/a/b/c
|
|
|
|
tmpdir/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a
|
|
|
|
tmpdir/a/a
|
|
|
|
)
|
2005-05-25 18:41:32 -04:00
|
|
|
my_rm_rf 'tmpdir'
|
2003-09-17 05:52:50 -04:00
|
|
|
dirs.each do |d|
|
|
|
|
mkdir_p d
|
2003-11-18 00:09:20 -05:00
|
|
|
assert_directory d
|
2003-09-17 05:52:50 -04:00
|
|
|
assert_file_not_exist "#{d}/a"
|
|
|
|
assert_file_not_exist "#{d}/b"
|
|
|
|
assert_file_not_exist "#{d}/c"
|
2005-05-25 18:41:32 -04:00
|
|
|
my_rm_rf 'tmpdir'
|
2003-09-17 05:52:50 -04:00
|
|
|
end
|
|
|
|
dirs.each do |d|
|
|
|
|
mkdir_p d
|
2003-11-18 00:09:20 -05:00
|
|
|
assert_directory d
|
2003-09-17 05:52:50 -04:00
|
|
|
end
|
|
|
|
rm_rf 'tmpdir'
|
2003-12-11 07:07:17 -05:00
|
|
|
dirs.each do |d|
|
2003-12-12 05:33:24 -05:00
|
|
|
mkdir_p "#{Dir.pwd}/#{d}"
|
2003-12-11 07:07:17 -05:00
|
|
|
assert_directory d
|
|
|
|
end
|
|
|
|
rm_rf 'tmpdir'
|
2003-09-17 05:52:50 -04:00
|
|
|
|
|
|
|
mkdir_p 'tmp/tmp/tmp', :mode => 0700
|
2003-11-18 00:09:20 -05:00
|
|
|
assert_directory 'tmp/tmp'
|
|
|
|
assert_directory 'tmp/tmp/tmp'
|
2003-11-20 05:16:27 -05:00
|
|
|
assert_equal 0700, (File.stat('tmp/tmp').mode & 0777) if have_file_perm?
|
|
|
|
assert_equal 0700, (File.stat('tmp/tmp/tmp').mode & 0777) if have_file_perm?
|
2003-09-17 05:52:50 -04:00
|
|
|
rm_rf 'tmp/tmp'
|
2003-12-02 06:03:37 -05:00
|
|
|
|
2004-09-10 02:56:20 -04:00
|
|
|
mkdir_p 'tmp/tmp', :mode => 0
|
|
|
|
assert_directory 'tmp/tmp'
|
|
|
|
assert_equal 0, (File.stat('tmp/tmp').mode & 0777) if have_file_perm?
|
|
|
|
# DO NOT USE rm_rf here.
|
|
|
|
# (rm(1) try to chdir to parent directory, it fails to remove directory.)
|
|
|
|
Dir.rmdir 'tmp/tmp'
|
|
|
|
Dir.rmdir 'tmp'
|
2013-06-03 10:20:15 -04:00
|
|
|
|
|
|
|
mkdir_p '/'
|
2009-09-17 22:20:39 -04:00
|
|
|
end
|
2004-09-10 02:56:20 -04:00
|
|
|
|
2009-09-17 22:20:39 -04:00
|
|
|
def test_mkdir_p_file_perm
|
2004-12-04 06:46:24 -05:00
|
|
|
mkdir_p 'tmp/tmp/tmp', :mode => 07777
|
|
|
|
assert_directory 'tmp/tmp/tmp'
|
|
|
|
assert_equal 07777, (File.stat('tmp/tmp/tmp').mode & 07777)
|
|
|
|
Dir.rmdir 'tmp/tmp/tmp'
|
|
|
|
Dir.rmdir 'tmp/tmp'
|
2009-09-17 22:20:39 -04:00
|
|
|
end if have_file_perm?
|
2004-12-04 06:46:24 -05:00
|
|
|
|
2009-09-17 22:20:39 -04:00
|
|
|
def test_mkdir_p_pathname
|
2003-12-02 06:03:37 -05:00
|
|
|
# pathname
|
|
|
|
assert_nothing_raised {
|
|
|
|
mkdir_p Pathname.new('tmp/tmp/tmp')
|
|
|
|
}
|
2003-09-17 05:52:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_install
|
2005-09-18 16:59:29 -04:00
|
|
|
check_singleton :install
|
|
|
|
|
2003-09-17 05:52:50 -04:00
|
|
|
File.open('tmp/aaa', 'w') {|f| f.puts 'aaa' }
|
|
|
|
File.open('tmp/bbb', 'w') {|f| f.puts 'bbb' }
|
|
|
|
install 'tmp/aaa', 'tmp/bbb', :mode => 0600
|
|
|
|
assert_equal "aaa\n", File.read('tmp/bbb')
|
2003-11-20 05:16:27 -05:00
|
|
|
assert_equal 0600, (File.stat('tmp/bbb').mode & 0777) if have_file_perm?
|
2003-09-17 05:52:50 -04:00
|
|
|
|
|
|
|
t = File.mtime('tmp/bbb')
|
|
|
|
install 'tmp/aaa', 'tmp/bbb'
|
|
|
|
assert_equal "aaa\n", File.read('tmp/bbb')
|
2003-11-20 05:16:27 -05:00
|
|
|
assert_equal 0600, (File.stat('tmp/bbb').mode & 0777) if have_file_perm?
|
2007-11-19 10:57:52 -05:00
|
|
|
assert_equal_time t, File.mtime('tmp/bbb')
|
2003-09-17 05:52:50 -04:00
|
|
|
|
|
|
|
File.unlink 'tmp/aaa'
|
|
|
|
File.unlink 'tmp/bbb'
|
2003-11-18 00:09:20 -05:00
|
|
|
|
2003-12-01 00:18:46 -05:00
|
|
|
# src==dest (1) same path
|
2003-11-18 00:09:20 -05:00
|
|
|
touch 'tmp/cptmp'
|
2008-09-24 13:44:39 -04:00
|
|
|
assert_raise(ArgumentError) {
|
2003-11-18 00:09:20 -05:00
|
|
|
install 'tmp/cptmp', 'tmp/cptmp'
|
|
|
|
}
|
2009-09-17 22:20:39 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_install_symlink
|
|
|
|
touch 'tmp/cptmp'
|
2003-12-01 00:18:46 -05:00
|
|
|
# src==dest (2) symlink and its target
|
2003-11-18 05:05:21 -05:00
|
|
|
File.symlink 'cptmp', 'tmp/cptmp_symlink'
|
2008-09-24 13:44:39 -04:00
|
|
|
assert_raise(ArgumentError) {
|
2003-11-18 00:09:20 -05:00
|
|
|
install 'tmp/cptmp', 'tmp/cptmp_symlink'
|
|
|
|
}
|
2008-09-24 13:44:39 -04:00
|
|
|
assert_raise(ArgumentError) {
|
2003-12-01 00:18:46 -05:00
|
|
|
install 'tmp/cptmp_symlink', 'tmp/cptmp'
|
|
|
|
}
|
|
|
|
# src==dest (3) looped symlink
|
2003-11-18 05:05:21 -05:00
|
|
|
File.symlink 'symlink', 'tmp/symlink'
|
2008-09-24 13:44:39 -04:00
|
|
|
assert_raise(Errno::ELOOP) {
|
2003-12-01 00:18:46 -05:00
|
|
|
# File#install invokes open(2), always ELOOP must be raised
|
2003-11-18 00:09:20 -05:00
|
|
|
install 'tmp/symlink', 'tmp/symlink'
|
|
|
|
}
|
2009-09-17 22:20:39 -04:00
|
|
|
end if have_symlink?
|
2003-12-02 06:03:37 -05:00
|
|
|
|
2009-09-17 22:20:39 -04:00
|
|
|
def test_install_pathname
|
2003-12-02 06:03:37 -05:00
|
|
|
# pathname
|
|
|
|
assert_nothing_raised {
|
|
|
|
rm_f 'tmp/a'; touch 'tmp/a'
|
|
|
|
install 'tmp/a', Pathname.new('tmp/b')
|
|
|
|
rm_f 'tmp/a'; touch 'tmp/a'
|
|
|
|
install Pathname.new('tmp/a'), 'tmp/b'
|
|
|
|
rm_f 'tmp/a'; touch 'tmp/a'
|
|
|
|
install Pathname.new('tmp/a'), Pathname.new('tmp/b')
|
|
|
|
rm_f 'tmp/a'
|
|
|
|
touch 'tmp/a'
|
|
|
|
touch 'tmp/b'
|
|
|
|
mkdir 'tmp/dest'
|
|
|
|
install [Pathname.new('tmp/a'), Pathname.new('tmp/b')], 'tmp/dest'
|
2005-05-25 18:41:32 -04:00
|
|
|
my_rm_rf 'tmp/dest'
|
2003-12-02 06:03:37 -05:00
|
|
|
mkdir 'tmp/dest'
|
|
|
|
install [Pathname.new('tmp/a'), Pathname.new('tmp/b')], Pathname.new('tmp/dest')
|
|
|
|
}
|
2003-09-17 05:52:50 -04:00
|
|
|
end
|
|
|
|
|
2004-05-02 08:57:31 -04:00
|
|
|
def test_chmod
|
2005-09-18 16:59:29 -04:00
|
|
|
check_singleton :chmod
|
|
|
|
|
2005-05-26 07:33:16 -04:00
|
|
|
touch 'tmp/a'
|
|
|
|
chmod 0700, 'tmp/a'
|
|
|
|
assert_equal 0700, File.stat('tmp/a').mode & 0777
|
|
|
|
chmod 0500, 'tmp/a'
|
|
|
|
assert_equal 0500, File.stat('tmp/a').mode & 0777
|
2009-09-17 22:20:39 -04:00
|
|
|
end if have_file_perm?
|
2005-05-26 07:33:16 -04:00
|
|
|
|
2011-05-01 12:16:05 -04:00
|
|
|
def test_chmod_symbol_mode
|
|
|
|
check_singleton :chmod
|
|
|
|
|
|
|
|
touch 'tmp/a'
|
2013-07-04 13:22:08 -04:00
|
|
|
chmod "u=wrx,g=rx,o=x", 'tmp/a'
|
|
|
|
assert_equal 0751, File.stat('tmp/a').mode & 07777
|
|
|
|
chmod "g+w-x", 'tmp/a'
|
|
|
|
assert_equal 0761, File.stat('tmp/a').mode & 07777
|
|
|
|
chmod "o+r,g=o+w,o-r,u-o", 'tmp/a' # 761 => 763 => 773 => 771 => 671
|
|
|
|
assert_equal 0671, File.stat('tmp/a').mode & 07777
|
2011-05-01 12:16:05 -04:00
|
|
|
chmod "u=wrx,g=,o=", 'tmp/a'
|
|
|
|
assert_equal 0700, File.stat('tmp/a').mode & 0777
|
|
|
|
chmod "u=rx,go=", 'tmp/a'
|
|
|
|
assert_equal 0500, File.stat('tmp/a').mode & 0777
|
|
|
|
chmod "+wrx", 'tmp/a'
|
|
|
|
assert_equal 0777, File.stat('tmp/a').mode & 0777
|
|
|
|
chmod "u+s,o=s", 'tmp/a'
|
|
|
|
assert_equal 04770, File.stat('tmp/a').mode & 07777
|
|
|
|
chmod "u-w,go-wrx", 'tmp/a'
|
|
|
|
assert_equal 04500, File.stat('tmp/a').mode & 07777
|
|
|
|
chmod "+s", 'tmp/a'
|
|
|
|
assert_equal 06500, File.stat('tmp/a').mode & 07777
|
2011-05-03 07:31:20 -04:00
|
|
|
|
|
|
|
# FreeBSD ufs and tmpfs don't allow to change sticky bit against
|
|
|
|
# regular file. It's slightly strange. Anyway it's no effect bit.
|
|
|
|
# see /usr/src/sys/ufs/ufs/ufs_chmod()
|
2011-08-24 12:41:12 -04:00
|
|
|
# NetBSD, OpenBSD and Solaris also denies it.
|
|
|
|
if /freebsd|netbsd|openbsd|solaris/ !~ RUBY_PLATFORM
|
2011-05-03 07:31:20 -04:00
|
|
|
chmod "u+t,o+t", 'tmp/a'
|
|
|
|
assert_equal 07500, File.stat('tmp/a').mode & 07777
|
|
|
|
chmod "a-t,a-s", 'tmp/a'
|
|
|
|
assert_equal 0500, File.stat('tmp/a').mode & 07777
|
|
|
|
end
|
|
|
|
|
2013-07-04 22:29:49 -04:00
|
|
|
assert_raise_with_message(ArgumentError, /invalid\b.*\bfile mode/) {
|
2013-07-04 13:22:08 -04:00
|
|
|
chmod "a", 'tmp/a'
|
|
|
|
}
|
|
|
|
|
2013-07-04 22:29:49 -04:00
|
|
|
assert_raise_with_message(ArgumentError, /invalid\b.*\bfile mode/) {
|
2013-07-04 13:22:08 -04:00
|
|
|
chmod "x+a", 'tmp/a'
|
|
|
|
}
|
|
|
|
|
2013-07-04 22:29:49 -04:00
|
|
|
assert_raise_with_message(ArgumentError, /invalid\b.*\bfile mode/) {
|
2013-07-04 13:22:08 -04:00
|
|
|
chmod "u+z", 'tmp/a'
|
|
|
|
}
|
|
|
|
|
2013-07-04 22:29:49 -04:00
|
|
|
assert_raise_with_message(ArgumentError, /invalid\b.*\bfile mode/) {
|
2013-07-04 13:22:08 -04:00
|
|
|
chmod ",+x", 'tmp/a'
|
|
|
|
}
|
|
|
|
|
2013-07-04 22:29:49 -04:00
|
|
|
assert_raise_with_message(ArgumentError, /invalid\b.*\bfile mode/) {
|
2013-07-04 13:22:08 -04:00
|
|
|
chmod "755", 'tmp/a'
|
|
|
|
}
|
|
|
|
|
2011-05-01 12:16:05 -04:00
|
|
|
end if have_file_perm?
|
|
|
|
|
|
|
|
|
2005-05-26 07:33:16 -04:00
|
|
|
def test_chmod_R
|
2005-09-18 16:59:29 -04:00
|
|
|
check_singleton :chmod_R
|
|
|
|
|
2005-05-26 07:33:16 -04:00
|
|
|
mkdir_p 'tmp/dir/dir'
|
|
|
|
touch %w( tmp/dir/file tmp/dir/dir/file )
|
|
|
|
chmod_R 0700, 'tmp/dir'
|
|
|
|
assert_equal 0700, File.stat('tmp/dir').mode & 0777
|
|
|
|
assert_equal 0700, File.stat('tmp/dir/file').mode & 0777
|
|
|
|
assert_equal 0700, File.stat('tmp/dir/dir').mode & 0777
|
|
|
|
assert_equal 0700, File.stat('tmp/dir/dir/file').mode & 0777
|
|
|
|
chmod_R 0500, 'tmp/dir'
|
|
|
|
assert_equal 0500, File.stat('tmp/dir').mode & 0777
|
|
|
|
assert_equal 0500, File.stat('tmp/dir/file').mode & 0777
|
|
|
|
assert_equal 0500, File.stat('tmp/dir/dir').mode & 0777
|
|
|
|
assert_equal 0500, File.stat('tmp/dir/dir/file').mode & 0777
|
|
|
|
chmod_R 0700, 'tmp/dir' # to remove
|
2009-09-17 22:20:39 -04:00
|
|
|
end if have_file_perm?
|
2005-05-26 07:33:16 -04:00
|
|
|
|
2011-05-01 12:16:05 -04:00
|
|
|
def test_chmod_symbol_mode_R
|
|
|
|
check_singleton :chmod_R
|
|
|
|
|
|
|
|
mkdir_p 'tmp/dir/dir'
|
|
|
|
touch %w( tmp/dir/file tmp/dir/dir/file )
|
|
|
|
chmod_R "u=wrx,g=,o=", 'tmp/dir'
|
|
|
|
assert_equal 0700, File.stat('tmp/dir').mode & 0777
|
|
|
|
assert_equal 0700, File.stat('tmp/dir/file').mode & 0777
|
|
|
|
assert_equal 0700, File.stat('tmp/dir/dir').mode & 0777
|
|
|
|
assert_equal 0700, File.stat('tmp/dir/dir/file').mode & 0777
|
|
|
|
chmod_R "u=xr,g+X,o=", 'tmp/dir'
|
|
|
|
assert_equal 0510, File.stat('tmp/dir').mode & 0777
|
|
|
|
assert_equal 0500, File.stat('tmp/dir/file').mode & 0777
|
|
|
|
assert_equal 0510, File.stat('tmp/dir/dir').mode & 0777
|
|
|
|
assert_equal 0500, File.stat('tmp/dir/dir/file').mode & 0777
|
|
|
|
chmod_R 0700, 'tmp/dir' # to remove
|
|
|
|
end if have_file_perm?
|
|
|
|
|
2013-02-01 22:07:17 -05:00
|
|
|
def test_chmod_verbose
|
|
|
|
check_singleton :chmod
|
|
|
|
|
|
|
|
r, w = IO.pipe
|
|
|
|
stderr_back = $stderr
|
|
|
|
read, $stderr = IO.pipe
|
|
|
|
th = Thread.new { read.read }
|
|
|
|
|
|
|
|
touch 'tmp/a'
|
|
|
|
chmod 0700, 'tmp/a', verbose: true
|
|
|
|
assert_equal 0700, File.stat('tmp/a').mode & 0777
|
|
|
|
chmod 0500, 'tmp/a', verbose: true
|
|
|
|
assert_equal 0500, File.stat('tmp/a').mode & 0777
|
|
|
|
|
|
|
|
$stderr.close
|
|
|
|
lines = th.value.lines.map {|l| l.chomp }
|
|
|
|
assert_equal(["chmod 700 tmp/a", "chmod 500 tmp/a"], lines)
|
|
|
|
ensure
|
|
|
|
$stderr = stderr_back if stderr_back
|
|
|
|
end if have_file_perm?
|
|
|
|
|
2005-05-26 07:33:16 -04:00
|
|
|
# FIXME: How can I test this method?
|
2004-12-04 07:29:55 -05:00
|
|
|
def test_chown
|
2005-09-18 16:59:29 -04:00
|
|
|
check_singleton :chown
|
2009-09-17 22:20:39 -04:00
|
|
|
end if have_file_perm?
|
2004-12-04 07:29:55 -05:00
|
|
|
|
2005-05-26 07:33:16 -04:00
|
|
|
# FIXME: How can I test this method?
|
2004-12-04 07:29:55 -05:00
|
|
|
def test_chown_R
|
2005-09-18 16:59:29 -04:00
|
|
|
check_singleton :chown_R
|
2009-09-17 22:20:39 -04:00
|
|
|
end if have_file_perm?
|
2004-05-02 08:57:31 -04:00
|
|
|
|
2005-01-01 02:22:04 -05:00
|
|
|
def test_copy_entry
|
2005-09-18 16:59:29 -04:00
|
|
|
check_singleton :copy_entry
|
|
|
|
|
2005-04-14 06:00:52 -04:00
|
|
|
each_srcdest do |srcpath, destpath|
|
2005-01-01 02:22:04 -05:00
|
|
|
copy_entry srcpath, destpath
|
|
|
|
assert_same_file srcpath, destpath
|
2005-01-08 13:23:24 -05:00
|
|
|
assert_equal File.stat(srcpath).ftype, File.stat(destpath).ftype
|
2005-01-01 02:22:04 -05:00
|
|
|
end
|
2009-09-17 22:20:39 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_copy_entry_symlink
|
2005-05-26 07:33:16 -04:00
|
|
|
# root is a symlink
|
2005-01-01 02:22:04 -05:00
|
|
|
File.symlink 'somewhere', 'tmp/symsrc'
|
|
|
|
copy_entry 'tmp/symsrc', 'tmp/symdest'
|
2005-05-26 07:33:16 -04:00
|
|
|
assert_symlink 'tmp/symdest'
|
|
|
|
assert_equal 'somewhere', File.readlink('tmp/symdest')
|
|
|
|
|
|
|
|
# content is a symlink
|
|
|
|
mkdir 'tmp/dir'
|
|
|
|
File.symlink 'somewhere', 'tmp/dir/sym'
|
|
|
|
copy_entry 'tmp/dir', 'tmp/dirdest'
|
|
|
|
assert_directory 'tmp/dirdest'
|
|
|
|
assert_not_symlink 'tmp/dirdest'
|
|
|
|
assert_symlink 'tmp/dirdest/sym'
|
|
|
|
assert_equal 'somewhere', File.readlink('tmp/dirdest/sym')
|
2009-09-17 22:20:39 -04:00
|
|
|
end if have_symlink?
|
2005-01-01 02:22:04 -05:00
|
|
|
|
|
|
|
def test_copy_file
|
2005-09-18 16:59:29 -04:00
|
|
|
check_singleton :copy_file
|
|
|
|
|
2005-04-14 06:00:52 -04:00
|
|
|
each_srcdest do |srcpath, destpath|
|
2005-01-01 02:22:04 -05:00
|
|
|
copy_file srcpath, destpath
|
|
|
|
assert_same_file srcpath, destpath
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_copy_stream
|
2005-09-18 16:59:29 -04:00
|
|
|
check_singleton :copy_stream
|
2005-01-01 02:22:04 -05:00
|
|
|
# IO
|
2005-04-14 06:00:52 -04:00
|
|
|
each_srcdest do |srcpath, destpath|
|
2010-05-04 05:38:21 -04:00
|
|
|
File.open(srcpath, 'rb') {|src|
|
|
|
|
File.open(destpath, 'wb') {|dest|
|
2005-01-01 02:22:04 -05:00
|
|
|
copy_stream src, dest
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert_same_file srcpath, destpath
|
|
|
|
end
|
2010-05-04 05:38:21 -04:00
|
|
|
end
|
2005-01-01 02:22:04 -05:00
|
|
|
|
2010-05-04 05:38:21 -04:00
|
|
|
def test_copy_stream_duck
|
|
|
|
check_singleton :copy_stream
|
2005-01-01 02:22:04 -05:00
|
|
|
# duck typing test [ruby-dev:25369]
|
2005-04-14 06:00:52 -04:00
|
|
|
each_srcdest do |srcpath, destpath|
|
2010-05-04 05:38:21 -04:00
|
|
|
File.open(srcpath, 'rb') {|src|
|
|
|
|
File.open(destpath, 'wb') {|dest|
|
2005-01-01 02:22:04 -05:00
|
|
|
copy_stream Stream.new(src), Stream.new(dest)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert_same_file srcpath, destpath
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_remove_file
|
2005-09-18 16:59:29 -04:00
|
|
|
check_singleton :remove_file
|
2005-04-14 06:00:52 -04:00
|
|
|
File.open('data/tmp', 'w') {|f| f.puts 'dummy' }
|
|
|
|
remove_file 'data/tmp'
|
|
|
|
assert_file_not_exist 'data/tmp'
|
2009-09-17 22:20:39 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_remove_file_file_perm
|
2005-04-14 06:00:52 -04:00
|
|
|
File.open('data/tmp', 'w') {|f| f.puts 'dummy' }
|
|
|
|
File.chmod 0, 'data/tmp'
|
|
|
|
remove_file 'data/tmp'
|
|
|
|
assert_file_not_exist 'data/tmp'
|
2009-09-17 22:20:39 -04:00
|
|
|
end if have_file_perm?
|
2005-01-01 02:22:04 -05:00
|
|
|
|
|
|
|
def test_remove_dir
|
2005-09-18 16:59:29 -04:00
|
|
|
check_singleton :remove_dir
|
2005-04-14 06:00:52 -04:00
|
|
|
Dir.mkdir 'data/tmpdir'
|
|
|
|
File.open('data/tmpdir/a', 'w') {|f| f.puts 'dummy' }
|
|
|
|
remove_dir 'data/tmpdir'
|
|
|
|
assert_file_not_exist 'data/tmpdir'
|
2009-09-17 22:20:39 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_remove_dir_file_perm
|
2005-04-14 06:00:52 -04:00
|
|
|
Dir.mkdir 'data/tmpdir'
|
|
|
|
File.chmod 0555, 'data/tmpdir'
|
|
|
|
remove_dir 'data/tmpdir'
|
|
|
|
assert_file_not_exist 'data/tmpdir'
|
2009-09-17 22:20:39 -04:00
|
|
|
end if have_file_perm?
|
2005-01-01 02:22:04 -05:00
|
|
|
|
|
|
|
def test_compare_file
|
2005-09-18 16:59:29 -04:00
|
|
|
check_singleton :compare_file
|
2005-01-01 02:22:04 -05:00
|
|
|
# FIXME
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_compare_stream
|
2005-09-18 16:59:29 -04:00
|
|
|
check_singleton :compare_stream
|
2005-01-01 02:22:04 -05:00
|
|
|
# FIXME
|
|
|
|
end
|
|
|
|
|
|
|
|
class Stream
|
|
|
|
def initialize(f)
|
|
|
|
@f = f
|
|
|
|
end
|
|
|
|
|
2008-09-05 05:37:55 -04:00
|
|
|
def read(*args)
|
|
|
|
@f.read(*args)
|
2005-01-01 02:22:04 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def write(str)
|
|
|
|
@f.write str
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_uptodate?
|
2005-09-18 16:59:29 -04:00
|
|
|
check_singleton :uptodate?
|
2005-04-14 06:00:52 -04:00
|
|
|
prepare_time_data
|
2005-01-01 02:22:04 -05:00
|
|
|
Dir.chdir('data') {
|
|
|
|
assert( uptodate?('newest', %w(old newer notexist)) )
|
|
|
|
assert( ! uptodate?('newer', %w(old newest notexist)) )
|
|
|
|
assert( ! uptodate?('notexist', %w(old newest newer)) )
|
|
|
|
}
|
|
|
|
|
|
|
|
# pathname
|
|
|
|
touch 'tmp/a'
|
|
|
|
touch 'tmp/b'
|
|
|
|
touch 'tmp/c'
|
|
|
|
assert_nothing_raised {
|
|
|
|
uptodate? Pathname.new('tmp/a'), ['tmp/b', 'tmp/c']
|
|
|
|
uptodate? 'tmp/a', [Pathname.new('tmp/b'), 'tmp/c']
|
|
|
|
uptodate? 'tmp/a', ['tmp/b', Pathname.new('tmp/c')]
|
|
|
|
uptodate? Pathname.new('tmp/a'), [Pathname.new('tmp/b'), Pathname.new('tmp/c')]
|
|
|
|
}
|
2012-07-16 04:15:08 -04:00
|
|
|
# [Bug #6708] [ruby-core:46256]
|
2013-07-04 22:29:49 -04:00
|
|
|
assert_raise_with_message(ArgumentError, "wrong number of arguments (3 for 2)") {
|
2012-07-16 04:15:08 -04:00
|
|
|
uptodate?('new',['old', 'oldest'], {})
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2005-09-18 16:59:29 -04:00
|
|
|
def test_cd
|
|
|
|
check_singleton :cd
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_chdir
|
|
|
|
check_singleton :chdir
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_getwd
|
|
|
|
check_singleton :getwd
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_identical?
|
|
|
|
check_singleton :identical?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_link
|
|
|
|
check_singleton :link
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_makedirs
|
|
|
|
check_singleton :makedirs
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_mkpath
|
|
|
|
check_singleton :mkpath
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_move
|
|
|
|
check_singleton :move
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_rm_rf
|
|
|
|
check_singleton :rm_rf
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_rmdir
|
|
|
|
check_singleton :rmdir
|
2013-06-03 11:01:42 -04:00
|
|
|
|
|
|
|
begin
|
|
|
|
Dir.rmdir '/'
|
|
|
|
rescue => e
|
|
|
|
assert_raise(e.class) {
|
2013-06-05 07:53:02 -04:00
|
|
|
# Dir.rmdir('') raises Errno::ENOENT.
|
|
|
|
# FileUtils#rmdir ignores it.
|
|
|
|
# And this test failed as expected.
|
2013-06-03 11:01:42 -04:00
|
|
|
rmdir '/'
|
|
|
|
}
|
|
|
|
end
|
2013-06-13 09:03:30 -04:00
|
|
|
|
|
|
|
subdir = 'data/sub/dir'
|
|
|
|
mkdir_p(subdir)
|
|
|
|
assert_nothing_raised(Errno::ENOENT) {
|
|
|
|
rmdir(subdir, parents: true)
|
|
|
|
}
|
2013-06-13 09:12:35 -04:00
|
|
|
assert_file_not_exist(subdir)
|
2013-06-13 09:03:30 -04:00
|
|
|
assert_file_not_exist('data/sub')
|
|
|
|
assert_directory('data')
|
2005-09-18 16:59:29 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_rmtree
|
|
|
|
check_singleton :rmtree
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_safe_unlink
|
|
|
|
check_singleton :safe_unlink
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_symlink
|
|
|
|
check_singleton :symlink
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_touch
|
|
|
|
check_singleton :touch
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_collect_methods
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_commands
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_have_option?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_options
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_options_of
|
|
|
|
end
|
|
|
|
|
2003-09-17 05:52:50 -04:00
|
|
|
end
|