Class: ICFS::StoreFs Deprecated

Inherits:
Store
  • Object
show all
Defined in:
lib/icfs/store_fs.rb

Overview

Deprecated.

Using a filesystem for a production system is a horrible idea. This is provided as an example and should be used for development use only.

Permanent store for items using the filesystem

Instance Method Summary collapse

Methods inherited from Store

#action_read, #action_write, #case_read, #case_write, #close, #entry_read, #entry_write, #index_read, #index_write, #log_read, #log_write

Constructor Details

#initialize(base) ⇒ StoreFs

New instance

Parameters:

  • base (String)

    the base directory



31
32
33
34
35
36
37
# File 'lib/icfs/store_fs.rb', line 31

def initialize(base)
  if base[-1] == '/'.freeze
    @base = base.freeze
  else
    @base = (base + '/').freeze
  end
end

Instance Method Details

#file_read(cid, enum, lnum, fnum) ⇒ File, Tempfile

Read a file

Parameters:

  • cid (String)

    caseid

  • enum (Integer)

    Entry number

  • lnum (Integer)

    Log number

  • fnum (Integer)

    File number

Returns:

  • (File, Tempfile)

    Read only copy of the file



43
44
45
46
47
# File 'lib/icfs/store_fs.rb', line 43

def file_read(cid, enum, lnum, fnum)
  File.open(_file(cid, enum, lnum, fnum), 'rb')
rescue Errno::ENOENT
  return nil
end

#file_size(cid, enum, lnum, fnum) ⇒ Integer

Get a file size

Parameters:

  • cid (String)

    caseid

  • enum (Integer)

    Entry number

  • lnum (Integer)

    Log number

  • fnum (Integer)

    File number

Returns:

  • (Integer)

    The size of the file



67
68
69
70
71
# File 'lib/icfs/store_fs.rb', line 67

def file_size(cid, enum, lnum, fnum)
  File.size(_file(cid, enum, lnum, fnum))
rescue Errno::ENOENT
  return nil
end

#file_write(cid, enum, lnum, fnum, tmpf) ⇒ Object

Write a file

Parameters:

  • cid (String)

    caseid

  • enum (Integer)

    Entry number

  • lnum (Integer)

    Log number

  • fnum (Integer)

    File number

  • tmpf (Tempfile)

    A Tempfile obtained from #tempfile



53
54
55
56
57
58
59
60
61
# File 'lib/icfs/store_fs.rb', line 53

def file_write(cid, enum, lnum, fnum, tmpf)
  fn = _file(cid, enum, lnum, fnum)
  FileUtils.ln(tmpf.path, fn, force: true)
  tmpf.close!
rescue Errno::ENOENT
  FileUtils.mkdir_p(File.dirname(fn))
  FileUtils.ln(tmpf.path, fn, force: true)
  tmpf.close!
end

#tempfileTempfile

Get a Tempfile to use to write files

Returns:

  • (Tempfile)

    a Tempfile which can be written and passed to #file_write



77
78
79
# File 'lib/icfs/store_fs.rb', line 77

def tempfile
  Tempfile.new('tmp'.freeze, @base, :encoding => 'ascii-8bit'.freeze)
end