class ZKSync::CryptoInode

Attributes

atime[RW]
ctime[RW]
ftype[RW]
gid[RW]
index[RW]
mode[RW]
mtime[RW]
path[RW]
sha256[RW]
size[RW]
uid[RW]

Public Class Methods

new(arg) click to toggle source
# 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

Public Instance Methods

equals(other) click to toggle source
# 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_width() click to toggle source
# File lib/zksync/crypto_inode.rb, line 33
def inode_width
  CryptoFileIndex.inode_width
end
set_from_fs(fs_path, opts={}) click to toggle source
# 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_used() click to toggle source
# File lib/zksync/crypto_inode.rb, line 37
def slots_used
  (to_s.length.to_f/inode_width).ceil
end
to_h() click to toggle source
# 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_json() click to toggle source
# File lib/zksync/crypto_inode.rb, line 74
def to_json
  to_h.to_json
end
to_s() click to toggle source

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

# File lib/zksync/crypto_inode.rb, line 79
def to_s
  json = to_json
  json.length.to_s + "|" + json
end