Class: Net::SMB::Dir
- Inherits:
-
Object
- Object
- Net::SMB::Dir
- Includes:
- Enumerable
- Defined in:
- ext/net_smb/smbdir.c
Instance Method Summary collapse
- #close ⇒ Object
- #closed? ⇒ Boolean
- #each ⇒ Object
- #initialize(smb_obj, url_obj) ⇒ Object constructor
- #read ⇒ Object
- #rewind ⇒ Object
- #seek(offset_num) ⇒ Object
- #smb ⇒ Object
- #stat ⇒ Object
- #tell ⇒ Object (also: #pos)
- #url ⇒ Object
- #xattr(name_obj) ⇒ Object
Constructor Details
#initialize(smb_obj, url_obj) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'ext/net_smb/smbdir.c', line 87
static VALUE rb_smbdir_initialize(VALUE self, VALUE smb_obj, VALUE url_obj)
{
RB_SMBFILE_DATA_FROM_OBJ(self, data);
RB_SMB_DATA_FROM_OBJ(smb_obj, smb_data);
smbc_opendir_fn fn;
const char *url = StringValueCStr(url_obj);
fn = smbc_getFunctionOpendir(smb_data->smbcctx);
data->smbcfile = (*fn)(smb_data->smbcctx, url);
if (data->smbcfile == NULL) {
rb_sys_fail_str(url_obj);
}
/* FIXME: Take encoding from argument */
/* FIXME: Read unix charset (?) from smb.conf for default encoding */
data->enc = rb_enc_find("UTF-8");
data->smb_obj = smb_obj;
data->smb_data = smb_data;
data->smbcctx = smb_data->smbcctx;
data->url = ruby_strdup(url);
RB_SMB_DEBUG("smbcctx=%p smbcfile=%p\n", data->smbcctx, data->smbcfile);
if (rb_block_given_p()) {
return rb_ensure(rb_yield, self, rb_smbdir_close, self);
}
return self;
}
|
Instance Method Details
#close ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 |
# File 'ext/net_smb/smbdir.c', line 132
static VALUE rb_smbdir_close(VALUE self)
{
RB_SMBFILE_DATA_FROM_OBJ(self, data);
RB_SMBFILE_DATA_CLOSED(data);
RB_SMB_DEBUG("data=%p smbcctx=%p smbcfile=%p\n", data, data->smbcctx, data->smbcfile);
rb_smbdir_close_and_deref_by_data(data);
return self;
}
|
#closed? ⇒ Boolean
147 148 149 150 151 152 |
# File 'ext/net_smb/smbdir.c', line 147
static VALUE rb_smbdir_closed_p(VALUE self)
{
RB_SMBFILE_DATA_FROM_OBJ(self, data);
return rb_smbdir_closed_p_by_data(data);
}
|
#each ⇒ Object
241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'ext/net_smb/smbdir.c', line 241
static VALUE rb_smbdir_each(VALUE self)
{
VALUE name;
rb_smbdir_rewind(self);
RETURN_ENUMERATOR(self, 0, 0);
while (!NIL_P(name = rb_smbdir_read(self))) {
rb_yield(name);
}
return self;
}
|
#read ⇒ Object
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'ext/net_smb/smbdir.c', line 208
static VALUE rb_smbdir_read(VALUE self)
{
RB_SMBFILE_DATA_FROM_OBJ(self, data);
RB_SMBFILE_DATA_CLOSED(data);
smbc_readdir_fn fn;
struct smbc_dirent *smbcdent;
fn = smbc_getFunctionReaddir(data->smbcctx);
errno = 0;
smbcdent = (*fn)(data->smbcctx, data->smbcfile);
if (smbcdent == NULL) {
if (errno) {
rb_sys_fail(data->url);
}
return Qnil;
}
VALUE args[4];
args[0] = rb_external_str_new_with_enc(smbcdent->name,
strlen(smbcdent->name), data->enc);
args[1] = INT2NUM(smbcdent->smbc_type);
args[2] = rb_str_new2(data->url);
rb_str_cat2(args[2], "/"); /* FIXME: Unless if the last char is not "/" */
rb_str_cat2(args[2], smbcdent->name); /* FIXME: Must be URL encoding */
args[3] = rb_str_new(smbcdent->comment, smbcdent->commentlen);
VALUE entry_obj = rb_class_new_instance(4, args, rb_cSMBDirEntry);
return entry_obj;
}
|
#rewind ⇒ Object
203 204 205 206 |
# File 'ext/net_smb/smbdir.c', line 203
static VALUE rb_smbdir_rewind(VALUE self)
{
return rb_smbdir_seek(self, LONG2NUM(0));
}
|
#seek(offset_num) ⇒ Object
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'ext/net_smb/smbdir.c', line 186
static VALUE rb_smbdir_seek(VALUE self, VALUE offset_num)
{
RB_SMBFILE_DATA_FROM_OBJ(self, data);
RB_SMBFILE_DATA_CLOSED(data);
smbc_lseekdir_fn fn;
off_t offset = (off_t)NUM2LONG(offset_num);
fn = smbc_getFunctionLseekdir(data->smbcctx);
errno = 0;
if ((*fn)(data->smbcctx, data->smbcfile, offset) == -1) {
rb_sys_fail(data->url);
}
return self;
}
|
#smb ⇒ Object
118 119 120 121 122 123 |
# File 'ext/net_smb/smbdir.c', line 118
static VALUE rb_smbdir_smb(VALUE self)
{
RB_SMBFILE_DATA_FROM_OBJ(self, data);
return data->smb_obj;
}
|
#stat ⇒ Object
154 155 156 157 |
# File 'ext/net_smb/smbdir.c', line 154
static VALUE rb_smbdir_stat(VALUE self)
{
return rb_class_new_instance(1, &self, rb_cSMBStat);
}
|
#tell ⇒ Object Also known as: pos
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'ext/net_smb/smbdir.c', line 166
static VALUE rb_smbdir_tell(VALUE self)
{
RB_SMBFILE_DATA_FROM_OBJ(self, data);
RB_SMBFILE_DATA_CLOSED(data);
smbc_telldir_fn fn;
off_t offset;
fn = smbc_getFunctionTelldir(data->smbcctx);
errno = 0;
offset = (*fn)(data->smbcctx, data->smbcfile);
if (offset == (off_t)-1) {
if (errno != 0) {
rb_sys_fail(data->url);
}
}
return LONG2NUM(offset);
}
|
#url ⇒ Object
125 126 127 128 129 130 |
# File 'ext/net_smb/smbdir.c', line 125
static VALUE rb_smbdir_url(VALUE self)
{
RB_SMBFILE_DATA_FROM_OBJ(self, data);
return rb_str_new2(data->url);
}
|
#xattr(name_obj) ⇒ Object
159 160 161 162 163 164 |
# File 'ext/net_smb/smbdir.c', line 159
static VALUE rb_smbdir_xattr_get(VALUE self, VALUE name_obj)
{
RB_SMBFILE_DATA_FROM_OBJ(self, data);
return rb_smb_xattr_get(data->smb_obj, rb_str_new2(data->url), name_obj);
}
|