solaris-file 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,11 @@
1
+ == 0.3.3 - 20-Aug-2007
2
+ * Added the File.door? method, and the underlying File::Stat#door? method,
3
+ that returns whether or not the file is a door file.
4
+ * Modified the File.ftype method, and the underlying File::Stat#ftype method,
5
+ so that the word 'door' is returned if the file is a door file.
6
+ * Added tests for the new and updated methods.
7
+ * These modifications were inspired by Hiro Asari (ruby-core: 11890).
8
+
1
9
  == 0.3.2 - 24-Jul-2007
2
10
  * Added a Rakefile with tasks for testing and installation.
3
11
  * Fixed an internal function name that conflicted with one in the acl.h file.
data/README CHANGED
@@ -1,32 +1,31 @@
1
1
  == Description
2
- Adds ACL support for the File class on Solaris.
2
+ Adds ACL support and Door methods for the File class on Solaris.
3
3
 
4
4
  == Prerequisites
5
5
  Ruby 1.8.x
6
6
 
7
7
  == Installation
8
- === Manual Installation
9
8
  rake test (optional)
10
- rake install
11
-
12
- === Gem Install
13
- rake test (optional)
14
- rake install_gem
9
+ rake install (non-gem) OR rake install_gem (gem)
15
10
 
16
11
  == Synopsis
17
- require "solaris/file"
12
+ require 'solaris/file'
18
13
 
19
- f = "some_file.txt"
14
+ f = 'some_file.txt'
20
15
  acl_text = "user::rw-,user:nobody:r--,"
21
16
  acl_text << "group::r--,group:sys:r--,mask:r--,other:r--"
22
17
 
23
- File.trivial?(f) # probably true
18
+ File.trivial?(f) # => true (probably)
24
19
  File.acl_write_text(acl_text)
25
20
 
26
21
  # No longer a trivial file
27
- File.trivial?(f) # false
22
+ File.trivial?(f) # => false
28
23
  File.acl_read(f).each{ |acl| p acl }
29
24
 
25
+ # Door file?
26
+ File.door?("/var/run/syslog_door") # => true
27
+ File.ftype("/var/run/syslog_door") # => 'door'
28
+
30
29
  == Class Methods
31
30
  File.acl_count(file_name)
32
31
  Returns the number of ACL entries for the file. Returns 0 if it's a
@@ -42,6 +41,12 @@ Fiel.acl_read_text(file_name)
42
41
  File.acl_write_text(file_name, acl_string)
43
42
  Accepts a formatted ACL string that set the ACL for the file. If the
44
43
  string is badly formed, a File::SolarisError is raised.
44
+
45
+ File.door?(file_name)
46
+ Returns whether or not +file_name+ is a Door file.
47
+
48
+ File.ftype(file_name)
49
+ Modified so that it returns the word 'door' if +file_name+ is a door file.
45
50
 
46
51
  File.realpath(path)
47
52
  Resolves all symbolic links in +path+. Resolves to an absolute pathname
@@ -57,7 +62,7 @@ File.trivial?(file_name)
57
62
  Returns true if the file is a trivial ACL file, i.e. has no ACL entries for
58
63
  additional users or groups.
59
64
 
60
- = Instance Methods
65
+ = File Instance Methods
61
66
  File#acl_count
62
67
  Returns the number of ACL entries for the file. Returns 0 if it's a
63
68
  trivial file.
@@ -77,6 +82,14 @@ File#trivial?
77
82
  Returns true if the file is a trivial ACL file, i.e. has no ACL entries for
78
83
  additional users or groups
79
84
 
85
+ = File::Stat Instance Methods
86
+ File::Stat#door?
87
+ Returns whether or not the stat object is a door file.
88
+
89
+ File::Stat#ftype
90
+ Modified so that the stat object returns the word 'door' if the stat file
91
+ is a Door file.
92
+
80
93
  == Constants
81
94
  File::SOLARIS_VERSION
82
95
  Returns the current version number of this package as a String.
data/ext/solaris/sfile.c CHANGED
@@ -1,9 +1,11 @@
1
- #include "ruby.h"
2
- #include "rubyio.h"
1
+ #include <ruby.h>
2
+ #include <rubyio.h>
3
3
  #include <sys/acl.h>
4
4
  #include <sys/param.h>
5
+ #include <sys/stat.h>
5
6
  #include <unistd.h>
6
- #include "sfile.h"
7
+ #include <fcntl.h>
8
+ #include <sfile.h>
7
9
 
8
10
  /*
9
11
  * call-seq:
@@ -39,9 +41,9 @@ static VALUE acl_count(VALUE klass, VALUE v_path){
39
41
  */
40
42
  static VALUE acl_icount(VALUE self){
41
43
  int num_acls = 0;
42
- int fildes = FIX2INT(rb_funcall(self,rb_intern("fileno"), 0, 0));
44
+ int fd = FIX2INT(rb_funcall(self,rb_intern("fileno"), 0, 0));
43
45
 
44
- if((num_acls = facl(fildes, GETACLCNT, 0, NULL)) == -1)
46
+ if((num_acls = facl(fd, GETACLCNT, 0, NULL)) == -1)
45
47
  rb_sys_fail(0);
46
48
 
47
49
  if(num_acls == MIN_ACL_ENTRIES)
@@ -117,10 +119,10 @@ static VALUE acl_read(VALUE klass, VALUE v_path){
117
119
  static VALUE acl_iread(VALUE self){
118
120
  int i;
119
121
  int num_acls = 0;
120
- int fildes = FIX2INT(rb_funcall(self, rb_intern("fileno"), 0, 0));
122
+ int fd = FIX2INT(rb_funcall(self, rb_intern("fileno"), 0, 0));
121
123
  VALUE v_array = Qnil;
122
124
 
123
- if( (num_acls = facl(fildes, GETACLCNT, 0, NULL)) == -1)
125
+ if( (num_acls = facl(fd, GETACLCNT, 0, NULL)) == -1)
124
126
  rb_sys_fail(0);
125
127
 
126
128
  if(num_acls != MIN_ACL_ENTRIES){
@@ -130,7 +132,7 @@ static VALUE acl_iread(VALUE self){
130
132
  if( (acl_buf = malloc(sizeof(aclent_t) * num_acls) ) == NULL)
131
133
  rb_sys_fail(0);
132
134
 
133
- if(facl(fildes, GETACL, num_acls, acl_buf) != num_acls)
135
+ if(facl(fd, GETACL, num_acls, acl_buf) != num_acls)
134
136
  rb_sys_fail(0);
135
137
 
136
138
  for(i = 0; i < num_acls; i++){
@@ -251,7 +253,7 @@ static VALUE solaris_resolvepath(VALUE klass, VALUE v_path){
251
253
  * call-seq:
252
254
  * File.realpath(path)
253
255
  *
254
- * Resolves all symbolic links in +path+. Resolves to an absolute pathname
256
+ * Resolves all symbolic links in +path+. Resolves to an absolute pathname
255
257
  * where possible.
256
258
  *
257
259
  * The difference between this method and File.resolvepath is that this method
@@ -277,14 +279,14 @@ static VALUE solaris_realpath(VALUE klass, VALUE v_path){
277
279
  * Sets the ACL for the file using +acl_text+. The +acl_text+ argument is a
278
280
  * human readable ACL text String.
279
281
  *
280
- * If +acl_text+ is invalid then a File::SolarisError is raised, and in most
282
+ * If +acl_text+ is invalid then a File::Solaris::Error is raised, and in most
281
283
  * cases the offending entry number will be identified.
282
284
  */
283
285
  static VALUE acl_iwrite_text(VALUE self, VALUE v_text){
284
286
  aclent_t* acl_buf;
285
287
  int num_acls, which;
286
288
  char* acl_text = StringValuePtr(v_text);
287
- int fildes = FIX2INT(rb_funcall(self, rb_intern("fileno"), 0, 0));
289
+ int fd = FIX2INT(rb_funcall(self, rb_intern("fileno"), 0, 0));
288
290
  int rv;
289
291
 
290
292
  SafeStringValue(v_text);
@@ -295,7 +297,7 @@ static VALUE acl_iwrite_text(VALUE self, VALUE v_text){
295
297
  rv = aclcheck(acl_buf, num_acls, &which);
296
298
  do_acl_check(rv, which);
297
299
 
298
- if(facl(fildes, SETACL, num_acls, acl_buf) == -1){
300
+ if(facl(fd, SETACL, num_acls, acl_buf) == -1){
299
301
  free(acl_text);
300
302
  rb_sys_fail(0);
301
303
  }
@@ -317,10 +319,10 @@ static VALUE acl_iwrite_text(VALUE self, VALUE v_text){
317
319
  static VALUE acl_iread_text(VALUE self){
318
320
  char* acl_text;
319
321
  int num_acls = 0;
320
- int fildes = FIX2INT(rb_funcall(self,rb_intern("fileno"),0,0));
322
+ int fd = FIX2INT(rb_funcall(self,rb_intern("fileno"),0,0));
321
323
  VALUE v_text = Qnil;
322
324
 
323
- if( (num_acls = facl(fildes,GETACLCNT,0,NULL)) == -1)
325
+ if( (num_acls = facl(fd,GETACLCNT,0,NULL)) == -1)
324
326
  rb_sys_fail(0);
325
327
 
326
328
  if(num_acls != MIN_ACL_ENTRIES){
@@ -329,7 +331,7 @@ static VALUE acl_iread_text(VALUE self){
329
331
  if( (acl_buf = malloc(sizeof(aclent_t) * num_acls) ) == NULL)
330
332
  rb_sys_fail(0);
331
333
 
332
- if(facl(fildes, GETACL, num_acls, acl_buf) != num_acls)
334
+ if(facl(fd, GETACL, num_acls, acl_buf) != num_acls)
333
335
  rb_sys_fail(0);
334
336
 
335
337
  acl_text = acltotext(acl_buf,num_acls);
@@ -346,7 +348,7 @@ static VALUE acl_iread_text(VALUE self){
346
348
  * File.trivial?(file_name)
347
349
  *
348
350
  * Returns true if +file_name+ is a trivial file, i.e. has no additional ACL
349
- * entries. Otherwise, it returns false.
351
+ * entries. Otherwise, it returns false.
350
352
  */
351
353
  static VALUE acl_is_trivial(VALUE klass, VALUE v_path){
352
354
  char pathp[PATH_MAX];
@@ -375,11 +377,11 @@ static VALUE acl_is_trivial(VALUE klass, VALUE v_path){
375
377
  * ACL entries. Otherwise, it returns false.
376
378
  */
377
379
  static VALUE acl_itrivial(VALUE self){
378
- int fildes = FIX2INT(rb_funcall(self,rb_intern("fileno"),0,0));
380
+ int fd = FIX2INT(rb_funcall(self, rb_intern("fileno"), 0, 0));
379
381
  int num_acls = 0;
380
382
  VALUE v_bool = Qfalse;
381
383
 
382
- if( (num_acls = facl(fildes,GETACLCNT,0,NULL)) == -1)
384
+ if( (num_acls = facl(fd, GETACLCNT, 0, NULL)) == -1)
383
385
  rb_sys_fail(0);
384
386
 
385
387
  if(num_acls == MIN_ACL_ENTRIES)
@@ -388,6 +390,55 @@ static VALUE acl_itrivial(VALUE self){
388
390
  return v_bool;
389
391
  }
390
392
 
393
+ /* File::Stat Additions */
394
+
395
+ /*
396
+ * call-seq:
397
+ * statfile.door?
398
+ *
399
+ * Returns true if +statfile+ is a door, false otherwise.
400
+ */
401
+ static VALUE solaris_stat_is_door(VALUE self){
402
+ struct stat stat_buf;
403
+ VALUE v_bool = Qtrue;
404
+ int mode = FIX2INT(rb_funcall(self, rb_intern("mode"), 0, 0));
405
+
406
+ if(S_ISDOOR(mode) == 0)
407
+ v_bool = Qfalse;
408
+
409
+ return v_bool;
410
+ }
411
+
412
+ static VALUE solaris_stat_ftype(VALUE self){
413
+ int mode = FIX2INT(rb_funcall(self, rb_intern("mode"), 0, 0));
414
+
415
+ if(S_ISDOOR(mode))
416
+ return rb_str_new2("door");
417
+ else
418
+ return rb_funcall(self, rb_intern("old_ftype"), 0, 0);
419
+ }
420
+
421
+ /* call-seq:
422
+ * File.door?(file)
423
+ *
424
+ * Returns true if +file+ is a door file, false otherwise.
425
+ */
426
+ static VALUE solaris_file_is_door(VALUE klass, VALUE v_file){
427
+ VALUE v_stat = rb_funcall(rb_cStat, rb_intern("new"), 1, v_file);
428
+ return solaris_stat_is_door(v_stat);
429
+ }
430
+
431
+ /* call-seq:
432
+ * File.ftype(file)
433
+ *
434
+ * The File.ftype method was modified so that 'door' is returned if the
435
+ * +file+ is a door file.
436
+ */
437
+ static VALUE solaris_file_ftype(VALUE klass, VALUE v_file){
438
+ VALUE v_stat = rb_funcall(rb_cStat, rb_intern("new"), 1, v_file);
439
+ return solaris_stat_ftype(v_stat);
440
+ }
441
+
391
442
  /*
392
443
  * Adds ACL support for the File class on Solaris
393
444
  */
@@ -405,19 +456,26 @@ void Init_file(){
405
456
  rb_define_singleton_method(rb_cFile, "trivial?", acl_is_trivial, 1);
406
457
  rb_define_singleton_method(rb_cFile, "realpath", solaris_realpath, 1);
407
458
  rb_define_singleton_method(rb_cFile, "resolvepath", solaris_resolvepath, 1);
459
+ rb_define_singleton_method(rb_cFile, "door?", solaris_file_is_door, 1);
460
+ rb_define_singleton_method(rb_cFile, "ftype", solaris_file_ftype, 1);
461
+
462
+ /* File Instance Methods */
463
+ rb_define_method(rb_cFile, "acl_count", acl_icount, 0);
464
+ rb_define_method(rb_cFile, "acl_read", acl_iread, 0);
465
+ rb_define_method(rb_cFile, "acl_read_text", acl_iread_text, 0);
466
+ rb_define_method(rb_cFile, "acl_write_text", acl_iwrite_text, 1);
467
+ rb_define_method(rb_cFile, "trivial?", acl_itrivial, 0);
408
468
 
409
- /* Instance Methods */
410
- rb_define_method(rb_cFile,"acl_count", acl_icount, 0);
411
- rb_define_method(rb_cFile,"acl_read", acl_iread, 0);
412
- rb_define_method(rb_cFile,"acl_read_text", acl_iread_text, 0);
413
- rb_define_method(rb_cFile,"acl_write_text", acl_iwrite_text, 1);
414
- rb_define_method(rb_cFile,"trivial?", acl_itrivial, 0);
469
+ /* File::Stat Instance Methods */
470
+ rb_define_alias(rb_cStat, "old_ftype", "ftype");
471
+ rb_define_method(rb_cStat, "door?", solaris_stat_is_door, 0);
472
+ rb_define_method(rb_cStat, "ftype", solaris_stat_ftype, 0);
415
473
 
416
474
  /* Structs */
417
475
  sACLStruct = rb_struct_define("ACLStruct",
418
476
  "acl_type", "acl_id", "acl_perm", NULL
419
477
  );
420
478
 
421
- /* 0.3.2: The version of this library, returned as a String */
479
+ /* 0.3.3: The version of this library, returned as a String */
422
480
  rb_define_const(rb_cFile, "SOLARIS_VERSION", rb_str_new2(SOLARIS_VERSION));
423
481
  }
data/ext/solaris/sfile.h CHANGED
@@ -1,4 +1,4 @@
1
- #define SOLARIS_VERSION "0.3.2"
1
+ #define SOLARIS_VERSION "0.3.3"
2
2
  #define MAX_STRING 512
3
3
 
4
4
  VALUE cSolarisFileError;
@@ -13,6 +13,8 @@ class TC_Solaris_File < Test::Unit::TestCase
13
13
  @dir = Dir.pwd
14
14
  @file = "foo.txt" # trivial
15
15
  @file2 = "bar.txt" # non-trivial
16
+ @door = "/var/run/syslog_door"
17
+ @stat = File::Stat.new(@door)
16
18
 
17
19
  @acl_text = "user::rw-,user:nobody:r--,"
18
20
  @acl_text << "group::r--,group:sys:r--,mask:r--,other:r--"
@@ -27,7 +29,7 @@ class TC_Solaris_File < Test::Unit::TestCase
27
29
  end
28
30
 
29
31
  def test_version
30
- assert_equal("0.3.2", File::SOLARIS_VERSION)
32
+ assert_equal('0.3.3', File::SOLARIS_VERSION)
31
33
  end
32
34
 
33
35
  # CLASS METHODS
@@ -95,6 +97,20 @@ class TC_Solaris_File < Test::Unit::TestCase
95
97
  assert_raises(Errno::ENOENT){ File.resolvepath("bogus") }
96
98
  end
97
99
 
100
+ def test_class_is_door
101
+ assert_respond_to(File, :door?)
102
+ assert_equal(true, File.door?(@door))
103
+ assert_equal(false, File.door?(Dir.pwd))
104
+ assert_raises(Errno::ENOENT){ File.door?("bogus") }
105
+ end
106
+
107
+ def test_class_ftype
108
+ assert_respond_to(File, :ftype)
109
+ assert_equal('door', File.ftype(@door))
110
+ assert_equal('directory', File.ftype(Dir.pwd))
111
+ assert_raises(Errno::ENOENT){ File.ftype("bogus") }
112
+ end
113
+
98
114
  # INSTANCE METHODS
99
115
 
100
116
  def test_instance_acl
@@ -132,8 +148,18 @@ class TC_Solaris_File < Test::Unit::TestCase
132
148
  assert_respond_to(@fh,:acl_count)
133
149
  assert_nothing_raised{ @fh.acl_count }
134
150
  assert_kind_of(Fixnum,@fh.acl_count)
135
- assert_equal(0,@fh.acl_count)
136
- assert_equal(6,@fh2.acl_count)
151
+ assert_equal(0, @fh.acl_count)
152
+ assert_equal(6, @fh2.acl_count)
153
+ end
154
+
155
+ def test_stat_door
156
+ assert_respond_to(@stat, :door?)
157
+ assert_equal(true, @stat.door?)
158
+ end
159
+
160
+ def test_stat_ftype
161
+ assert_respond_to(@stat, :ftype)
162
+ assert_equal('door', @stat.ftype)
137
163
  end
138
164
 
139
165
  def teardown
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: solaris-file
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.3.2
7
- date: 2007-07-24 00:00:00 -06:00
6
+ version: 0.3.3
7
+ date: 2007-08-20 00:00:00 -06:00
8
8
  summary: ACL and other methods for the File class on Solaris
9
9
  require_paths:
10
10
  - lib