[#6143] — Christophe Poucet <christophe.poucet@...>

Hello,

17 messages 2005/10/04
[#6147] Re: patch.tgz — nobu.nokada@... 2005/10/04

Hi,

[#6199] Kernel rdoc HTML file not being created when rdoc is run on 1.8.3 — James Britt <ruby@...>

When 1.8.3 came out, I grabbed the source and ran rdoc on it. After

9 messages 2005/10/08

[#6251] RubyGems, upstream releases and idempotence of packaging — Mauricio Fern疣dez <mfp@...>

[sorry for the very late reply; I left this message in +postponed and forgot

14 messages 2005/10/12

[#6282] Wilderness: Need Code to invoke ELTS_SHARED response — "Charles E. Thornton" <ruby-core@...>

Testing the My Object Dump and I am trying to cause creation

13 messages 2005/10/14
[#6283] Re: Wilderness: Need Code to invoke ELTS_SHARED response — Mauricio Fern疣dez <mfp@...> 2005/10/14

On Fri, Oct 14, 2005 at 05:04:59PM +0900, Charles E. Thornton wrote:

[#6288] Re: Wilderness: Need Code to invoke ELTS_SHARED response — "Charles E. Thornton" <ruby-core@...> 2005/10/14

Mauricio Fern疣dez wrote:

[#6365] Time for built-in Rational and Complex classes? — Gavin Sinclair <gsinclair@...>

There has been some support for, but no comment on, RCR #260 ("Make

12 messages 2005/10/24
[#6366] Re: Time for built-in Rational and Complex classes? — "Ara.T.Howard" <Ara.T.Howard@...> 2005/10/24

On Mon, 24 Oct 2005, Gavin Sinclair wrote:

[#6405] Re: [PATCH] Pathname.exists?() — "Berger, Daniel" <Daniel.Berger@...>

12 messages 2005/10/25
[#6406] Re: [PATCH] Pathname.exists?() — TRANS <transfire@...> 2005/10/25

On 10/25/05, Berger, Daniel <Daniel.Berger@qwest.com> wrote:

[#6408] Re: [PATCH] Pathname.exists?() — Gavin Sinclair <gsinclair@...> 2005/10/25

On 10/26/05, TRANS <transfire@gmail.com> wrote:

[#6442] Wilderness: I Have formatted README.EXT into an HTML Document — "Charles E. Thornton" <ruby-core@...>

I have taken README.EXT (English Version Only) and have reformatted

14 messages 2005/10/27

[#6469] csv.rb a start on refactoring. — Hugh Sasse <hgs@...>

For a database application I found using CSV to be rather slow.

50 messages 2005/10/28
[#6470] Re: csv.rb a start on refactoring. — "Ara.T.Howard" <Ara.T.Howard@...> 2005/10/28

[#6471] Re: csv.rb a start on refactoring. — James Edward Gray II <james@...> 2005/10/28

On Oct 28, 2005, at 8:53 AM, Ara.T.Howard wrote:

[#6474] Re: csv.rb a start on refactoring. — "Ara.T.Howard" <Ara.T.Howard@...> 2005/10/28

On Fri, 28 Oct 2005, James Edward Gray II wrote:

[#6484] Re: csv.rb a start on refactoring. — James Edward Gray II <james@...> 2005/10/29

On Oct 28, 2005, at 9:58 AM, Ara.T.Howard wrote:

[#6485] Re: csv.rb a start on refactoring. — "Ara.T.Howard" <Ara.T.Howard@...> 2005/10/29

On Sat, 29 Oct 2005, James Edward Gray II wrote:

[#6486] Re: csv.rb a start on refactoring. — James Edward Gray II <james@...> 2005/10/29

On Oct 28, 2005, at 8:25 PM, Ara.T.Howard wrote:

[#6487] Re: csv.rb a start on refactoring. — "Ara.T.Howard" <Ara.T.Howard@...> 2005/10/29

On Sat, 29 Oct 2005, James Edward Gray II wrote:

[#6491] Re: csv.rb a start on refactoring. — James Edward Gray II <james@...> 2005/10/29

On Oct 28, 2005, at 8:43 PM, Ara.T.Howard wrote:

[#6493] Re: csv.rb a start on refactoring. — James Edward Gray II <james@...> 2005/10/29

On Oct 28, 2005, at 10:06 PM, James Edward Gray II wrote:

[#6496] Re: csv.rb a start on refactoring. — "Ara.T.Howard" <Ara.T.Howard@...> 2005/10/29

On Sun, 30 Oct 2005, James Edward Gray II wrote:

[#6502] Re: csv.rb a start on refactoring. — James Edward Gray II <james@...> 2005/10/30

On Oct 29, 2005, at 12:11 PM, Ara.T.Howard wrote:

[#6505] Re: csv.rb a start on refactoring. — "Ara.T.Howard" <Ara.T.Howard@...> 2005/10/30

On Mon, 31 Oct 2005, James Edward Gray II wrote:

[#6511] Planning FasterCSV (was Re: csv.rb a start on refactoring.) — James Edward Gray II <james@...> 2005/10/30

I've decided to create a FasterCSV library, based on the code we

[#6516] Re: Planning FasterCSV (was Re: csv.rb a start on refactoring.) — "Ara.T.Howard" <Ara.T.Howard@...> 2005/10/31

On Mon, 31 Oct 2005, James Edward Gray II wrote:

[#6518] Re: Planning FasterCSV (was Re: csv.rb a start on refactoring.) — "NAKAMURA, Hiroshi" <nakahiro@...> 2005/10/31

-----BEGIN PGP SIGNED MESSAGE-----

FileUtils.cp_r - when things go wrong.

From: Hugh Sasse <hgs@...>
Date: 2005-10-31 14:04:06 UTC
List: ruby-core #6522
At present, with FileUtils.cp_r if there is a problem the whole
opearation fails, however far it has got.  Using varios programs
under windows I have run into the problem that some files cannot be
copied to another disk because they are "in use by another process".
(I don't see why I cant read read the files, but still, the problem
exists.)  I'd like to be able to backup as much as I can to another
disk and not have the whole operation fail at some indeterminate
point; I'd rather the failures were logged and the process copied
the files it could copy, in this case.

The attached patch against 1.8 CVS allows a block to be passed to
FileUtils.cp_r so that when an error occurs the block is called.  If
the block returns nil or false then the operation carries on with the
other files.  If it returns a true value then the error is re-raised
and present behaviour (i.e. bailing out immediately) takes place.

I think this should not break existing code, but it will run a
little slower due to the begin...rescue...end block.

I was going test this on Cygwin, because it the copying fails on
Windows systems, but my update of Cygwin has completely corrupted
something (I'm getting messages about functions in CYGREADLINE.DLL
being missing.) so I can't test this at the moment.

Any comments?
       HTH
       Hugh

Attachments (1)

fileutils_diff (2.18 KB, text/plain)
--- orig_fileutils.rb	2005-09-24 00:56:42.000000000 +0100
+++ fileutils.rb	2005-10-31 11:23:42.427378000 +0000
@@ -28,8 +28,8 @@
 #   ln_sf(src, dest, options)
 #   cp(src, dest, options)
 #   cp(list, dir, options)
-#   cp_r(src, dest, options)
-#   cp_r(list, dir, options)
+#   cp_r(src, dest, options) {|source, dest, error| .... }
+#   cp_r(list, dir, options) {|source, dest, error| .... }
 #   mv(src, dest, options)
 #   mv(list, dir, options)
 #   rm(list, options)
@@ -398,11 +398,21 @@
   # all its contents recursively. If +dest+ is a directory, copies
   # +src+ to +dest/src+.
   #
+  # If a block is given then when an error occurs the block is
+  # called.  If the block returns +nil+ (which it will for a simple
+  # operation like +puts+ or +open(file, "w"){|f|...}+ or +false+,
+  # then #cp_r will continue working.  If the block returns
+  # anything true then the error will be re-raised so as to stop the
+  # recursive copy.  This has been added so that a hierarchy may be
+  # copied even when there are some failures (for example
+  # NTUSERS.DAT seems to fail on Windows because it is used by
+  # another process), but the errors can be logged.
+  #
   # +src+ can be a list of files.
   # 
   #   # Installing ruby library "mylib" under the site_ruby
-  #   FileUtils.rm_r site_ruby + '/mylib', :force
-  #   FileUtils.cp_r 'lib/', site_ruby + '/mylib'
+  #   FileUtils.rm_r site_ruby + '/mylib', :force FileUtils.cp_r
+  #   'lib/', site_ruby + '/mylib'
   # 
   #   # Examples of copying several files to target directory.
   #   FileUtils.cp_r %w(mail.rb field.rb debug/), site_ruby + '/tmail'
@@ -420,7 +430,15 @@
     return if options[:noop]
     options[:dereference_root] = true unless options.key?(:dereference_root)
     fu_each_src_dest(src, dest) do |s, d|
-      copy_entry s, d, options[:preserve], options[:dereference_root]
+      begin
+        copy_entry s, d, options[:preserve], options[:dereference_root]
+      rescue => e
+        stop = true   # If no block_given, fail as before
+        if block_given?
+          stop = yield s,d,e
+        end
+        raise if stop
+      end
     end
   end
   module_function :cp_r

In This Thread

Prev Next