class File

Add operation methods of extended file attribute to File.

File クラスに拡張属性を操作するメソッドを追加します。

感嘆符 (『!』) のついたメソッドは、シンボリックリンクに対する操作となります。

メソッドにキーワード引数として namespace: を与えることにより、拡張属性の名前空間を指定することが出来ます。

現在の実装においては EXTATTR_NAMESPACE_USEREXTATTR_NAMESPACE_SYSTEM のみが利用可能です。

Constants

EXTATTR_IMPLEMANT
EXTATTR_NAMESPACE_SYSTEM
EXTATTR_NAMESPACE_USER
EXTATTR_VERSION

Public Class Methods

extattr_delete(path, name, namespace: File::EXTATTR_NAMESPACE_USER) → nil click to toggle source
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 click to toggle source
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: File::EXTATTR_NAMESPACE_USER) → Enumerator click to toggle source
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
# 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) { |name, extattr_get!(path, name, *namespace)| ... } click to toggle source
# 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) → data click to toggle source
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) → data click to toggle source
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) → names array click to toggle source
extattr_list(path, namespace: File::EXTATTR_NAMESPACE_USER) { |name| ... } → nil

ファイル名を指定すること以外は File#extattr_list と同じです。

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) → names array click to toggle source
extattr_list!(path, namespace: File::EXTATTR_NAMESPACE_USER) { |name| ... } → nil

シンボリックリンクに対する操作という以外は、File.extattr_list と同じです。

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 click to toggle source
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 click to toggle source
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) → size click to toggle source
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) → size click to toggle source
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));
}

Public Instance Methods

extattr_delete(name, namespace: File::EXTATTR_NAMESPACE_USER) → nil click to toggle source
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) { |name, extattr_get(name, *namespace)| ... } click to toggle source
# 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) → data click to toggle source
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) → names array click to toggle source
extattr_list(namespace: File::EXTATTR_NAMESPACE_USER) { |name| ... } → nil

開いているファイルの拡張属性名一覧を得ます。

ブロックが指定された場合、一つ一つの拡張属性名を渡してブロックが評価されます。ブロックの戻り値は無視されます。

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 click to toggle source
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) → names array click to toggle source

拡張属性の大きさを取得します。

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));
}