Class: Net::SMB::Stat

Inherits:
Object
  • Object
show all
Defined in:
ext/net_smb/smbstat.c

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Object



49
50
51
52
53
54
55
56
57
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'ext/net_smb/smbstat.c', line 49

static VALUE rb_smbstat_initialize(int argc, VALUE *argv, VALUE self)
{
  RB_SMBSTAT_DATA_FROM_OBJ(self, data);
  VALUE smb_or_file_obj;
  VALUE url_obj;

  rb_scan_args(argc, argv, "11", &smb_or_file_obj, &url_obj);

  if (rb_obj_is_kind_of(smb_or_file_obj, rb_cSMB)) {
    RB_SMB_DATA_FROM_OBJ(smb_or_file_obj, smb_data);

    if (rb_obj_is_kind_of(url_obj, rb_cString)) {
      /* OK */
    }
    else if (rb_respond_to(url_obj, id_to_s)) {
      url_obj = rb_funcall(url_obj, id_to_s, 0);
    }
    else {
      rb_raise(rb_eTypeError, "String was expected");
    }

    const char *url = StringValueCStr(url_obj);
    smbc_stat_fn fn = smbc_getFunctionStat(smb_data->smbcctx);
    if ((*fn)(smb_data->smbcctx, url, &data->stat)) {
      rb_sys_fail_str(url_obj);
    }
  }
  else if (rb_obj_is_kind_of(smb_or_file_obj, rb_cSMBFile)) {
    RB_SMBFILE_DATA_FROM_OBJ(smb_or_file_obj, smbfile_data);
    smbc_fstat_fn fn = smbc_getFunctionFstat(smbfile_data->smbcctx);

    if ((*fn)(smbfile_data->smbcctx, smbfile_data->smbcfile, &data->stat)) {
      rb_sys_fail(smbfile_data->url);
    }
  }
  else if (rb_obj_is_kind_of(smb_or_file_obj, rb_cSMBDir)) {
    RB_SMBFILE_DATA_FROM_OBJ(smb_or_file_obj, smbfile_data);
#if 0
    /*
     * SMBC_fstatdir_ctx() does nothing. See source/libsmb/libsmb_dir.c in
     * Samba source tree.
     */
    smbc_fstatdir_fn fn = smbc_getFunctionFstatdir(smbfile_data->smbcctx);

    if ((*fn)(smbfile_data->smbcctx, smbfile_data->smbcfile, &data->stat)) {
      rb_sys_fail(smbfile_data->url);
    }
#else
    smbc_stat_fn fn = smbc_getFunctionStat(smbfile_data->smbcctx);
    if ((*fn)(smbfile_data->smbcctx, smbfile_data->url, &data->stat)) {
      rb_sys_fail(smbfile_data->url);
    }
#endif
  }
  else {
    rb_raise(rb_eTypeError, "Net::SMB, Net::SMB::Dir or Net::SMB::File was expected");
  }

  return self;
}

Instance Method Details

#atimeObject



159
160
161
162
163
164
# File 'ext/net_smb/smbstat.c', line 159

static VALUE rb_smbstat_atime(VALUE self)
{
  RB_SMBSTAT_DATA_FROM_OBJ(self, data);

  return rb_time_new(data->stat.st_atime, 0);
}

#ctimeObject



173
174
175
176
177
178
# File 'ext/net_smb/smbstat.c', line 173

static VALUE rb_smbstat_ctime(VALUE self)
{
  RB_SMBSTAT_DATA_FROM_OBJ(self, data);

  return rb_time_new(data->stat.st_ctime, 0);
}

#devObject



110
111
112
113
114
115
# File 'ext/net_smb/smbstat.c', line 110

static VALUE rb_smbstat_dev(VALUE self)
{
  RB_SMBSTAT_DATA_FROM_OBJ(self, data);

  return DEVT2NUM(data->stat.st_dev);
}

#gidObject



145
146
147
148
149
150
# File 'ext/net_smb/smbstat.c', line 145

static VALUE rb_smbstat_gid(VALUE self)
{
  RB_SMBSTAT_DATA_FROM_OBJ(self, data);

  return GIDT2NUM(data->stat.st_gid);
}

#inoObject



117
118
119
120
121
122
# File 'ext/net_smb/smbstat.c', line 117

static VALUE rb_smbstat_ino(VALUE self)
{
  RB_SMBSTAT_DATA_FROM_OBJ(self, data);

  return ULL2NUM(data->stat.st_ino);
}

#modeObject



124
125
126
127
128
129
# File 'ext/net_smb/smbstat.c', line 124

static VALUE rb_smbstat_mode(VALUE self)
{
  RB_SMBSTAT_DATA_FROM_OBJ(self, data);

  return UINT2NUM(data->stat.st_mode);
}

#mtimeObject



166
167
168
169
170
171
# File 'ext/net_smb/smbstat.c', line 166

static VALUE rb_smbstat_mtime(VALUE self)
{
  RB_SMBSTAT_DATA_FROM_OBJ(self, data);

  return rb_time_new(data->stat.st_mtime, 0);
}


131
132
133
134
135
136
# File 'ext/net_smb/smbstat.c', line 131

static VALUE rb_smbstat_nlink(VALUE self)
{
  RB_SMBSTAT_DATA_FROM_OBJ(self, data);

  return ULL2NUM(data->stat.st_nlink);
}

#sizeObject



152
153
154
155
156
157
# File 'ext/net_smb/smbstat.c', line 152

static VALUE rb_smbstat_size(VALUE self)
{
  RB_SMBSTAT_DATA_FROM_OBJ(self, data);

  return OFFT2NUM(data->stat.st_size);
}

#uidObject



138
139
140
141
142
143
# File 'ext/net_smb/smbstat.c', line 138

static VALUE rb_smbstat_uid(VALUE self)
{
  RB_SMBSTAT_DATA_FROM_OBJ(self, data);

  return UIDT2NUM(data->stat.st_uid);
}