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



41
42
43
44
45
46
# File 'lib/talia_core/data_types/delayed_copier.rb', line 41

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

.cp(source, target) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/talia_core/data_types/delayed_copier.rb', line 24

def self.cp(source, target)
  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