module DRbQS::Temporary

Public Class Methods

delete() click to toggle source

Delete all temporary directory.

# File lib/drbqs/utility/temporary.rb, line 57
def self.delete
  if @root
    FileUtils.rm_r(@root)
    @pid = nil
    @root = nil
    @filename = nil
  end
end
directory() click to toggle source

Create new temporary directory and return the path of directory.

# File lib/drbqs/utility/temporary.rb, line 42
def self.directory
  filename.create(:add => :always, :directory => :self)
end
file(basename = nil) click to toggle source

Return new path of temporary file. @param [String] basename Set the basename of created filename

# File lib/drbqs/utility/temporary.rb, line 48
def self.file(basename = nil)
  if basename
    File.join(self.directory, basename)
  else
    filename.create(:add => :always, :directory => :parent)
  end
end
filename() click to toggle source

Return FileName object to generate names of temporary files on DRbQS nodes.

# File lib/drbqs/utility/temporary.rb, line 30
def self.filename
  unless @filename
    if @subdir
      @filename = FileName.new(File.join(@subdir, sprintf("temp_%d", rand(10000))))
    else
      @filename = FileName.new(File.join(self.root, sprintf("temp_%d", rand(10000))))
    end
  end
  @filename
end
root() click to toggle source

Return root of temporary directory.

# File lib/drbqs/utility/temporary.rb, line 11
def self.root
  if @pid != Process.pid
    @pid = Process.pid
    @root = File.join(Dir.tmpdir, sprintf("drbqs_%s_%d_%d", ENV['USER'], @pid, rand(10000)))
    FileUtils.mkdir_p(@root, :mode => 0700)
  end
  @root
end
set_sub_directory(dir) click to toggle source
# File lib/drbqs/utility/temporary.rb, line 20
def self.set_sub_directory(dir)
  @filename = nil
  @subdir = File.join(self.root, dir)
end
socket_path() click to toggle source
# File lib/drbqs/utility/temporary.rb, line 66
def self.socket_path
  FileName.create(self.root, "socket", :add => :always, :type => :time)
end
subdirectory() click to toggle source
# File lib/drbqs/utility/temporary.rb, line 25
def self.subdirectory
  @subdir && File.exist?(@subdir) ? @subdir : nil
end