Class: File

Inherits:
Object
  • Object
show all
Defined in:
(unknown)

Constant Summary collapse

SOLARIS_VERSION =

The version of the solaris-file library

0.3.7

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.acl_count(file_name) ⇒ Object

Returns the number of ACL entries for file_name. Returns 0 if file_name is a trivial file.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'ext/solaris/sfile.c', line 17

static VALUE acl_count(VALUE klass, VALUE v_path){
  int num_acls = 0;
  char pathp[PATH_MAX];

  SafeStringValue(v_path);

  if(strlcpy(pathp, StringValuePtr(v_path), PATH_MAX) >= PATH_MAX)
    rb_raise(rb_eArgError, "path length exceeds limit of: %i", PATH_MAX);

  if((num_acls = acl(pathp, GETACLCNT, 0, NULL)) == -1)
    rb_sys_fail(0);

  if(num_acls == MIN_ACL_ENTRIES)
    num_acls = 0;

  return INT2FIX(num_acls);
}

.acl_read(file_name) ⇒ Object

Returns an array of ACLStruct’s that contain three members each:

  • acl_type (String)

  • acl_id (Integer)

  • acl_perm (Integer)

Returns nil if file_name is a trivial file.



67
68
69
70
71
72
73
74
75
76
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
105
# File 'ext/solaris/sfile.c', line 67

static VALUE acl_read(VALUE klass, VALUE v_path){
  int num_acls = 0;
  char pathp[PATH_MAX];
  VALUE v_array = Qnil;
  int i;

  SafeStringValue(v_path);

  if(strlcpy(pathp, StringValuePtr(v_path), PATH_MAX) >= PATH_MAX)
    rb_raise(rb_eArgError, "path length exceeds limit of: %i", PATH_MAX);

  if((num_acls = acl(pathp, GETACLCNT, 0, NULL)) == -1)
    rb_sys_fail(0);

  if(num_acls != MIN_ACL_ENTRIES){
    aclent_t* acl_buf;
    v_array = rb_ary_new();

    if((acl_buf = malloc(sizeof(aclent_t) * num_acls) ) == NULL)
      rb_sys_fail(0);

    if(acl(pathp, GETACL, num_acls, acl_buf) != num_acls)
      rb_sys_fail(0);

    for(i = 0; i < num_acls; i++){
      rb_ary_push(v_array,
        rb_struct_new(sACLStruct,
          acl_type_string(acl_buf[i].a_type),
          INT2FIX(acl_buf[i].a_id),
          INT2FIX(acl_buf[i].a_perm)
        )
       );
    }

    free(acl_buf);
  }

  return v_array;
}

.acl_read_text(file_name) ⇒ Object

Returns a textual representation of the ACL for file_name. If file_name is a trivial file, nil is returned.



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'ext/solaris/sfile.c', line 161

static VALUE acl_read_text(VALUE klass, VALUE v_path){
  aclent_t* acl_buf;
  int num_acls = 0;
  char* acl_text;
  char pathp[PATH_MAX];
  VALUE v_text = Qnil;

  SafeStringValue(v_path);

  if(strlcpy(pathp, StringValuePtr(v_path), PATH_MAX) >= PATH_MAX)
    rb_raise(rb_eArgError, "path length exceeds limit of: %i", PATH_MAX);

  if((num_acls = acl(pathp, GETACLCNT, 0, NULL)) == -1)
    rb_sys_fail(0);

  if(num_acls != MIN_ACL_ENTRIES){
    if((acl_buf = malloc(sizeof(aclent_t) * num_acls) ) == NULL)
      rb_sys_fail(0);

    if(acl(pathp, GETACL, num_acls, acl_buf) != num_acls)
      rb_sys_fail(0);

    acl_text = acltotext(acl_buf, num_acls);
      
    free(acl_buf);
    v_text = rb_str_new2(acl_text);
  }

  return v_text;
}

.acl_write_text(file_name, acl_text) ⇒ Object

Sets the ACL for file_name using acl_text. The acl_text argument is a human readable ACL text String.

If acl_text is invalid then a Solaris::File::Error is raised, and in most cases the offending entry number will be identified.



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'ext/solaris/sfile.c', line 202

static VALUE acl_write_text(VALUE klass, VALUE v_path, VALUE v_text){
  aclent_t* acl_buf;
  int num_acls, which, rv;
  char pathp[PATH_MAX];
  char* acl_text = StringValuePtr(v_text);

  SafeStringValue(v_path);
  SafeStringValue(v_text);

  if(strlcpy(pathp, StringValuePtr(v_path), PATH_MAX) >= PATH_MAX)
    rb_raise(rb_eArgError, "path length exceeds limit of: %i", PATH_MAX);

  if((acl_buf = aclfromtext(acl_text, &num_acls)) == NULL)
    rb_raise(cSolarisFileError, "invalid ACL text");

  rv = aclcheck(acl_buf, num_acls, &which);
  do_acl_check(rv, which);

  if(acl(pathp, SETACL, num_acls, acl_buf) == -1){
    free(acl_text);
    rb_sys_fail(0);
  }

  free(acl_text);
  free(acl_buf);

  return klass;
}

.door?(file) ⇒ Boolean

Returns true if file is a door file, false otherwise.

Returns:

  • (Boolean)


432
433
434
435
# File 'ext/solaris/sfile.c', line 432

static VALUE solaris_file_is_door(VALUE klass, VALUE v_file){
  VALUE v_stat = rb_funcall(rb_cStat, rb_intern("new"), 1, v_file);
  return solaris_stat_is_door(v_stat);
}

.ftype(file) ⇒ Object

The File.ftype method was modified so that ‘door’ is returned if the file is a door file.



444
445
446
447
# File 'ext/solaris/sfile.c', line 444

static VALUE solaris_file_ftype(VALUE klass, VALUE v_file){
  VALUE v_stat = rb_funcall(rb_cStat, rb_intern("new"), 1, v_file);
  return solaris_stat_ftype(v_stat);
}

.realpath(path) ⇒ Object

Resolves all symbolic links in path. Resolves to an absolute pathname where possible.

The difference between this method and File.resolvepath is that this method will resolve to an absolute pathname where possible.



262
263
264
265
266
267
268
269
270
271
# File 'ext/solaris/sfile.c', line 262

static VALUE solaris_realpath(VALUE klass, VALUE v_path){
  char pathp[PATH_MAX];

  SafeStringValue(v_path);

  if(realpath(StringValuePtr(v_path), pathp) == NULL)
    rb_sys_fail(0);

  return rb_str_new2(pathp);
}

.resolvepath(path) ⇒ Object

Resolves all symbolic links in 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 “/”.



240
241
242
243
244
245
246
247
248
249
250
# File 'ext/solaris/sfile.c', line 240

static VALUE solaris_resolvepath(VALUE klass, VALUE v_path){
  char pathp[PATH_MAX];

  SafeStringValue(v_path);
  memset(pathp, 0, PATH_MAX);

  if(resolvepath(StringValuePtr(v_path), pathp, PATH_MAX) == -1)
    rb_sys_fail(0);

  return rb_str_new2(pathp);
}

.trivial?(file_name) ⇒ Boolean

Returns true if file_name is a trivial file, i.e. has no additional ACL entries. Otherwise, it returns false.

Returns:

  • (Boolean)


352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
# File 'ext/solaris/sfile.c', line 352

static VALUE acl_is_trivial(VALUE klass, VALUE v_path){
  char pathp[PATH_MAX];
  int num_acls = 0;
  VALUE v_bool = Qfalse;

  SafeStringValue(v_path);

  if(strlcpy(pathp, StringValuePtr(v_path), PATH_MAX) >= PATH_MAX)
    rb_raise(rb_eArgError, "path length exceeds limit of: %i", PATH_MAX);

  if((num_acls = acl(pathp, GETACLCNT, 0, NULL)) == -1)
    rb_sys_fail(0);

  if(num_acls == MIN_ACL_ENTRIES)
    v_bool = Qtrue;

  return v_bool;
}

Instance Method Details

#acl_countObject

Returns the number of ACL entries for the current handle. Returns 0 if the file is a trivial file.



42
43
44
45
46
47
48
49
50
51
52
53
# File 'ext/solaris/sfile.c', line 42

static VALUE acl_icount(VALUE self){
  int num_acls = 0;
  int fd = FIX2INT(rb_funcall(self, rb_intern("fileno"), 0, 0));

  if((num_acls = facl(fd, GETACLCNT, 0, NULL)) == -1)
    rb_sys_fail(0);

  if(num_acls == MIN_ACL_ENTRIES)
    num_acls = 0;

  return INT2FIX(num_acls);
}

#acl_readObject

Returns an array of ACLStruct’s that contain three members each:

  • acl_type (String)

  • acl_id (Integer)

  • acl_perm (Integer)

Returns nil if the file is a trivial file.



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'ext/solaris/sfile.c', line 119

static VALUE acl_iread(VALUE self){
  int i;
  int num_acls = 0;
  int fd = FIX2INT(rb_funcall(self, rb_intern("fileno"), 0, 0));
  VALUE v_array = Qnil;

  if((num_acls = facl(fd, GETACLCNT, 0, NULL)) == -1)
    rb_sys_fail(0);

  if(num_acls != MIN_ACL_ENTRIES){
    aclent_t* acl_buf;
    v_array = rb_ary_new();

    if((acl_buf = malloc(sizeof(aclent_t) * num_acls) ) == NULL)
      rb_sys_fail(0);

    if(facl(fd, GETACL, num_acls, acl_buf) != num_acls)
      rb_sys_fail(0);

    for(i = 0; i < num_acls; i++){
      rb_ary_push(v_array,
        rb_struct_new(sACLStruct,
          acl_type_string(acl_buf[i].a_type),
          INT2FIX(acl_buf[i].a_id),
          INT2FIX(acl_buf[i].a_perm)
        )
      );
    }

    free(acl_buf);
  }

  return v_array;
}

#acl_read_textObject

Returns a textual representation of the ACL for the current handle. If the file is a trivial file, nil is returned.



318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
# File 'ext/solaris/sfile.c', line 318

static VALUE acl_iread_text(VALUE self){
  char* acl_text;
  int num_acls = 0;
  int fd = FIX2INT(rb_funcall(self,rb_intern("fileno"),0,0));
  VALUE v_text = Qnil;

  if((num_acls = facl(fd,GETACLCNT,0,NULL)) == -1)
    rb_sys_fail(0);

  if(num_acls != MIN_ACL_ENTRIES){
    aclent_t* acl_buf;

    if((acl_buf = malloc(sizeof(aclent_t) * num_acls) ) == NULL)
      rb_sys_fail(0);

    if(facl(fd, GETACL, num_acls, acl_buf) != num_acls)
      rb_sys_fail(0);

    acl_text = acltotext(acl_buf,num_acls);
      
    free(acl_buf);
    v_text = rb_str_new2(acl_text); 
  }

  return v_text;
}

#acl_write_text(acl_text) ⇒ Object

Sets the ACL for the file using acl_text. The acl_text argument is a human readable ACL text String.

If acl_text is invalid then a File::Solaris::Error is raised, and in most cases the offending entry number will be identified.



285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'ext/solaris/sfile.c', line 285

static VALUE acl_iwrite_text(VALUE self, VALUE v_text){
  aclent_t* acl_buf;
  int num_acls, which, rv;
  char* acl_text = StringValuePtr(v_text);
  int fd = FIX2INT(rb_funcall(self, rb_intern("fileno"), 0, 0));

  SafeStringValue(v_text);

  if((acl_buf = aclfromtext(acl_text, &num_acls)) == NULL)
    rb_raise(cSolarisFileError, "invalid ACL text");

  rv = aclcheck(acl_buf, num_acls, &which);
  do_acl_check(rv, which);

  if(facl(fd, SETACL, num_acls, acl_buf) == -1){
    free(acl_text);
    rb_sys_fail(0);
  }

  free(acl_text);
  free(acl_buf);

  return self;
}

#trivial?Boolean

Returns true if the current file is a trivial file, i.e. has no additional ACL entries. Otherwise, it returns false.

Returns:

  • (Boolean)


378
379
380
381
382
383
384
385
386
387
388
389
390
# File 'ext/solaris/sfile.c', line 378

static VALUE acl_itrivial(VALUE self){
  int fd = FIX2INT(rb_funcall(self, rb_intern("fileno"), 0, 0));
  int num_acls = 0;
  VALUE v_bool = Qfalse;

  if((num_acls = facl(fd, GETACLCNT, 0, NULL)) == -1)
    rb_sys_fail(0);

  if(num_acls == MIN_ACL_ENTRIES)
    v_bool = Qtrue;

  return v_bool;
}