1

Looking at the Fileutils.cp_r documentation, it seems to be using cp -r in a shell. This command will ignore subdirectories that are empty (at least on my OS X 10.9 machine).

Can anyone suggest a solution that would allow me to include the empty subdirectories?

EDIT: cp -r in my shell does in fact copy the empty subdirectories, so now I am even more confused...

David Hall
  • 515
  • 6
  • 13
  • Both Ruby's `cp_r` and the OS's `cp -r` should copy empty directories as they are significant. I'd suggest retesting carefully. – the Tin Man Jul 31 '14 at 15:27
  • Yes, I think that there is something fishy going on here. I'll investigate.. – David Hall Jul 31 '14 at 15:30
  • @DavidHall you should add the last part as an actual answer and accept that. It allows other visitor to quickly see the answer and will mark the question as "done". – Patrick Oscity Jul 31 '14 at 16:12
  • @p11y Thanks, unfortunately I have to wait 2 days before I can accept my own answer – David Hall Jul 31 '14 at 16:34
  • It's not necessary to add the "Resolved" note. We can tell the question/problem is resolved when an answer is selected. – the Tin Man Jul 31 '14 at 16:58

3 Answers3

1

Strange. It should copy even the empty directories. I checked on Linux and OSX, here you got the session from OSX:

% mkdir empty
% ruby -e "require 'fileutils'; FileUtils.cp_r 'empty', 'double'"
% ls -ld double
drwxr-xr-x  2 grych  staff  68 Jul 31 17:22 double
Grych
  • 2,861
  • 13
  • 22
0

I was writing a file within the Homebrew package manager, and it turns out that their build environment deletes empty directories at the end.

David Hall
  • 515
  • 6
  • 13
0

Wow - So I just ran into this issue while developing a gem. Theres two important things to note:

A gemspec often builds from the available files in git:

Gem::Specification.new do |spec|
  spec.files         = `git ls-files -z`.split("\x0")
end

Git however, will ignore empty directories from version control.

I was able to work around the issue by adding a .keep file to ALL empty directories, including their nested empty directories, and the issue was resolved. Which could explain the shell vs ruby scenario in your example.

More information on keep files here: Random 'concerns' folders and '.keep' files

Community
  • 1
  • 1
random-forest-cat
  • 33,652
  • 11
  • 120
  • 99