class ICFS::StoreFs
Permanent store for items using the filesystem
@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.
Public Class Methods
new(base)
click to toggle source
New instance
@param base [String] the base directory
# File lib/icfs/store_fs.rb, line 33 def initialize(base) if base[-1] == '/' @base = base.freeze else @base = (base + '/').freeze end end
Public Instance Methods
file_read(cid, enum, lnum, fnum)
click to toggle source
(see Store#file_read
)
# File lib/icfs/store_fs.rb, line 45 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)
click to toggle source
(see Store#file_size
)
# File lib/icfs/store_fs.rb, line 69 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)
click to toggle source
(see Store#file_write
)
# File lib/icfs/store_fs.rb, line 55 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
tempfile()
click to toggle source
(see Store#tempfile
)
# File lib/icfs/store_fs.rb, line 79 def tempfile Tempfile.new('tmp', @base, :encoding => 'ascii-8bit') end
Private Instance Methods
_read(fnam)
click to toggle source
Read an item
# File lib/icfs/store_fs.rb, line 90 def _read(fnam) return File.read(fnam, encoding: 'utf-8') rescue Errno::ENOENT return nil end
_write(fnam, item)
click to toggle source
Write an item
# File lib/icfs/store_fs.rb, line 100 def _write(fnam, item) File.open(fnam, 'w', encoding: 'utf-8') do |fi| fi.write(item) end rescue Errno::ENOENT FileUtils.mkdir_p(File.dirname(fnam)) File.open(fnam, 'w', encoding: 'utf-8') do |fi| fi.write(item) end end