class FakeFS::File::Stat
Attributes
Public Class Methods
Source
# File lib/fakefs/file.rb, line 369 def initialize(file, lstat = false) raise(Errno::ENOENT, file.to_s) unless File.exist?(file) @file = file @fake_file = FileSystem.find(@file) @__lstat = lstat @ctime = @fake_file.ctime @mtime = @fake_file.mtime @atime = @fake_file.atime @mode = @fake_file.mode @uid = @fake_file.uid @gid = @fake_file.gid @inode = @fake_file.inode @birthtime = if @fake_file.respond_to?(:birthtime) @fake_file.birthtime else @fake_file.ctime end end
Public Instance Methods
Source
# File lib/fakefs/file.rb, line 403 def ftype return 'link' if symlink? return 'directory' if directory? 'file' end
Source
# File lib/fakefs/file.rb, line 409 def readable? # a file is readable if, and only if, it has the following bits: # 4 ( read permission ) # 5 ( read + execute permission ) # 6 ( read + write permission ) # 7 ( read + write + execute permission ) # for each group we will isolate the wanted numbers ( for owner, world, or group ) # and see if the third bit is set ( as that is the bit for read ) read_bit = 4 check_if_bit_set(read_bit) end
Source
# File lib/fakefs/file.rb, line 452 def size if @__lstat && symlink? @fake_file.target.size else File.size(@file) end end
Source
# File lib/fakefs/file.rb, line 434 def sticky? false end
Assume nothing is sticky.
Source
# File lib/fakefs/file.rb, line 440 def world_writable? 0o777 end
World_writable and readable are platform dependent usually comparing with S_IROTH defined on compilation (MRI)
Source
# File lib/fakefs/file.rb, line 421 def writable? # a file is writable if, and only if, it has the following bits: # 2 ( write permission ) # 3 ( write + execute permission ) # 6 ( read + write permission ) # 7 ( read + write + execute permission ) # for each group we will isolate the wanted numbers ( for owner, world, or group ) # and see if the second bit is set ( as that is the bit for write ) write_bit = 2 check_if_bit_set(write_bit) end
Private Instance Methods
Source
# File lib/fakefs/file.rb, line 476 def check_if_bit_set(bit) # get user's group and user ids # NOTE: I am picking `Process` over `Etc` as we use `Process` # when instaniating file classes. It may be worth it to ensure # our Process/Group detection scheme is robust in all cases uid = Process.uid gid = Process.gid # check if bit set for owner owner_bits = (@mode >> 6) & 0o7 if uid == @uid # the user is locked out of the file if they are owner of the file # but do not have the bit set at the user level return true if owner_bits & bit == bit return false end # check if bit set for group group_bits = (@mode >> 3) & 0o7 if gid == @gid # the user is locked out of the file if they are in the group that # owns the file but do not have the bit set at the group level return true if group_bits & bit == bit return false end # check if bit set for world world_bits = @mode & 0o7 return true if world_bits & bit == bit false end