extattr 0.1.2 → 0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,27 +5,29 @@ raise "require ruby-1.9.3+" unless RUBY_VERSION >= "1.9.3"
5
5
 
6
6
  require "mkmf"
7
7
 
8
- #$CFLAGS << " -std=c99"
8
+ #$CFLAGS << " -std=c99"
9
9
 
10
10
  case
11
11
  when have_header("sys/extattr.h")
12
+
13
+ when have_header("attr/xattr.h")
14
+ $CPPFLAGS << " -DLINUX_XATTR_H=\\<attr/xattr.h\\>"
15
+
16
+ when have_header("sys/xattr.h")
17
+ $CPPFLAGS << " -DLINUX_XATTR_H=\\<sys/xattr.h\\>"
18
+
12
19
  when have_header("winnt.h") && have_header("ntdef.h") && have_header("psapi.h") &&
13
20
  have_header("ddk/ntifs.h") && have_header("ddk/winddk.h") &&
14
21
  have_library("ntoskrnl") && have_library("ntdll") && have_library("psapi")
15
- when have_header("attr/xattr.h")
16
- $CPPFLAGS << " -DLINUX_XATTR_H=\\<attr/xattr.h\\>"
17
- when have_header("sys/xattr.h")
18
- $CPPFLAGS << " -DLINUX_XATTR_H=\\<sys/xattr.h\\>"
22
+
19
23
  else
20
- $stderr.puts <<-EOS
24
+ $stderr.puts <<EOM
21
25
  #$0: not supported target.
22
26
  \tmust be available either ddk/ntifs.h, sys/extattr.h or attr/xattr.h on your system.
23
- EOS
24
- exit 1
27
+ EOM
28
+ exit 1
25
29
  end
26
30
 
27
- create_makefile "extattr" or exit 2
28
-
29
-
30
- #$CPPFLAGS << " -Wall -DFUSE_USE_VERSION=26"
31
+ #$CFLAGS << " -std=c99"
31
32
 
33
+ create_makefile "extattr"
@@ -0,0 +1,57 @@
1
+ #vim: set fileencoding:utf-8
2
+
3
+ ver = RbConfig::CONFIG["ruby_version"]
4
+ soname = File.basename(__FILE__, ".rb") << ".so"
5
+ lib = File.join(File.dirname(__FILE__), ver, soname)
6
+ if File.file?(lib)
7
+ require_relative File.join(ver, soname)
8
+ else
9
+ require_relative soname
10
+ end
11
+
12
+ #
13
+ # Add operation methods of extended file attribute to File.
14
+ #
15
+ # File クラスに拡張属性を操作するメソッドを追加します。
16
+ #
17
+ # 感嘆符 (『!』) のついたメソッドは、シンボリックリンクに対する操作となります。
18
+ #
19
+ # メソッドにキーワード引数として <code>namespace:</code> を与えることにより、拡張属性の名前空間を指定することが出来ます。
20
+ #
21
+ # 現在の実装においては <code>EXTATTR_NAMESPACE_USER</code> と <code>EXTATTR_NAMESPACE_SYSTEM</code> のみが利用可能です。
22
+ #
23
+ class File
24
+ #
25
+ # call-seq:
26
+ # extattr_each(path, namespace: File::EXTATTR_NAMESPACE_USER) -> Enumerator
27
+ # extattr_each(path, namespace: File::EXTATTR_NAMESPACE_USER) { |name, data| ... } -> File
28
+ # extattr_each!(path, namespace: File::EXTATTR_NAMESPACE_USER) -> Enumerator
29
+ # extattr_each!(path, namespace: File::EXTATTR_NAMESPACE_USER) { |name, data| ... } -> File
30
+ #
31
+ def self.extattr_each(path, *namespace)
32
+ return to_enum(:extattr_each, path, *namespace) unless block_given?
33
+
34
+ extattr_list(path, *namespace) do |name|
35
+ yield(name, extattr_get(path, name, *namespace))
36
+ end
37
+ self
38
+ end
39
+
40
+ def self.extattr_each!(path, *namespace)
41
+ return to_enum(:extattr_each!, path, *namespace) unless block_given?
42
+
43
+ extattr_list!(path, *namespace) do |name|
44
+ yield(name, extattr_get!(path, name, *namespace))
45
+ end
46
+ self
47
+ end
48
+
49
+ def extattr_each(*namespace)
50
+ return to_enum(:extattr_each, *namespace) unless block_given?
51
+
52
+ extattr_list(*namespace) do |name|
53
+ yield(name, extattr_get(name, *namespace))
54
+ end
55
+ self
56
+ end
57
+ end
metadata CHANGED
@@ -1,66 +1,89 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: extattr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
5
- prerelease:
4
+ version: '0.2'
6
5
  platform: ruby
7
6
  authors:
8
7
  - dearblue
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-22 00:00:00.000000000 Z
13
- dependencies: []
14
- description: ! 'extattr is extended attribute operation library for ruby.
15
-
16
- Supported for FreeBSD, Gnu/Linux and Microsoft Windows.
17
-
18
- '
11
+ date: 2014-03-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: |
42
+ extattr is extended file attribute operation library for ruby.
43
+ Supported for FreeBSD (extattr), GNU/Linux (xattr) and Microsoft Windows (NTFS ADS + Extended Attributes).
19
44
  email: dearblue@users.sourceforge.jp
20
45
  executables: []
21
46
  extensions:
22
47
  - ext/extconf.rb
23
- extra_rdoc_files:
24
- - README.txt
25
- - LICENSE.txt
26
- - ext/extattr.c
48
+ extra_rdoc_files: []
27
49
  files:
28
- - README.txt
29
- - LICENSE.txt
30
- - ext/extconf.rb
50
+ - LICENSE.md
51
+ - README.md
52
+ - Rakefile
53
+ - ext/extattr-extattr.h
54
+ - ext/extattr-windows.h
55
+ - ext/extattr-xattr.h
31
56
  - ext/extattr.c
32
- - ext/extattr.bsd
33
- - ext/extattr.linux
34
- - ext/extattr.windows
35
- - rspecs/extattr.rb
57
+ - ext/extconf.rb
58
+ - lib/extattr.rb
59
+ - spec/extattr_spec.rb
36
60
  homepage: http://sourceforge.jp/projects/rutsubo/
37
61
  licenses:
38
62
  - 2-clause BSD License
63
+ metadata: {}
39
64
  post_install_message:
40
65
  rdoc_options:
41
- - -e
66
+ - "--charset"
42
67
  - UTF-8
43
- - -m
44
- - README.txt
68
+ - "--main"
69
+ - README.md
45
70
  require_paths:
46
71
  - lib
47
72
  required_ruby_version: !ruby/object:Gem::Requirement
48
- none: false
49
73
  requirements:
50
- - - ! '>='
74
+ - - ">="
51
75
  - !ruby/object:Gem::Version
52
76
  version: 1.9.3
53
77
  required_rubygems_version: !ruby/object:Gem::Requirement
54
- none: false
55
78
  requirements:
56
- - - ! '>='
79
+ - - ">="
57
80
  - !ruby/object:Gem::Version
58
81
  version: '0'
59
82
  requirements: []
60
83
  rubyforge_project:
61
- rubygems_version: 1.8.24
84
+ rubygems_version: 2.2.2
62
85
  signing_key:
63
- specification_version: 3
86
+ specification_version: 4
64
87
  summary: extended attribute operation library for ruby
65
88
  test_files: []
66
- has_rdoc: false
89
+ has_rdoc:
data/README.txt DELETED
@@ -1,73 +0,0 @@
1
- = extattr
2
-
3
- extattr is filesystem extended attributes operation library for FreeBSD, GNU/Linux and Microsoft Windows.
4
-
5
- ----
6
-
7
- extattr はファイルシステムの拡張属性を操作するライブラリで、FreeBSD、GNU/Linux、Windows に対応しています。
8
-
9
- サポートされる環境で、統一的なメソッドを提供します。
10
-
11
-
12
- == test system
13
-
14
- - Microsoft Windows XP Professional SP3
15
- - PC-BSD/AMD64 9.0
16
- - lubuntu 12.04
17
-
18
-
19
- == 簡易リファレンスマニュアル
20
-
21
- クラスメソッドに『!』がついているものはシンボリックリンクに対する操作となります。
22
-
23
- キーワード引数の <code>namespace</code> を与えると、拡張属性の名前空間を指定できます。
24
- 規定値は <code>EXTATTR_NAMESPACE_USER</code> で、ほかの値は <code>EXTATTR_NAMESPACE_SYSTEM</code> のみが指定できます
25
- (Windows 版では <code>EXTATTR_NAMESPACE_USER</code> のみが指定可能です)。
26
-
27
- 拡張属性の属性名を取得:
28
-
29
- File#extattr_list(namespace: File::EXTATTR_NAMESPACE_USER) -> array
30
- File#extattr_list(namespace: File::EXTATTR_NAMESPACE_USER) { |name| ... } -> nil
31
- File.extattr_list(path, namespace: File::EXTATTR_NAMESPACE_USER) -> array
32
- File.extattr_list(path, namespace: File::EXTATTR_NAMESPACE_USER) { |name| ... } -> nil
33
- File.extattr_list!(path, namespace: File::EXTATTR_NAMESPACE_USER) -> array
34
- File.extattr_list!(path, namespace: File::EXTATTR_NAMESPACE_USER) { |name| ... } -> nil
35
-
36
- 拡張属性の要素の大きさを取得:
37
-
38
- File#extattr_size(name, namespace: File::EXTATTR_NAMESPACE_USER) -> size
39
- File.extattr_size(path, name, namespace: File::EXTATTR_NAMESPACE_USER) -> size
40
- File.extattr_size!(path, name, namespace: File::EXTATTR_NAMESPACE_USER) -> size
41
-
42
- 拡張属性の要素を取得:
43
-
44
- File#extattr_get(name, namespace: File::EXTATTR_NAMESPACE_USER) -> data (String)
45
- File.extattr_get(path, name, namespace: File::EXTATTR_NAMESPACE_USER) -> data (String)
46
- File.extattr_get!(path, name, namespace: File::EXTATTR_NAMESPACE_USER) -> data (String)
47
-
48
- 拡張属性の要素を設定:
49
-
50
- File#extattr_set(name, data, namespace: File::EXTATTR_NAMESPACE_USER) -> nil
51
- File.extattr_set(path, name, data, namespace: File::EXTATTR_NAMESPACE_USER) -> nil
52
- File.extattr_set!(path, name, data, namespace: File::EXTATTR_NAMESPACE_USER) -> nil
53
-
54
- 拡張属性の要素を削除:
55
-
56
- File#extattr_delete(name, namespace: File::EXTATTR_NAMESPACE_USER) -> nil
57
- File.extattr_delete(path, name, namespace: File::EXTATTR_NAMESPACE_USER) -> nil
58
- File.extattr_delete!(path, name, namespace: File::EXTATTR_NAMESPACE_USER) -> nil
59
-
60
-
61
- == Microsoft Windows における諸注意
62
-
63
- Windows 2000 以降でのみ動作します。Windows 9X シリーズでは <code>require "extattr"</code> の段階で例外が発生するでしょう。
64
-
65
- リパースポイント (ジャンクションやシンボリックリンク) に対する ADS は要素の取得や設定、削除は出来ません。
66
- 必ずリンク先に対する操作となります。
67
-
68
- 64 KiB を超える ADS は取得も設定も出来ません。
69
- これは『拡張属性』と捉えた場合、巨大なデータを扱えるべきではないという考えによるためです
70
- (本当のところは FreeBSD の拡張属性が最大 64KiB 弱であることが由来です)。
71
- 巨大な ADS を扱いたい場合は、<code>File.open</code> でファイルとして扱えるので自由に読み書きできます
72
- (これは ruby に限ったことではなく、Windows による仕様です)。
73
- この場合の与えるファイル名は、<code>path + ":" + name</code> という形になります。
@@ -1,186 +0,0 @@
1
- #include <sys/types.h>
2
- #include <sys/extattr.h>
3
-
4
-
5
- static void
6
- split_name(const char list[], size_t size, void (*func)(void *, VALUE), void *userdata)
7
- {
8
- // Each list entry consists of a single byte containing the length of
9
- // the attribute name, followed by the attribute name.
10
- // The attribute name is not terminated by ASCII 0 (nul).
11
- const char *ptr = list;
12
- const char *end = list + size;
13
-
14
- while (ptr < end) {
15
- size_t len = (uint8_t)*ptr ++;
16
- if (ptr + len > end) { return; }
17
- func(userdata, rb_str_new(ptr, len));
18
- ptr += len;
19
- }
20
- }
21
-
22
- static int
23
- get_extattr_list_size(int (*extattr_list)(), intptr_t d, int namespace)
24
- {
25
- int size = extattr_list(d, namespace, NULL, 0);
26
- if (size < 0) { rb_sys_fail("extattr_list call error"); }
27
- return size;
28
- }
29
-
30
- static VALUE
31
- extattr_list0(int (*extattr_list)(), intptr_t d, int namespace)
32
- {
33
- size_t size = get_extattr_list_size(extattr_list, d, namespace);
34
- VALUE buf = rb_str_buf_new(size);
35
- char *ptr = RSTRING_PTR(buf);
36
-
37
- ssize_t size1 = extattr_list(d, namespace, ptr, size);
38
- if (size1 < 0) { rb_sys_fail("extattr_list call error"); }
39
-
40
- VALUE list = Qnil;
41
- if (rb_block_given_p()) {
42
- split_name(ptr, size1, (void (*)(void *, VALUE))rb_yield_values, (void *)(1));
43
- } else {
44
- list = rb_ary_new();
45
- split_name(ptr, size1, (void (*)(void *, VALUE))rb_ary_push, (void *)list);
46
- }
47
- rb_free_tmp_buffer(&buf);
48
-
49
- return list;
50
- }
51
-
52
- static VALUE
53
- file_extattr_list0(VALUE file, int fd, int namespace)
54
- {
55
- return extattr_list0(extattr_list_fd, fd, namespace);
56
- }
57
-
58
- static VALUE
59
- file_s_extattr_list0(VALUE path, int namespace)
60
- {
61
- return extattr_list0(extattr_list_file, (intptr_t)StringValueCStr(path), namespace);
62
- }
63
-
64
- static VALUE
65
- file_s_extattr_list_link0(VALUE path, int namespace)
66
- {
67
- return extattr_list0(extattr_list_link, (intptr_t)StringValueCStr(path), namespace);
68
- }
69
-
70
-
71
- static VALUE
72
- extattr_size0(int (*extattr_get)(), intptr_t d, int namespace, VALUE name)
73
- {
74
- ssize_t size = extattr_get(d, namespace, RSTRING_PTR(name), NULL, 0);
75
- if (size < 0) { rb_sys_fail("extattr_get call error"); }
76
- return SIZET2NUM(size);
77
- }
78
-
79
- static VALUE
80
- file_extattr_size0(VALUE file, int fd, int namespace, VALUE name)
81
- {
82
- return extattr_size0(extattr_get_fd, fd, namespace, name);
83
- }
84
-
85
- static VALUE
86
- file_s_extattr_size0(VALUE path, int namespace, VALUE name)
87
- {
88
- return extattr_size0(extattr_get_file, (intptr_t)StringValueCStr(path), namespace, name);
89
- }
90
-
91
- static VALUE
92
- file_s_extattr_size_link0(VALUE path, int namespace, VALUE name)
93
- {
94
- return extattr_size0(extattr_get_link, (intptr_t)StringValueCStr(path), namespace, name);
95
- }
96
-
97
-
98
- static VALUE
99
- extattr_get0(int (*extattr_get)(), intptr_t d, VALUE path, int namespace, VALUE name)
100
- {
101
- ssize_t size = extattr_get(d, namespace, RSTRING_PTR(name), NULL, 0);
102
- if (size < 0) { rb_sys_fail(StringValueCStr(path)); }
103
- VALUE buf = rb_str_buf_new(size);
104
- size = extattr_get(d, namespace, RSTRING_PTR(name), RSTRING_PTR(buf), size);
105
- if (size < 0) { rb_sys_fail(StringValueCStr(path)); }
106
- rb_str_set_len(buf, size);
107
- return buf;
108
- }
109
-
110
- static VALUE
111
- file_extattr_get0(VALUE file, int fd, int namespace, VALUE name)
112
- {
113
- return extattr_get0(extattr_get_fd, fd, RFILE(file)->fptr->pathv, namespace, name);
114
- }
115
-
116
- static VALUE
117
- file_s_extattr_get0(VALUE path, int namespace, VALUE name)
118
- {
119
- return extattr_get0(extattr_get_file, (intptr_t)StringValueCStr(path), path, namespace, name);
120
- }
121
-
122
- static VALUE
123
- file_s_extattr_get_link0(VALUE path, int namespace, VALUE name)
124
- {
125
- return extattr_get0(extattr_get_link, (intptr_t)StringValueCStr(path), path, namespace, name);
126
- }
127
-
128
-
129
- static VALUE
130
- extattr_set0(int (*extattr_set)(), intptr_t d, int namespace, VALUE name, VALUE data)
131
- {
132
- int status = extattr_set(d, namespace, RSTRING_PTR(name), RSTRING_PTR(data), RSTRING_LEN(data));
133
- if (status < 0) { rb_sys_fail("extattr_set call error"); }
134
- return Qnil;
135
- }
136
-
137
- static VALUE
138
- file_extattr_set0(VALUE file, int fd, int namespace, VALUE name, VALUE data)
139
- {
140
- return extattr_set0(extattr_set_fd, fd, namespace, name, data);
141
- }
142
-
143
- static VALUE
144
- file_s_extattr_set0(VALUE path, int namespace, VALUE name, VALUE data)
145
- {
146
- return extattr_set0(extattr_set_file, (intptr_t)StringValueCStr(path), namespace, name, data);
147
- }
148
-
149
- static VALUE
150
- file_s_extattr_set_link0(VALUE path, int namespace, VALUE name, VALUE data)
151
- {
152
- return extattr_set0(extattr_set_link, (intptr_t)StringValueCStr(path), namespace, name, data);
153
- }
154
-
155
-
156
- static VALUE
157
- extattr_delete0(int (*extattr_delete)(), intptr_t d, int namespace, VALUE name)
158
- {
159
- int status = extattr_delete(d, namespace, RSTRING_PTR(name), NULL, 0);
160
- if (status < 0) { rb_sys_fail("extattr_delete call error"); }
161
- return Qnil;
162
- }
163
-
164
- static VALUE
165
- file_extattr_delete0(VALUE file, int fd, int namespace, VALUE name)
166
- {
167
- return extattr_delete0(extattr_delete_fd, fd, namespace, name);
168
- }
169
-
170
- static VALUE
171
- file_s_extattr_delete0(VALUE path, int namespace, VALUE name)
172
- {
173
- return extattr_delete0(extattr_delete_file, (intptr_t)StringValueCStr(path), namespace, name);
174
- }
175
-
176
- static VALUE
177
- file_s_extattr_delete_link0(VALUE path, int namespace, VALUE name)
178
- {
179
- return extattr_delete0(extattr_delete_link, (intptr_t)StringValueCStr(path), namespace, name);
180
- }
181
-
182
-
183
- static void
184
- setup(void)
185
- {
186
- }