Class: Qfs::BaseClient
- Inherits:
-
Object
- Object
- Qfs::BaseClient
- Defined in:
- ext/qfs/qfs.c
Direct Known Subclasses
Instance Method Summary collapse
- #cd(path) ⇒ Object
- #chmod(path, mode) ⇒ Object
- #exists(path) ⇒ Object
-
#initialize(host, port) ⇒ Object
constructor
qfs_connect wrapper.
- #isdirectory(path) ⇒ Object
- #isfile(path) ⇒ Object
- #mkdir(path, mode) ⇒ Object
- #mkdir_p(path, mode) ⇒ Object
- #open(*args) ⇒ Object
- #readdir(path) ⇒ Object
-
#release ⇒ Object
qfs_release wrapper.
- #remove(path) ⇒ Object
- #rename(old, new) ⇒ Object
- #rmdir(path) ⇒ Object
- #rmdirs(path) ⇒ Object
- #setwd(path) ⇒ Object
-
#stat(path) ⇒ Object
QFS C api.
Constructor Details
#initialize(host, port) ⇒ Object
qfs_connect wrapper. Raises Qfs::Error on error
47 48 49 50 51 52 53 54 55 56 57 |
# File 'ext/qfs/qfs.c', line 47 static VALUE qfs_client_connect(VALUE self, VALUE host, VALUE port) { struct qfs_client *qfs; Check_Type(host, T_STRING); Check_Type(port, T_FIXNUM); Data_Get_Struct(self, struct qfs_client, qfs); qfs->qfs = qfs_connect(StringValueCStr(host), FIX2INT(port)); if (!qfs->qfs) { rb_raise(eQfsError, "Connection failed"); } return Qnil; } |
Instance Method Details
#cd(path) ⇒ Object
298 299 300 |
# File 'ext/qfs/qfs.c', line 298 static VALUE qfs_client_cd(VALUE self, VALUE path) { return qfs_client_cd_base(self, path, qfs_cd); } |
#chmod(path, mode) ⇒ Object
258 259 260 |
# File 'ext/qfs/qfs.c', line 258 static VALUE qfs_client_chmod(VALUE self, VALUE path, VALUE mode) { return qfs_client_chmod_base(self, path, mode, qfs_chmod); } |
#exists(path) ⇒ Object
141 142 143 |
# File 'ext/qfs/qfs.c', line 141 static VALUE qfs_client_exists(VALUE self, VALUE path) { return qfs_client_path_checking(self, path, qfs_exists); } |
#isdirectory(path) ⇒ Object
149 150 151 |
# File 'ext/qfs/qfs.c', line 149 static VALUE qfs_client_isdirectory(VALUE self, VALUE path) { return qfs_client_path_checking(self, path, qfs_isdirectory); } |
#isfile(path) ⇒ Object
145 146 147 |
# File 'ext/qfs/qfs.c', line 145 static VALUE qfs_client_isfile(VALUE self, VALUE path) { return qfs_client_path_checking(self, path, qfs_isfile); } |
#mkdir(path, mode) ⇒ Object
195 196 197 |
# File 'ext/qfs/qfs.c', line 195 static VALUE qfs_client_mkdir(VALUE self, VALUE path, VALUE mode) { return qfs_client_mkdir_base(self, path, mode, qfs_mkdir); } |
#mkdir_p(path, mode) ⇒ Object
199 200 201 |
# File 'ext/qfs/qfs.c', line 199 static VALUE qfs_client_mkdir_p(VALUE self, VALUE path, VALUE mode) { return qfs_client_mkdir_base(self, path, mode, qfs_mkdirs); } |
#open(*args) ⇒ Object
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 109 |
# File 'ext/qfs/qfs.c', line 72 static VALUE qfs_client_open(int argc, VALUE *argv, VALUE self) { struct qfs_client *client; VALUE path; VALUE oflag; VALUE mode; VALUE params; rb_scan_args(argc, argv, "13", &path, &oflag, &mode, ¶ms); Check_Type(path, T_STRING); int ioflag; uint16_t imode; char *sparams; if (oflag == Qnil) { ioflag = O_RDONLY; } else { Check_Type(oflag, T_FIXNUM); ioflag = FIX2INT(oflag); } if (mode == Qnil) { imode = 0666; } else { Check_Type(mode, T_FIXNUM); imode = (uint16_t)FIX2INT(mode); } if (params == Qnil) { sparams = NULL; } else { Check_Type(params, T_STRING); sparams = StringValueCStr(params); } Data_Get_Struct(self, struct qfs_client, client); int fd = qfs_open_file(client->qfs, StringValueCStr(path), ioflag, imode, sparams); QFS_CHECK_ERR(fd); struct qfs_file *file = ALLOC(struct qfs_file); file->client = self; file->fd = fd; return Data_Wrap_Struct(cQfsFile, qfs_file_mark, qfs_file_deallocate, file); } |
#readdir(path) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'ext/qfs/qfs.c', line 111 static VALUE qfs_client_readdir(VALUE self, VALUE path) { int left; int count = 0; Check_Type(path, T_STRING); char *p = StringValueCStr(path); struct qfs_iter *iter = NULL; struct qfs_attr attr; struct qfs_client *client; Data_Get_Struct(self, struct qfs_client, client); while ((left = qfs_readdir(client->qfs, p, &iter, &attr)) > 0) { struct qfs_attr *tmp_attr = ALLOC(struct qfs_attr); memcpy(tmp_attr, &attr, sizeof(attr)); count += 1; rb_yield(Data_Wrap_Struct(cQfsAttr, NULL, free, tmp_attr)); } qfs_iter_free(&iter); QFS_CHECK_ERR(left); return INT2FIX(count); } |
#release ⇒ Object
qfs_release wrapper
60 61 62 63 64 65 66 67 68 69 70 |
# File 'ext/qfs/qfs.c', line 60 static VALUE qfs_client_release(VALUE self) { TRACE; struct qfs_client *qfs; Data_Get_Struct(self, struct qfs_client, qfs); if (qfs->qfs) { qfs_release(qfs->qfs); } qfs->qfs = NULL; TRACE_R; return Qnil; } |
#remove(path) ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'ext/qfs/qfs.c', line 153 static VALUE qfs_client_remove(VALUE self, VALUE path) { Check_Type(path, T_STRING); char *p = StringValueCStr(path); // Check that the file is regular VALUE isfile = qfs_client_isfile(self, path); if (!RTEST(isfile)) { rb_raise(eQfsError, "Not a regular file - %s", p); } struct qfs_client *client; Data_Get_Struct(self, struct qfs_client, client); int res = qfs_remove(client->qfs, p); // Raise an exception if the file didn't exist if (res == -2) { rb_raise(rb_eErrnoENOENT, "No such file or directory - %s", p); } QFS_CHECK_ERR(res); return INT2NUM(1); } |
#rename(old, new) ⇒ Object
266 267 268 269 270 271 272 273 274 275 276 |
# File 'ext/qfs/qfs.c', line 266 static VALUE qfs_client_rename(VALUE self, VALUE old, VALUE new) { Check_Type(old, T_STRING); Check_Type(new, T_STRING); struct qfs_client *client; Data_Get_Struct(self, struct qfs_client, client); char *old_s = StringValueCStr(old); char *new_s = StringValueCStr(new); int res = qfs_rename(client->qfs, old_s, new_s); QFS_CHECK_ERR(res); return RES2BOOL(res); } |
#rmdir(path) ⇒ Object
221 222 223 |
# File 'ext/qfs/qfs.c', line 221 static VALUE qfs_client_rmdir(VALUE self, VALUE path) { return qfs_client_rmdir_base(self, path, qfs_rmdir); } |
#rmdirs(path) ⇒ Object
225 226 227 |
# File 'ext/qfs/qfs.c', line 225 static VALUE qfs_client_rmdirs(VALUE self, VALUE path) { return qfs_client_rmdir_base(self, path, qfs_rmdirs); } |
#setwd(path) ⇒ Object
302 303 304 |
# File 'ext/qfs/qfs.c', line 302 static VALUE qfs_client_setwd(VALUE self, VALUE path) { return qfs_client_cd_base(self, path, qfs_setwd); } |
#stat(path) ⇒ Object
QFS C api.
234 235 236 237 238 239 240 241 242 243 |
# File 'ext/qfs/qfs.c', line 234 static VALUE qfs_client_stat(VALUE self, VALUE path) { Check_Type(path, T_STRING); char *p = StringValueCStr(path); struct qfs_client *client; Data_Get_Struct(self, struct qfs_client, client); struct qfs_attr *attr = ALLOC(struct qfs_attr); int res = qfs_stat(client->qfs, p, attr); QFS_CHECK_ERR(res); return Data_Wrap_Struct(cQfsAttr, NULL, free, attr); } |