Class: MogileFS::NFSFile

Inherits:
File
  • Object
show all
Defined in:
lib/mogilefs/nfsfile.rb

Overview

NFSFile wraps up the new file operations for storing files onto an NFS storage node.

You really don’t want to create an NFSFile by hand. Instead you want to create a new file using MogileFS::MogileFS.new_file.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#classObject (readonly)

The class of this file.



26
27
28
# File 'lib/mogilefs/nfsfile.rb', line 26

def class
  @class
end

#keyObject (readonly)

The key for this file. This key won’t represent a real file until you’ve called #close.



21
22
23
# File 'lib/mogilefs/nfsfile.rb', line 21

def key
  @key
end

#pathObject (readonly)

The path of this file not including the local mount point.



15
16
17
# File 'lib/mogilefs/nfsfile.rb', line 15

def path
  @path
end

Class Method Details

.new(mg, fid, path, devid, klass, key) ⇒ Object

Wraps up File.new with MogileFS-specific data. Use MogileFS::MogileFS#new_file instead of this method.



34
35
36
37
38
# File 'lib/mogilefs/nfsfile.rb', line 34

def new(mg, fid, path, devid, klass, key)
  fp = super join(mg.root, path), 'w+'
  fp.send :setup, mg, fid, path, devid, klass, key
  return fp
end

.open(mg, fid, path, devid, klass, key, &block) ⇒ Object

Wraps up File.open with MogileFS-specific data. Use MogileFS::MogileFS#new_file instead of this method.



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/mogilefs/nfsfile.rb', line 44

def open(mg, fid, path, devid, klass, key, &block)
  fp = new mg, fid, path, devid, klass, key

  return fp if block.nil?

  begin
    yield fp
  ensure
    fp.close
  end
end

Instance Method Details

#closeObject

Closes the file handle and marks it as closed in MogileFS.



61
62
63
64
65
66
67
# File 'lib/mogilefs/nfsfile.rb', line 61

def close
  super
  @mg.backend.create_close(:fid => @fid, :devid => @devid,
                           :domain => @mg.domain, :key => @key,
                           :path => @path)
  return nil
end