ffi-xattr 0.0.1 → 0.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.
- data/lib/ffi-xattr/version.rb +1 -1
- data/lib/ffi-xattr.rb +4 -37
- data/spec/xattr_spec.rb +8 -1
- metadata +1 -1
data/lib/ffi-xattr/version.rb
CHANGED
data/lib/ffi-xattr.rb
CHANGED
@@ -23,13 +23,15 @@ class Xattr
|
|
23
23
|
def list
|
24
24
|
size = Lib.listxattr(@path, nil, 0)
|
25
25
|
res_ptr = FFI::MemoryPointer.new(:pointer, size)
|
26
|
-
|
27
26
|
Lib.listxattr(@path, res_ptr, size)
|
28
|
-
|
27
|
+
|
28
|
+
res_ptr.read_string(size).split("\000")
|
29
29
|
end
|
30
30
|
|
31
31
|
def get(key)
|
32
32
|
size = Lib.getxattr(@path, key.to_s, nil, 0)
|
33
|
+
return unless size > 0
|
34
|
+
|
33
35
|
str_ptr = FFI::MemoryPointer.new(:char, size);
|
34
36
|
Lib.getxattr(@path, key.to_s, str_ptr, size)
|
35
37
|
|
@@ -53,39 +55,4 @@ class Xattr
|
|
53
55
|
end
|
54
56
|
end
|
55
57
|
|
56
|
-
if __FILE__ == $0
|
57
|
-
require 'rspec/autorun'
|
58
|
-
|
59
|
-
describe Xattr do
|
60
|
-
let(:path) { "test.txt" }
|
61
|
-
let(:xattr) { Xattr.new(path) }
|
62
|
-
|
63
|
-
before { File.open(path, "w") { |io| io << "some content" } }
|
64
|
-
after { File.delete(path) }
|
65
|
-
|
66
|
-
it "has an inital empty list of xattrs" do
|
67
|
-
xattr.list.should be_kind_of(Array)
|
68
|
-
xattr.list.should be_empty
|
69
|
-
end
|
70
|
-
|
71
|
-
it "can set and get attributes" do
|
72
|
-
xattr.set "user.foo", "bar"
|
73
|
-
xattr.list.should == ["user.foo"]
|
74
58
|
|
75
|
-
xattr.get("user.foo").should == "bar"
|
76
|
-
end
|
77
|
-
|
78
|
-
it "can remove attributes" do
|
79
|
-
xattr.set "user.foo", "bar"
|
80
|
-
xattr.list.should == ["user.foo"]
|
81
|
-
|
82
|
-
xattr.remove "user.foo"
|
83
|
-
xattr.list.should == []
|
84
|
-
end
|
85
|
-
|
86
|
-
it "raises Errno::ENOENT if the file doesn't exist" do
|
87
|
-
lambda { Xattr.new("no-such-file") }.should raise_error(Errno::ENOENT)
|
88
|
-
end
|
89
|
-
|
90
|
-
end
|
91
|
-
end
|
data/spec/xattr_spec.rb
CHANGED
@@ -14,9 +14,12 @@ describe Xattr do
|
|
14
14
|
|
15
15
|
it "can set and get attributes" do
|
16
16
|
xattr.set "user.foo", "bar"
|
17
|
-
xattr.
|
17
|
+
xattr.set "user.bar", "boo"
|
18
|
+
|
19
|
+
xattr.list.should == ["user.foo", "user.bar"]
|
18
20
|
|
19
21
|
xattr.get("user.foo").should == "bar"
|
22
|
+
xattr.get("user.bar").should == "boo"
|
20
23
|
end
|
21
24
|
|
22
25
|
it "can remove attributes" do
|
@@ -27,6 +30,10 @@ describe Xattr do
|
|
27
30
|
xattr.list.should == []
|
28
31
|
end
|
29
32
|
|
33
|
+
it "returns nil if the attribute is not set" do
|
34
|
+
xattr.get("hello").should be_nil
|
35
|
+
end
|
36
|
+
|
30
37
|
it "raises Errno::ENOENT if the file doesn't exist" do
|
31
38
|
lambda { Xattr.new("no-such-file") }.should raise_error(Errno::ENOENT)
|
32
39
|
end
|