Project

General

Profile

Actions

Bug #7246

closed

FileUtils.cp_r does not preserve attributes of directories

Added by wedesoft (Jan Wedekind) over 11 years ago. Updated about 11 years ago.

Status:
Closed
Target version:
ruby -v:
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.3.0]
Backport:
[ruby-core:48603]

Description

(({FileUtils.cp_r})) does not preserve the file attributes of directories because the attributes are set before copying to the directory.
The following monkey patch fixes this behaviour. However the monkey patch relies on the contents of the source directory not changing during the copy operation.

(({require 'fileutils'

def copy_entry(src, dest, preserve = false, dereference_root = false, remove_destination = false)
Entry_.new(src, nil, dereference_root).traverse do |ent|
destent = Entry_.new(dest, ent.rel, false)
File.unlink destent.path if remove_destination && File.file?(destent.path)
ent.copy destent.path
end
Entry_.new(src, nil, dereference_root).postorder_traverse do |ent|
destent = Entry_.new(dest, ent.rel, false)
ent.copy_metadata destent.path if preserve
end
end
module_function :copy_entry

end}))


Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #5419: FileUtils.cp_rの:preserveの動作Closedseki (Masatoshi Seki)Actions

Updated by wedesoft (Jan Wedekind) over 11 years ago

The following code might be a proper bugfix.

(({require 'fileutils'

module FileUtils

class Entry_

def wrap_traverse(pre, post)
  pre.call self
  if directory?
    entries.each do |ent|
      ent.wrap_traverse pre, post
    end
  end
  post.call self
end

end

def copy_entry(src, dest, preserve = false, dereference_root = false, remove_destination = false)
Entry_.new(src, nil, dereference_root).wrap_traverse(proc do |ent|
destent = Entry_.new(dest, ent.rel, false)
File.unlink destent.path if remove_destination && File.file?(destent.path)
ent.copy destent.path
end, proc do |ent|
destent = Entry_.new(dest, ent.rel, false)
ent.copy_metadata destent.path if preserve
end)
end
module_function :copy_entry

end}))

Updated by mame (Yusuke Endoh) over 11 years ago

  • Status changed from Open to Assigned
  • Assignee set to mame (Yusuke Endoh)
  • Target version set to 2.0.0

Thanks, I'll import your fix unless there is objection.

--
Yusuke Endoh

Actions #3

Updated by mame (Yusuke Endoh) about 11 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r39015.
Jan, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • lib/fileutils.rb (copy_entry, wrap_traverse): preserve attributes of
    directories on FileUtils.cp_r. The fix was proposed by Jan
    Wedekind. [Bug #7246]

  • test/fileutils/test_fileutils.rb: add a test for above.

Actions #4

Updated by jeremyevans0 (Jeremy Evans) almost 4 years ago

  • Related to Bug #5419: FileUtils.cp_rの:preserveの動作 added
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0