From 1c0cee4f833150bd83eb3cfa578bc4dc83ca3d25 Mon Sep 17 00:00:00 2001 From: aamine Date: Tue, 18 Nov 2003 10:05:21 +0000 Subject: [PATCH] * lib/fileutils.rb (fu_same?): check by inode instead of path name, to detect two hard links pointing to the same content. * test/fileutils.rb: did not create correctly looped symlinks. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4980 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 7 +++++++ lib/fileutils.rb | 32 +++----------------------------- test/fileutils/test_fileutils.rb | 12 ++++++------ 3 files changed, 16 insertions(+), 35 deletions(-) diff --git a/ChangeLog b/ChangeLog index 20c978dd42..f13137425e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Tue Nov 18 19:05:04 2003 Minero Aoki + + * lib/fileutils.rb (fu_same?): check by inode instead of path + name, to detect two hard links pointing to the same content. + + * test/fileutils.rb: did not create correctly looped symlinks. + Tue Nov 18 18:23:05 2003 Nobuyoshi Nakada * ext/stringio/stringio.c (strio_read): behave as IO at empty string. diff --git a/lib/fileutils.rb b/lib/fileutils.rb index 94a8f5e939..9b50aec919 100644 --- a/lib/fileutils.rb +++ b/lib/fileutils.rb @@ -739,35 +739,9 @@ module FileUtils end def fu_same?( a, b ) - fu_resolve_symlink(a) == fu_resolve_symlink(b) - end - - def fu_resolve_symlink( path, limit = 128 ) - raise Errno::ELOOP, "too many levels of symlic links: #{path}" if limit < 0 - if File.symlink?(path) - then fu_resolve_symlink(fu_readlink(File.expand_path(path)), limit-1) - else path - end - end - - def fu_readlink( path ) - dest = File.readlink(path) - if absolute_path?(dest) - then dest - else File.dirname(File.expand_path(path)) + '/' + dest - path = File.readlink(path) - end - end - - def absolute_path?( path ) - if have_drive_letter? - then %r<\A([a-z]:)?/> === path - else %r<\A/> === path - end - end - - def have_drive_letter? - File::ALT_SEPARATOR ? true : false + File.stat(a).ino == File.stat(b).ino + rescue Errno::ENOENT + return false end def fu_stream_blksize( *streams ) diff --git a/test/fileutils/test_fileutils.rb b/test/fileutils/test_fileutils.rb index 922c065919..d5357ca4c9 100644 --- a/test/fileutils/test_fileutils.rb +++ b/test/fileutils/test_fileutils.rb @@ -149,11 +149,11 @@ end cp 'tmp/cptmp', 'tmp/cptmp' } if have_symlink? - File.symlink 'tmp/cptmp', 'tmp/cptmp_symlink' + File.symlink 'cptmp', 'tmp/cptmp_symlink' assert_raises(ArgumentError) { cp 'tmp/cptmp', 'tmp/cptmp_symlink' } - File.symlink 'tmp/symlink', 'tmp/symlink' + File.symlink 'symlink', 'tmp/symlink' assert_raises(Errno::ELOOP) { cp 'tmp/symlink', 'tmp/symlink' } @@ -180,11 +180,11 @@ end mv 'tmp/cptmp', 'tmp/cptmp' } if have_symlink? - File.symlink 'tmp/cptmp', 'tmp/cptmp_symlink' + File.symlink 'cptmp', 'tmp/cptmp_symlink' assert_raises(ArgumentError) { mv 'tmp/cptmp', 'tmp/cptmp_symlink' } - File.symlink 'tmp/symlink', 'tmp/symlink' + File.symlink 'symlink', 'tmp/symlink' assert_raises(Errno::ELOOP) { mv 'tmp/symlink', 'tmp/symlink' } @@ -412,11 +412,11 @@ end install 'tmp/cptmp', 'tmp/cptmp' } if have_symlink? - File.symlink 'tmp/cptmp', 'tmp/cptmp_symlink' + File.symlink 'cptmp', 'tmp/cptmp_symlink' assert_raises(ArgumentError) { install 'tmp/cptmp', 'tmp/cptmp_symlink' } - File.symlink 'tmp/symlink', 'tmp/symlink' + File.symlink 'symlink', 'tmp/symlink' assert_raises(Errno::ELOOP) { install 'tmp/symlink', 'tmp/symlink' }