Module: FileUtils

Defined in:
lib/folio/fileutils.rb

Instance Method Summary collapse

Instance Method Details

#stage(stage_directory, files) ⇒ Object

Stage by hard linking included files to a stage directory.

stage_directory   Stage directory.
files             Files to link to stage.

TODO: Rename to linkstage or something less likely to name clash?



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/folio/fileutils.rb', line 12

def stage(stage_directory, files)
  return stage_directory if dryrun?           # Don't link to stage if dryrun.

  if File.directory?(stage_directory)         # Ensure existance of staging area
    #raise(OverwriteError, stage_directory) unless force?
    rm_r(stage_directory)
  end

  mkdir_p(stage_directory)                    #dir = File.expand_path(stage)

  # TODO: dryrun test here or before folder creation?

  files.each do |f|                 # Link files into staging area.
    file = File.join(stage_directory, f)
    if File.directory?(f)
      mkdir_p(file)
    else
      unless File.exist?(file) and File.mtime(file) >= File.mtime(f)
        ln(f, file) #safe_ln ?
      end
    end
  end

  return stage_directory
end