Class: ZKSync::CryptoInode

Inherits:
Object
  • Object
show all
Defined in:
lib/zksync/crypto_inode.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arg) ⇒ CryptoInode

Returns a new instance of CryptoInode.



22
23
24
25
26
27
28
29
30
31
# File 'lib/zksync/crypto_inode.rb', line 22

def initialize(arg)
  if arg.is_a?(String)
    @path = arg
  else
    arg.each do |k,v|
      v = Time.parse(v) if [:atime, :mtime].include?(k.to_sym)
      self.send(:"#{k}=", v)
    end
  end
end

Instance Attribute Details

#atimeObject

Returns the value of attribute atime.



20
21
22
# File 'lib/zksync/crypto_inode.rb', line 20

def atime
  @atime
end

#ctimeObject

Returns the value of attribute ctime.



20
21
22
# File 'lib/zksync/crypto_inode.rb', line 20

def ctime
  @ctime
end

#ftypeObject

Returns the value of attribute ftype.



20
21
22
# File 'lib/zksync/crypto_inode.rb', line 20

def ftype
  @ftype
end

#gidObject

Returns the value of attribute gid.



20
21
22
# File 'lib/zksync/crypto_inode.rb', line 20

def gid
  @gid
end

#indexObject

Returns the value of attribute index.



20
21
22
# File 'lib/zksync/crypto_inode.rb', line 20

def index
  @index
end

#modeObject

Returns the value of attribute mode.



20
21
22
# File 'lib/zksync/crypto_inode.rb', line 20

def mode
  @mode
end

#mtimeObject

Returns the value of attribute mtime.



20
21
22
# File 'lib/zksync/crypto_inode.rb', line 20

def mtime
  @mtime
end

#pathObject

Returns the value of attribute path.



20
21
22
# File 'lib/zksync/crypto_inode.rb', line 20

def path
  @path
end

#sha256Object

Returns the value of attribute sha256.



20
21
22
# File 'lib/zksync/crypto_inode.rb', line 20

def sha256
  @sha256
end

#sizeObject

Returns the value of attribute size.



20
21
22
# File 'lib/zksync/crypto_inode.rb', line 20

def size
  @size
end

#uidObject

Returns the value of attribute uid.



20
21
22
# File 'lib/zksync/crypto_inode.rb', line 20

def uid
  @uid
end

Instance Method Details

#equals(other) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/zksync/crypto_inode.rb', line 62

def equals(other)
  [ :path, :mtime, :ctime, :atime, :mode, :uid, :gid, :size, :ftype, :sha256 ].each do |key|
    return false unless self.send(key) == other.send(key)
  end

  true
end

#inode_widthObject



33
34
35
# File 'lib/zksync/crypto_inode.rb', line 33

def inode_width
  CryptoFileIndex.inode_width
end

#set_from_fs(fs_path, opts = {}) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/zksync/crypto_inode.rb', line 41

def set_from_fs(fs_path, opts={})
  stat = File.stat(fs_path)

  @fs_path = fs_path
  @atime = stat.atime
  @mtime = stat.mtime
  @ctime = stat.ctime
  @ftype = stat.ftype
  @gid = stat.gid
  @mode = stat.mode
  @size = stat.ftype == "directory" ? 0 : stat.size
  @uid = stat.uid
  sha256 if opts[:hash]
end

#slots_usedObject



37
38
39
# File 'lib/zksync/crypto_inode.rb', line 37

def slots_used
  (to_s.length.to_f/inode_width).ceil
end

#to_hObject



70
71
72
# File 'lib/zksync/crypto_inode.rb', line 70

def to_h
  { path:path, mtime:mtime, ctime:ctime, atime:atime, mode:mode, uid:uid, gid:gid, size:size, ftype:ftype, sha256:sha256 }
end

#to_jsonObject



74
75
76
# File 'lib/zksync/crypto_inode.rb', line 74

def to_json
  to_h.to_json
end

#to_sObject

string is json right-space-padded to a multiple of inode_width, so we can reuse lines in @@index



79
80
81
82
# File 'lib/zksync/crypto_inode.rb', line 79

def to_s
  json = to_json
  json.length.to_s + "|" + json
end