Class: File
- Inherits:
-
Object
- Object
- File
- Extended by:
- Solaris::Functions
- Includes:
- Solaris::Constants, Solaris::Functions, Solaris::Structs
- Defined in:
- lib/solaris/file.rb
Defined Under Namespace
Classes: Stat
Constant Summary collapse
- SOLARIS_VERSION =
The version of the solaris-file library
'0.4.0'
Constants included from Solaris::Constants
Solaris::Constants::ACL_DEFAULT, Solaris::Constants::CLASS_ERROR, Solaris::Constants::CLASS_OBJ, Solaris::Constants::DEF_CLASS_OBJ, Solaris::Constants::DEF_GROUP, Solaris::Constants::DEF_GROUP_OBJ, Solaris::Constants::DEF_OTHER_OBJ, Solaris::Constants::DEF_USER, Solaris::Constants::DEF_USER_OBJ, Solaris::Constants::DUPLICATE_ERROR, Solaris::Constants::ENTRY_ERROR, Solaris::Constants::GETACL, Solaris::Constants::GETACLCNT, Solaris::Constants::GROUP, Solaris::Constants::GROUP_OBJ, Solaris::Constants::GRP_ERROR, Solaris::Constants::MEM_ERROR, Solaris::Constants::MIN_ACL_ENTRIES, Solaris::Constants::MISS_ERROR, Solaris::Constants::OTHER_ERROR, Solaris::Constants::OTHER_OBJ, Solaris::Constants::SETACL, Solaris::Constants::USER, Solaris::Constants::USER_ERROR, Solaris::Constants::USER_OBJ
Class Method Summary collapse
-
.acl_count(file) ⇒ Object
Returns the number of ACL entries for the given file.
-
.acl_read(file) ⇒ Object
Reads ACL information for the given file.
-
.acl_read_text(file) ⇒ Object
Returns a textual representation of the ACL for the given file.
-
.acl_write_text(file, text) ⇒ Object
Sets the ACL for the given file using
text
. -
.door?(file) ⇒ Boolean
Returns true if the given file is door file, false otherwise.
-
.ftype(file) ⇒ Object
The same as the default ftype method, except that “door” is returned if the file is a door file.
- .ftype_orig ⇒ Object
-
.resolvepath(file) ⇒ Object
Resolves all symbolic links in the given path.
-
.trivial?(file) ⇒ Boolean
Returns true if the given file is a trivial file, i.e.
Instance Method Summary collapse
-
#acl_count ⇒ Object
Returns the number of ACL entries for the current file.
-
#acl_read ⇒ Object
Reads ACL information for the current file.
-
#acl_read_text ⇒ Object
Returns a textual representation of the ACL for the current file.
-
#acl_write_text(text) ⇒ Object
Sets the ACL for the current file using
text
. -
#trivial? ⇒ Boolean
Returns true if the current file is a trivial file, i.e.
Class Method Details
.acl_count(file) ⇒ Object
Returns the number of ACL entries for the given file. Returns 0 if the file is a trivial file.
267 268 269 270 271 272 273 |
# File 'lib/solaris/file.rb', line 267 def self.acl_count(file) num = acl(file, GETACLCNT, 0, nil) raise SystemCallError.new('acl', FFI.errno) if num < 0 num == MIN_ACL_ENTRIES ? 0 : num end |
.acl_read(file) ⇒ Object
Reads ACL information for the given file. Returns an array of ACLStruct’s that contain three members each:
-
acl_type (String)
-
acl_id (Integer)
-
acl_perm (Integer)
Example:
File.acl_read(file)
Returns nil if the file is a trivial file.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/solaris/file.rb', line 35 def self.acl_read(file) num = acl(file, GETACLCNT, 0, nil) if num < 0 raise SystemCallError.new('acl', FFI.errno) end arr = nil if num != MIN_ACL_ENTRIES ptr = FFI::MemoryPointer.new(AclEnt.new, num) if acl(file, GETACL, num, ptr) < 0 raise SystemCallError.new('acl', FFI.errno) end arr = [] num.times{ |i| ent = AclEnt.new(ptr[i]) arr << ACLStruct.new( acl_type_string(ent[:a_type]), ent[:a_id], ent[:a_perm] ) } end arr end |
.acl_read_text(file) ⇒ Object
Returns a textual representation of the ACL for the given file. If the file is a trivial file, nil is returned instead.
Example:
File.acl_read_text(file)
Sample output:
'user::rw-,user:nobody:r--,group::r--,group:sys:r--,mask:r--,other:r--'
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/solaris/file.rb', line 117 def self.acl_read_text(file) num = acl(file, GETACLCNT, 0, nil) if num < 0 raise SystemCallError.new('acl', FFI.errno) end text = nil if num != MIN_ACL_ENTRIES ptr = FFI::MemoryPointer.new(AclEnt.new, num) if acl(file, GETACL, num, ptr) < 0 raise SystemCallError.new('acl', FFI.errno) end text = acltotext(ptr, num) end text end |
.acl_write_text(file, text) ⇒ Object
Sets the ACL for the given file using text
. The text
argument is a human readable ACL text string.
If the text is invalid then a ArgumentError is raised, and in most cases the offending entry number will be identified.
Example:
File.acl_write_text(file, text)
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/solaris/file.rb', line 182 def self.acl_write_text(file, text) pnum = FFI::MemoryPointer.new(:int) pwhich = FFI::MemoryPointer.new(:int) ptr = aclfromtext(text, pnum) if ptr.null? raise ArgumentError, "invalid ACL text" end num = pnum.read_int val = aclcheck(ptr, num, pwhich) if val != 0 raise ArgumentError, aclcheck_string(val, pwhich.read_int) end if acl(file, SETACL, num, ptr) < 0 raise SystemCallError.new('acl', FFI.errno) end text end |
.door?(file) ⇒ Boolean
Returns true if the given file is door file, false otherwise. – Door files are special files used for interprocess communication between a client and server.
308 309 310 |
# File 'lib/solaris/file.rb', line 308 def self.door?(file) File.stat(file).door? end |
.ftype(file) ⇒ Object
The same as the default ftype method, except that “door” is returned if the file is a door file.
315 316 317 |
# File 'lib/solaris/file.rb', line 315 def self.ftype(file) File.stat(file).ftype end |
.ftype_orig ⇒ Object
18 |
# File 'lib/solaris/file.rb', line 18 alias ftype_orig ftype |
.resolvepath(file) ⇒ Object
Resolves all symbolic links in the given path. All “.” components are removed, as well as all nonleading “..” components and their preceding directory component.
If leading “..” components resolve to the root directory, they are replaced by “/”.
293 294 295 296 297 298 299 300 301 |
# File 'lib/solaris/file.rb', line 293 def self.resolvepath(file) ptr = FFI::MemoryPointer.new(:char, 1024) if resolvepath_c(file, ptr, ptr.size) < 0 raise SystemCallError.new('resolvepath', FFI.errno) end ptr.read_string end |
.trivial?(file) ⇒ Boolean
Returns true if the given file is a trivial file, i.e. has no additional ACL entries. Otherwise, it returns false.
245 246 247 248 249 250 251 |
# File 'lib/solaris/file.rb', line 245 def self.trivial?(file) num = acl(file, GETACLCNT, 0, nil) raise SystemCallError.new('acl', FFI.errno) if num < 0 num == MIN_ACL_ENTRIES end |
Instance Method Details
#acl_count ⇒ Object
Returns the number of ACL entries for the current file. Returns 0 if the file is a trivial file.
278 279 280 281 282 283 284 |
# File 'lib/solaris/file.rb', line 278 def acl_count num = facl(fileno, GETACLCNT, 0, nil) raise SystemCallError.new('facl', FFI.errno) if num < 0 num == MIN_ACL_ENTRIES ? 0 : num end |
#acl_read ⇒ Object
Reads ACL information for the current file. Returns an array of ACLStruct’s that contain three members each:
-
acl_type (String)
-
acl_id (Integer)
-
acl_perm (Integer)
Example:
file#acl_read
Returns nil if the file is a trivial file.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/solaris/file.rb', line 77 def acl_read num = facl(fileno, GETACLCNT, 0, nil) if num < 0 raise SystemCallError.new('facl', FFI.errno) end arr = nil if num != MIN_ACL_ENTRIES ptr = FFI::MemoryPointer.new(AclEnt.new, num) if facl(fileno, GETACL, num, ptr) < 0 raise SystemCallError.new('facl', FFI.errno) end arr = [] num.times{ |i| ent = AclEnt.new(ptr[i]) arr << ACLStruct.new( self.class.acl_type_string(ent[:a_type]), ent[:a_id], ent[:a_perm] ) } end arr end |
#acl_read_text ⇒ Object
Returns a textual representation of the ACL for the current file. If the file is a trivial file, nil is returned instead.
Example:
file#acl_read_text
Sample output:
'user::rw-,user:nobody:r--,group::r--,group:sys:r--,mask:r--,other:r--'
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/solaris/file.rb', line 150 def acl_read_text num = facl(fileno, GETACLCNT, 0, nil) if num < 0 raise SystemCallError.new('facl', FFI.errno) end text = nil if num != MIN_ACL_ENTRIES ptr = FFI::MemoryPointer.new(AclEnt.new, num) if facl(fileno, GETACL, num, ptr) < 0 raise SystemCallError.new('acl', FFI.errno) end text = acltotext(ptr, num) end text end |
#acl_write_text(text) ⇒ Object
Sets the ACL for the current file using text
. The text
argument is a human readable ACL text string.
If the text is invalid then a ArgumentError is raised, and in most cases the offending entry number will be identified.
Example:
file#acl_write_text(text)
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/solaris/file.rb', line 217 def acl_write_text(text) pnum = FFI::MemoryPointer.new(:int) pwhich = FFI::MemoryPointer.new(:int) ptr = aclfromtext(text, pnum) if ptr.null? raise ArgumentError, "invalid ACL text" end num = pnum.read_int val = aclcheck(ptr, num, pwhich) if val != 0 raise ArgumentError, aclcheck_string(val, pwhich.read_int) end if facl(fileno, SETACL, num, ptr) < 0 raise SystemCallError.new('facl', FFI.errno) end text end |
#trivial? ⇒ Boolean
Returns true if the current file is a trivial file, i.e. has no additional ACL entries. Otherwise, it returns false.
256 257 258 259 260 261 262 |
# File 'lib/solaris/file.rb', line 256 def trivial? num = facl(fileno, GETACLCNT, 0, nil) raise SystemCallError.new('facl', FFI.errno) if num < 0 num == MIN_ACL_ENTRIES end |