Class: ICFS::StoreFs Deprecated
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
-
#file_read(cid, enum, lnum, fnum) ⇒ File, Tempfile
Read a file.
-
#file_size(cid, enum, lnum, fnum) ⇒ Integer
Get a file size.
-
#file_write(cid, enum, lnum, fnum, tmpf) ⇒ Object
Write a file.
-
#initialize(base) ⇒ StoreFs
constructor
New instance.
-
#tempfile ⇒ Tempfile
Get a Tempfile to use to write files.
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
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
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
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
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 |
#tempfile ⇒ Tempfile
Get a Tempfile to use to write files
77 78 79 |
# File 'lib/icfs/store_fs.rb', line 77 def tempfile Tempfile.new('tmp'.freeze, @base, :encoding => 'ascii-8bit'.freeze) end |