Class: TaliaCore::DataTypes::DelayedCopier

Inherits:
Object
  • Object
show all
Defined in:
lib/talia_core/data_types/delayed_copier.rb

Overview

This is used for “delayed” copy operations. Basically this will created a file called “delayed_copy.sh” in the RAILS_ROOT, which can later be run as a bash script. This will allow the user to run the copy operation and be potentially faster than using the builtin copy operations (especially using JRuby)

Class Method Summary collapse

Class Method Details

.closeObject

Close the delayed copy file



49
50
51
52
53
54
# File 'lib/talia_core/data_types/delayed_copier.rb', line 49

def self.close
  if(@delayed_copy_file)
    @delayed_copy_file.close
    @delayed_copy_file = nil
  end
end

.cp(source, target) ⇒ Object

This writes the “cp” command to the output script. It will also add a “mkdir” command to create the directory for the target file, if necessary.

At the moment, this will always use UNIX-style “cp” and “mkdir” commands.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/talia_core/data_types/delayed_copier.rb', line 30

def self.cp(source, target)
  # We use the << in-place string concenation, 'cause if there
  # are a lot of files, it really makes a speed difference
  unless(dir_seen?(File.expand_path(target)))
    mkdir_string = 'mkdir -vp "'
    mkdir_string << File.dirname(File.expand_path(target))
    mkdir_string << '"'
    delayed_copy_file.puts(mkdir_string)
  end
  cp_string = 'cp -v "'
  cp_string << File.expand_path(source)
  cp_string << '" "'
  cp_string << File.expand_path(target)
  cp_string << '"'
  delayed_copy_file.puts(cp_string)
  delayed_copy_file.flush
end

.delayed_copy_fileObject

Returns (and creates, if necessary) the file to write the delayed copy operations to



15
16
17
18
19
20
21
22
# File 'lib/talia_core/data_types/delayed_copier.rb', line 15

def self.delayed_copy_file
  @delayed_copy_file ||= begin
    backup_file if(File.exists?(delay_file_name))
    file = File.open(delay_file_name, 'w')
    file.puts('#!/bin/bash')
    file
  end
end