From 65a5162550f58047974793cdc8067a970b2435c0 Mon Sep 17 00:00:00 2001 From: matz Date: Fri, 13 Aug 1999 05:45:20 +0000 Subject: 1.4.0 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@520 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/ftools.rb | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'lib/ftools.rb') diff --git a/lib/ftools.rb b/lib/ftools.rb index 7ccc7a4468..39d6ca9462 100644 --- a/lib/ftools.rb +++ b/lib/ftools.rb @@ -24,6 +24,9 @@ class << File fsize = 1024 if fsize < 512 fsize = TOO_BIG if fsize > TOO_BIG + fmode = stat(from).mode + tpath = to + from = open(from, "r") from.binmode to = open(to, "w") @@ -47,6 +50,7 @@ class << File to.close from.close end + chmod(fmode, tpath) ret end @@ -63,13 +67,24 @@ class << File to = catname(from, to) $stderr.print from, " -> ", to, "\n" if verbose - if PLATFORM =~ /djgpp|cygwin|mswin32/ and FileTest.file? to + if RUBY_PLATFORM =~ /djgpp|cygwin|mswin32/ and FileTest.file? to unlink to end + fstat = stat(from) begin rename from, to rescue - syscopy from, to and unlink from + begin + symlink File.readlink(from), to and unlink from + rescue + from_stat = stat(from) + syscopy from, to and unlink from + utime(from_stat.atime, from_stat.mtime, to) + begin + chown(fstat.uid, fstat.gid, tpath) + rescue + end + end end end @@ -98,7 +113,8 @@ class << File if fr = from.read(fsize) tr = to.read(fr.size) else - ret = !to.read(fsize) + ret = to.read(fsize) + ret = !ret || ret.length == 0 break end end @@ -137,7 +153,9 @@ class << File parent = dirname(dir) makedirs parent unless FileTest.directory? parent $stderr.print "mkdir ", dir, "\n" if verbose - Dir.mkdir dir, mode + if basename(dir) != "" + Dir.mkdir dir, mode + end end end @@ -154,7 +172,7 @@ class << File def install(from, to, mode = nil, verbose = false) to = catname(from, to) unless FileTest.exist? to and cmp from, to - unlink to if FileTest.exist? to + safe_unlink to if FileTest.exist? to cp from, to, verbose chmod mode, to, verbose if mode end -- cgit v1.2.3