Class: EventMachine::File::Stat
- Inherits:
-
Object
- Object
- EventMachine::File::Stat
- Defined in:
- lib/em-fs/file/stat.rb
Constant Summary collapse
- STAT_REGEX =
/(\d+) (\d+) '([\w\/ ]+)' (\d+) (\d+) (\d+) '(.+)' (\d+) (\d+) ([\d.]+) ([\d.]+) ([\d.]+)/.freeze
- STAT_FORMAT =
access rights octal —number of blocks allocated —the size in bytes of each block reported by %b device number in decimal —raw mode in hex file type group id number of hardlinks inode number —mount point file name —optimal IO transfer size hint total size in bytes –major device type in hex –minor device type in hex user id –time of birth time of last access time of last mod time of last change
"%a %d '%F' %g %h %i '%n' %s %u %X %Y %Z"- S_IFBLK =
Types
0b00000001
- S_IFCHR =
block device
0b00000010
- S_IFDIR =
character device
0b00000100
- S_IFIFO =
directory
0b00001000
- S_IFLNK =
FIFO/pipe
0b00010000
- S_IFREG =
symlink
0b00100000
- S_IFSOCK =
regular file
0b01000000
- S_UNKNOWN =
socket
0b10000000
- S_IRUSR =
Mode Flags
0b100000000
- S_IWUSR =
0b010000000
- S_IXUSR =
0b001000000
- S_IRGRP =
0b000100000
- S_IWGRP =
0b000010000
- S_IXGRP =
0b000001000
- S_IROTH =
0b000000100
- S_IWOTH =
0b000000010
- S_IXOTH =
0b000000001
Instance Attribute Summary collapse
-
#atime ⇒ Object
readonly
Returns the value of attribute atime.
-
#ctime ⇒ Object
readonly
Returns the value of attribute ctime.
-
#dev ⇒ Object
readonly
Returns the value of attribute dev.
-
#ftype ⇒ Object
readonly
Returns the value of attribute ftype.
-
#gid ⇒ Object
readonly
Returns the value of attribute gid.
-
#ino ⇒ Object
readonly
Returns the value of attribute ino.
-
#mtime ⇒ Object
readonly
Returns the value of attribute mtime.
-
#nlink ⇒ Object
readonly
Returns the value of attribute nlink.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#uid ⇒ Object
readonly
Returns the value of attribute uid.
Class Method Summary collapse
-
.parse(str) ⇒ EM::File::Stat
Parses a given string for file stat information.
Instance Method Summary collapse
- #blockdev? ⇒ Boolean
- #chardev? ⇒ Boolean
- #directory? ⇒ Boolean
- #executable? ⇒ Boolean
- #executable_real? ⇒ Boolean
- #file? ⇒ Boolean
- #grpowned? ⇒ Boolean
-
#initialize(val = {}) ⇒ Stat
constructor
A new instance of Stat.
- #mode ⇒ Object
- #owned? ⇒ Boolean
- #pipe? ⇒ Boolean
- #readable? ⇒ Boolean
- #readable_real? ⇒ Boolean
- #rgrpowned? ⇒ Boolean
- #rowned? ⇒ Boolean
- #socket? ⇒ Boolean
- #symlink? ⇒ Boolean
- #world_readable? ⇒ Boolean
- #world_writable? ⇒ Boolean
- #writable? ⇒ Boolean
- #writable_real? ⇒ Boolean
- #zero? ⇒ Boolean
Constructor Details
#initialize(val = {}) ⇒ Stat
Returns a new instance of Stat.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/em-fs/file/stat.rb', line 92 def initialize val = {} @path = val[:path] @atime = val[:atime] @ctime = val[:ctime] @dev = val[:dev] @ftype = val[:ftype] @gid = val[:gid] @ino = val[:ino] @mode = val[:mode] @mtime = val[:mtime] @nlink = val[:nlink] @size = val[:size] @uid = val[:uid] end |
Instance Attribute Details
#atime ⇒ Object (readonly)
Returns the value of attribute atime.
89 90 91 |
# File 'lib/em-fs/file/stat.rb', line 89 def atime @atime end |
#ctime ⇒ Object (readonly)
Returns the value of attribute ctime.
89 90 91 |
# File 'lib/em-fs/file/stat.rb', line 89 def ctime @ctime end |
#dev ⇒ Object (readonly)
Returns the value of attribute dev.
89 90 91 |
# File 'lib/em-fs/file/stat.rb', line 89 def dev @dev end |
#ftype ⇒ Object (readonly)
Returns the value of attribute ftype.
89 90 91 |
# File 'lib/em-fs/file/stat.rb', line 89 def ftype @ftype end |
#gid ⇒ Object (readonly)
Returns the value of attribute gid.
89 90 91 |
# File 'lib/em-fs/file/stat.rb', line 89 def gid @gid end |
#ino ⇒ Object (readonly)
Returns the value of attribute ino.
89 90 91 |
# File 'lib/em-fs/file/stat.rb', line 89 def ino @ino end |
#mtime ⇒ Object (readonly)
Returns the value of attribute mtime.
89 90 91 |
# File 'lib/em-fs/file/stat.rb', line 89 def mtime @mtime end |
#nlink ⇒ Object (readonly)
Returns the value of attribute nlink.
89 90 91 |
# File 'lib/em-fs/file/stat.rb', line 89 def nlink @nlink end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
89 90 91 |
# File 'lib/em-fs/file/stat.rb', line 89 def path @path end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
89 90 91 |
# File 'lib/em-fs/file/stat.rb', line 89 def size @size end |
#uid ⇒ Object (readonly)
Returns the value of attribute uid.
89 90 91 |
# File 'lib/em-fs/file/stat.rb', line 89 def uid @uid end |
Class Method Details
.parse(str) ⇒ EM::File::Stat
Parses a given string for file stat information.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/em-fs/file/stat.rb', line 58 def parse str if m = str.match(STAT_REGEX) ftype = case m[3] when 'block device' then S_IFBLK when 'character device' then S_IFCHR when 'directory' then S_IFDIR when 'FIFO/pipe' then S_IFIFO when 'symlink' then S_IFLNK when 'regular file' then S_IFREG when 'socket' then S_IFSOCK else S_UNKNOWN end EM::File::Stat.new path: m[7], atime: Time.at(Integer(m[10].split('.')[0], 10)), ctime: Time.at(Integer(m[12].split('.')[0], 10)), dev: Integer(m[2], 10), ftype: ftype, gid: Integer(m[4], 10), ino: Integer(m[6], 10), mode: Integer(m[1], 8), mtime: Time.at(Integer(m[11].split('.')[0], 10)), nlink: Integer(m[5], 10), size: Integer(m[8], 10), uid: Integer(m[9], 10) else raise "Unable to parse stat string: #{str}" end end |
Instance Method Details
#blockdev? ⇒ Boolean
107 108 109 |
# File 'lib/em-fs/file/stat.rb', line 107 def blockdev? ftype^S_IFBLK == 0 end |
#chardev? ⇒ Boolean
111 112 113 |
# File 'lib/em-fs/file/stat.rb', line 111 def chardev? ftype^S_IFCHR == 0 end |
#directory? ⇒ Boolean
115 116 117 |
# File 'lib/em-fs/file/stat.rb', line 115 def directory? ftype^S_IFDIR == 0 end |
#executable? ⇒ Boolean
119 120 121 122 123 124 |
# File 'lib/em-fs/file/stat.rb', line 119 def executable? return true if Process::UID.rid == 0 return @mode & S_IXUSR != 0 if rowned? return @mode & S_IXGRP != 0 if rgrpowned? @mode & S_IXOTH != 0 end |
#executable_real? ⇒ Boolean
126 127 128 129 130 131 |
# File 'lib/em-fs/file/stat.rb', line 126 def executable_real? return true if Process::UID.rid == 0 return @mode & S_IXUSR != 0 if rowned? return @mode & S_IXGRP != 0 if rgrpowned? @mode & S_IXOTH != 0 end |
#file? ⇒ Boolean
133 134 135 |
# File 'lib/em-fs/file/stat.rb', line 133 def file? ftype^S_IFREG == 0 end |
#grpowned? ⇒ Boolean
137 138 139 |
# File 'lib/em-fs/file/stat.rb', line 137 def grpowned? gid == Process::GID.eid end |
#mode ⇒ Object
145 146 147 |
# File 'lib/em-fs/file/stat.rb', line 145 def mode @mode.to_s(8) end |
#owned? ⇒ Boolean
149 150 151 |
# File 'lib/em-fs/file/stat.rb', line 149 def owned? uid == Process::UID.eid end |
#pipe? ⇒ Boolean
157 158 159 |
# File 'lib/em-fs/file/stat.rb', line 157 def pipe? ftype^S_IFIFO == 0 end |
#readable? ⇒ Boolean
161 162 163 164 165 166 |
# File 'lib/em-fs/file/stat.rb', line 161 def readable? return true if Process::UID.eid == 0 return @mode & S_IRUSR != 0 if owned? return @mode & S_IRGRP != 0 if grpowned? @mode & S_IROTH != 0 end |
#readable_real? ⇒ Boolean
168 169 170 171 172 173 |
# File 'lib/em-fs/file/stat.rb', line 168 def readable_real? return true if Process::UID.rid == 0 return @mode & S_IRUSR != 0 if rowned? return @mode & S_IRGRP != 0 if rgrpowned? @mode & S_IROTH != 0 end |
#rgrpowned? ⇒ Boolean
141 142 143 |
# File 'lib/em-fs/file/stat.rb', line 141 def rgrpowned? gid == Process::GID.rid end |
#rowned? ⇒ Boolean
153 154 155 |
# File 'lib/em-fs/file/stat.rb', line 153 def rowned? uid == Process::UID.rid end |
#socket? ⇒ Boolean
175 176 177 |
# File 'lib/em-fs/file/stat.rb', line 175 def socket? ftype^S_IFSOCK == 0 end |
#symlink? ⇒ Boolean
179 180 181 |
# File 'lib/em-fs/file/stat.rb', line 179 def symlink? ftype^S_IFLNK == 0 end |
#world_readable? ⇒ Boolean
183 184 185 |
# File 'lib/em-fs/file/stat.rb', line 183 def world_readable? @mode if @mode & S_IROTH == S_IROTH end |
#world_writable? ⇒ Boolean
187 188 189 |
# File 'lib/em-fs/file/stat.rb', line 187 def world_writable? @mode if @mode & S_IWOTH == S_IWOTH end |
#writable? ⇒ Boolean
191 192 193 194 195 196 |
# File 'lib/em-fs/file/stat.rb', line 191 def writable? return true if Process::UID.rid == 0 return @mode & S_IWUSR != 0 if owned? return @mode & S_IWGRP != 0 if grpowned? @mode & S_IWOTH != 0 end |
#writable_real? ⇒ Boolean
198 199 200 201 202 203 |
# File 'lib/em-fs/file/stat.rb', line 198 def writable_real? return true if Process::UID.rid == 0 return @mode & S_IWUSR != 0 if rowned? return @mode & S_IWGRP != 0 if rgrpowned? @mode & S_IWOTH != 0 end |
#zero? ⇒ Boolean
205 206 207 |
# File 'lib/em-fs/file/stat.rb', line 205 def zero? @size == 0 end |