Class: File
- Inherits:
-
Object
- Object
- File
- Defined in:
- lib/extattr.rb
Overview
Add operation methods of extended file attribute to File.
File クラスに拡張属性を操作するメソッドを追加します。
感嘆符 (『!』) のついたメソッドは、シンボリックリンクに対する操作となります。
メソッドにキーワード引数として namespace: を与えることにより、拡張属性の名前空間を指定することが出来ます。
現在の実装においては EXTATTR_NAMESPACE_USER と EXTATTR_NAMESPACE_SYSTEM のみが利用可能です。
Constant Summary collapse
- EXTATTR_NAMESPACE_USER =
INT2NUM(EXTATTR_NAMESPACE_USER)
- EXTATTR_NAMESPACE_SYSTEM =
INT2NUM(EXTATTR_NAMESPACE_SYSTEM)
- EXTATTR_VERSION =
rb_str_freeze(rb_str_new_cstr("0.2"))
Class Method Summary collapse
- .extattr_delete(path, name, namespace: File::EXTATTR_NAMESPACE_USER) ⇒ nil
- .extattr_delete!(path, name, namespace: File::EXTATTR_NAMESPACE_USER) ⇒ nil
-
.extattr_each(path, *namespace) ⇒ Object
call-seq: extattr_each(path, namespace: File::EXTATTR_NAMESPACE_USER) -> Enumerator extattr_each(path, namespace: File::EXTATTR_NAMESPACE_USER) { |name, data| … } -> File extattr_each!(path, namespace: File::EXTATTR_NAMESPACE_USER) -> Enumerator extattr_each!(path, namespace: File::EXTATTR_NAMESPACE_USER) { |name, data| … } -> File.
- .extattr_each!(path, *namespace) ⇒ Object
- .extattr_get(path, name, namespace: File::EXTATTR_NAMESPACE_USER) ⇒ Object
- .extattr_get!(path, name, namespace: File::EXTATTR_NAMESPACE_USER) ⇒ Object
-
.extattr_list(argv[], file) ⇒ Object
ファイル名を指定すること以外は File#extattr_list と同じです。.
-
.extattr_list!(argv[], file) ⇒ Object
シンボリックリンクに対する操作という以外は、File.extattr_list と同じです。.
- .extattr_set(path, name, data, namespace: File::EXTATTR_NAMESPACE_USER) ⇒ nil
- .extattr_set!(path, name, data, namespace: File::EXTATTR_NAMESPACE_USER) ⇒ nil
- .extattr_size(path, name, namespace: File::EXTATTR_NAMESPACE_USER) ⇒ Object
- .extattr_size!(path, name, namespace: File::EXTATTR_NAMESPACE_USER) ⇒ Object
Instance Method Summary collapse
- #extattr_delete(name, namespace: File::EXTATTR_NAMESPACE_USER) ⇒ nil
- #extattr_each(*namespace) ⇒ Object
- #extattr_get(name, namespace: File::EXTATTR_NAMESPACE_USER) ⇒ Object
-
#extattr_list(argv[], file) ⇒ Object
開いているファイルの拡張属性名一覧を得ます。.
- #extattr_set(name, data, namespace: File::EXTATTR_NAMESPACE_USER) ⇒ nil
-
#extattr_size(name, namespace: File::EXTATTR_NAMESPACE_USER) ⇒ Object
拡張属性の大きさを取得します。.
Class Method Details
.extattr_delete(path, name, namespace: File::EXTATTR_NAMESPACE_USER) ⇒ nil
411 412 413 414 415 416 417 418 419 420 421 |
# File 'ext/extattr.c', line 411 static VALUE file_s_extattr_delete(int argc, VALUE argv[], VALUE file) { VALUE path, name, opts = Qnil; rb_scan_args(argc, argv, "2:", &path, &name, &opts); ext_check_path_security(path, name, Qnil); Check_Type(name, RUBY_T_STRING); return file_s_extattr_delete_main(StringValue(path), ext_get_namespace(opts), StringValue(name)); } |
.extattr_delete!(path, name, namespace: File::EXTATTR_NAMESPACE_USER) ⇒ nil
427 428 429 430 431 432 433 434 435 436 437 |
# File 'ext/extattr.c', line 427 static VALUE file_s_extattr_delete_link(int argc, VALUE argv[], VALUE file) { VALUE path, name, opts = Qnil; rb_scan_args(argc, argv, "2:", &path, &name, &opts); ext_check_path_security(path, name, Qnil); Check_Type(name, RUBY_T_STRING); return file_s_extattr_delete_link_main(StringValue(path), ext_get_namespace(opts), StringValue(name)); } |
.extattr_each(path, *namespace) ⇒ Object
call-seq:
extattr_each(path, namespace: File::EXTATTR_NAMESPACE_USER) -> Enumerator
extattr_each(path, namespace: File::EXTATTR_NAMESPACE_USER) { |name, data| ... } -> File
extattr_each!(path, namespace: File::EXTATTR_NAMESPACE_USER) -> Enumerator
extattr_each!(path, namespace: File::EXTATTR_NAMESPACE_USER) { |name, data| ... } -> File
31 32 33 34 35 36 37 38 |
# File 'lib/extattr.rb', line 31 def self.extattr_each(path, *namespace) return to_enum(:extattr_each, path, *namespace) unless block_given? extattr_list(path, *namespace) do |name| yield(name, extattr_get(path, name, *namespace)) end self end |
.extattr_each!(path, *namespace) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/extattr.rb', line 40 def self.extattr_each!(path, *namespace) return to_enum(:extattr_each!, path, *namespace) unless block_given? extattr_list!(path, *namespace) do |name| yield(name, extattr_get!(path, name, *namespace)) end self end |
.extattr_get(path, name, namespace: File::EXTATTR_NAMESPACE_USER) ⇒ Object
306 307 308 309 310 311 312 313 314 315 316 317 318 |
# File 'ext/extattr.c', line 306 static VALUE file_s_extattr_get(int argc, VALUE argv[], VALUE file) { VALUE path, name, opts = Qnil; rb_scan_args(argc, argv, "2:", &path, &name, &opts); ext_check_path_security(path, name, Qnil); Check_Type(name, RUBY_T_STRING); VALUE v = file_s_extattr_get_main(StringValue(path), ext_get_namespace(opts), StringValue(name)); OBJ_INFECT(v, path); return v; } |
.extattr_get!(path, name, namespace: File::EXTATTR_NAMESPACE_USER) ⇒ Object
324 325 326 327 328 329 330 331 332 333 334 335 336 |
# File 'ext/extattr.c', line 324 static VALUE file_s_extattr_get_link(int argc, VALUE argv[], VALUE file) { VALUE path, name, opts = Qnil; rb_scan_args(argc, argv, "2:", &path, &name, &opts); ext_check_path_security(path, name, Qnil); Check_Type(name, RUBY_T_STRING); VALUE v = file_s_extattr_get_link_main(StringValue(path), ext_get_namespace(opts), StringValue(name)); OBJ_INFECT(v, path); return v; } |
.extattr_list(path, namespace: File::EXTATTR_NAMESPACE_USER) ⇒ Object .extattr_list(path, namespace: File::EXTATTR_NAMESPACE_USER) {|name| ... } ⇒ nil
ファイル名を指定すること以外は File#extattr_list と同じです。
205 206 207 208 209 210 211 212 213 |
# File 'ext/extattr.c', line 205 static VALUE file_s_extattr_list(int argc, VALUE argv[], VALUE file) { VALUE path, opts = Qnil; rb_scan_args(argc, argv, "1:", &path, &opts); ext_check_path_security(path, Qnil, Qnil); return file_s_extattr_list_main(StringValue(path), ext_get_namespace(opts)); } |
.extattr_list!(path, namespace: File::EXTATTR_NAMESPACE_USER) ⇒ Object .extattr_list!(path, namespace: File::EXTATTR_NAMESPACE_USER) {|name| ... } ⇒ nil
シンボリックリンクに対する操作という以外は、File.extattr_list と同じです。
222 223 224 225 226 227 228 229 230 |
# File 'ext/extattr.c', line 222 static VALUE file_s_extattr_list_link(int argc, VALUE argv[], VALUE file) { VALUE path, opts = Qnil; rb_scan_args(argc, argv, "1:", &path, &opts); ext_check_path_security(path, Qnil, Qnil); return file_s_extattr_list_link_main(StringValue(path), ext_get_namespace(opts)); } |
.extattr_set(path, name, data, namespace: File::EXTATTR_NAMESPACE_USER) ⇒ nil
360 361 362 363 364 365 366 367 368 369 370 371 |
# File 'ext/extattr.c', line 360 static VALUE file_s_extattr_set(int argc, VALUE argv[], VALUE file) { VALUE path, name, data, opts = Qnil; rb_scan_args(argc, argv, "3:", &path, &name, &data, &opts); ext_check_path_security(path, name, data); Check_Type(name, RUBY_T_STRING); return file_s_extattr_set_main(StringValue(path), ext_get_namespace(opts), StringValue(name), StringValue(data)); } |
.extattr_set!(path, name, data, namespace: File::EXTATTR_NAMESPACE_USER) ⇒ nil
377 378 379 380 381 382 383 384 385 386 387 388 |
# File 'ext/extattr.c', line 377 static VALUE file_s_extattr_set_link(int argc, VALUE argv[], VALUE file) { VALUE path, name, data, opts = Qnil; rb_scan_args(argc, argv, "3:", &path, &name, &data, &opts); ext_check_path_security(path, name, data); Check_Type(name, RUBY_T_STRING); return file_s_extattr_set_link_main(StringValue(path), ext_get_namespace(opts), StringValue(name), StringValue(data)); } |
.extattr_size(path, name, namespace: File::EXTATTR_NAMESPACE_USER) ⇒ Object
255 256 257 258 259 260 261 262 263 264 265 |
# File 'ext/extattr.c', line 255 static VALUE file_s_extattr_size(int argc, VALUE argv[], VALUE file) { VALUE path, name, opts = Qnil; rb_scan_args(argc, argv, "2:", &path, &name, &opts); ext_check_path_security(path, name, Qnil); Check_Type(name, RUBY_T_STRING); return file_s_extattr_size_main(StringValue(path), ext_get_namespace(opts), StringValue(name)); } |
.extattr_size!(path, name, namespace: File::EXTATTR_NAMESPACE_USER) ⇒ Object
271 272 273 274 275 276 277 278 279 280 281 |
# File 'ext/extattr.c', line 271 static VALUE file_s_extattr_size_link(int argc, VALUE argv[], VALUE file) { VALUE path, name, opts = Qnil; rb_scan_args(argc, argv, "2:", &path, &name, &opts); ext_check_path_security(path, name, Qnil); Check_Type(name, RUBY_T_STRING); return file_s_extattr_size_link_main(StringValue(path), ext_get_namespace(opts), StringValue(name)); } |
Instance Method Details
#extattr_delete(name, namespace: File::EXTATTR_NAMESPACE_USER) ⇒ nil
395 396 397 398 399 400 401 402 403 404 405 |
# File 'ext/extattr.c', line 395 static VALUE file_extattr_delete(int argc, VALUE argv[], VALUE file) { VALUE name, opts = Qnil; rb_scan_args(argc, argv, "1:", &name, &opts); ext_check_file_security(file, name, Qnil); Check_Type(name, RUBY_T_STRING); return file_extattr_delete_main(file, file2fd(file), ext_get_namespace(opts), StringValue(name)); } |
#extattr_each(*namespace) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/extattr.rb', line 49 def extattr_each(*namespace) return to_enum(:extattr_each, *namespace) unless block_given? extattr_list(*namespace) do |name| yield(name, extattr_get(name, *namespace)) end self end |
#extattr_get(name, namespace: File::EXTATTR_NAMESPACE_USER) ⇒ Object
288 289 290 291 292 293 294 295 296 297 298 299 300 |
# File 'ext/extattr.c', line 288 static VALUE file_extattr_get(int argc, VALUE argv[], VALUE file) { VALUE name, opts = Qnil; rb_scan_args(argc, argv, "1:", &name, &opts); ext_check_file_security(file, name, Qnil); Check_Type(name, RUBY_T_STRING); VALUE v = file_extattr_get_main(file, file2fd(file), ext_get_namespace(opts), StringValue(name)); OBJ_INFECT(v, file); return v; } |
#extattr_list(namespace: File::EXTATTR_NAMESPACE_USER) ⇒ Object #extattr_list(namespace: File::EXTATTR_NAMESPACE_USER) {|name| ... } ⇒ nil
開いているファイルの拡張属性名一覧を得ます。
ブロックが指定された場合、一つ一つの拡張属性名を渡してブロックが評価されます。ブロックの戻り値は無視されます。
188 189 190 191 192 193 194 195 196 |
# File 'ext/extattr.c', line 188 static VALUE file_extattr_list(int argc, VALUE argv[], VALUE file) { VALUE opts = Qnil; rb_scan_args(argc, argv, "0:", &opts); ext_check_file_security(file, Qnil, Qnil); return file_extattr_list_main(file, file2fd(file), ext_get_namespace(opts)); } |
#extattr_set(name, data, namespace: File::EXTATTR_NAMESPACE_USER) ⇒ nil
343 344 345 346 347 348 349 350 351 352 353 354 |
# File 'ext/extattr.c', line 343 static VALUE file_extattr_set(int argc, VALUE argv[], VALUE file) { VALUE name, data, opts = Qnil; rb_scan_args(argc, argv, "2:", &name, &data, &opts); ext_check_file_security(file, name, data); Check_Type(name, RUBY_T_STRING); return file_extattr_set_main(file, file2fd(file), ext_get_namespace(opts), StringValue(name), StringValue(data)); } |
#extattr_size(name, namespace: File::EXTATTR_NAMESPACE_USER) ⇒ Object
拡張属性の大きさを取得します。
239 240 241 242 243 244 245 246 247 248 249 |
# File 'ext/extattr.c', line 239 static VALUE file_extattr_size(int argc, VALUE argv[], VALUE file) { VALUE name, opts = Qnil; rb_scan_args(argc, argv, "1:", &name, &opts); ext_check_file_security(file, name, Qnil); Check_Type(name, RUBY_T_STRING); return file_extattr_size_main(file, file2fd(file), ext_get_namespace(opts), StringValue(name)); } |