ffi-xattr 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e9a5f43304cb60076094f298ec9168a89a9df2ba
4
- data.tar.gz: f645a4aaf033393e17df324565c195b54bcb7015
2
+ SHA256:
3
+ metadata.gz: 4e89f2e515824d33bf4cfe74b95eea1526e35092c669bb5f4280c8d4c86071d4
4
+ data.tar.gz: 3369d3f39135d5176d1b24077eb380ff5140aa78498ccbd9f0b0291d2c36484c
5
5
  SHA512:
6
- metadata.gz: d5c62fa8db807ef7acefe5d47c2936cb96813c234c4dcad46b322802047a6e482faaf08d5a2152b80d39a042a9ef091c8d46789cf3aacc02067a13d9d4473d15
7
- data.tar.gz: 513f18a55640e5bc9b72095842a8018ec9665674c7ea85740b810540fbc1d0b834ebec5fc9b08ebbb3baac0c322c657fbf2d36fdb92bc4d46a75064d536c948f
6
+ metadata.gz: ea47fac5b6f82cf0c065724f3283bb72fe81f0636eb9613be1e7f89f42066e52cc038a8fa2d00ee12b8faa88f74dbb830f795eea1144ec7943f18bb40c134ef1
7
+ data.tar.gz: fd88cae5f42ca84e36214b76c82afedfd367c5e60e3767d786221ec62dbf95d9c9ea6ccf4e395ea55a2be9a66524bc015edad49b744505d7dcfca239b720145a
data/.gitignore CHANGED
@@ -3,3 +3,4 @@
3
3
  Gemfile.lock
4
4
  pkg/*
5
5
  /doc/
6
+ vendor
@@ -16,7 +16,7 @@ class Xattr # :nodoc: all
16
16
  end
17
17
 
18
18
  def check(int)
19
- raise SystemCallError.new(*last) if int != 0
19
+ raise SystemCallError.new(*last) if int < 0
20
20
  end
21
21
  end
22
22
  end
@@ -0,0 +1,62 @@
1
+ class Xattr # :nodoc: all
2
+ module Lib
3
+ extend FFI::Library
4
+
5
+ ffi_lib "c"
6
+
7
+ EXTATTR_NAMESPACE_USER = 1
8
+
9
+ attach_function :extattr_list_file, [:string, :int, :pointer, :size_t], :ssize_t
10
+ attach_function :extattr_set_file, [:string, :int, :string, :pointer, :size_t], :ssize_t
11
+ attach_function :extattr_get_file, [:string, :int, :string, :pointer, :size_t], :ssize_t
12
+ attach_function :extattr_delete_file, [:string, :int, :string], :ssize_t
13
+
14
+ attach_function :extattr_list_link, [:string, :int, :pointer, :size_t], :ssize_t
15
+ attach_function :extattr_set_link, [:string, :int, :string, :pointer, :size_t], :ssize_t
16
+ attach_function :extattr_get_link, [:string, :int, :string, :pointer, :size_t], :ssize_t
17
+ attach_function :extattr_delete_link, [:string, :int, :string], :ssize_t
18
+
19
+ class << self
20
+ def list(path, no_follow)
21
+ method = no_follow ? :extattr_list_link : :extattr_list_file
22
+ size = send(method, path, EXTATTR_NAMESPACE_USER, nil, 0)
23
+ res_ptr = FFI::MemoryPointer.new(:pointer, size)
24
+ send(method, path, EXTATTR_NAMESPACE_USER, res_ptr, size)
25
+
26
+ res = []
27
+ bytes = res_ptr.read_string(size).bytes
28
+ until bytes.empty?
29
+ size = bytes.shift
30
+ res << bytes.shift(size).map(&:chr).join
31
+ end
32
+
33
+ res
34
+ end
35
+
36
+ def get(path, no_follow, key)
37
+ method = no_follow ? :extattr_get_link : :extattr_get_file
38
+ size = send(method, path, EXTATTR_NAMESPACE_USER, key, nil, 0)
39
+ return unless size > 0
40
+
41
+ str_ptr = FFI::MemoryPointer.new(:char, size)
42
+ send(method, path, EXTATTR_NAMESPACE_USER, key, str_ptr, size)
43
+
44
+ str_ptr.read_string(size)
45
+ end
46
+
47
+ def set(path, no_follow, key, value)
48
+ method = no_follow ? :extattr_set_link : :extattr_set_file
49
+ #require 'byebug'
50
+ #byebug
51
+
52
+ Error.check send(method, path, EXTATTR_NAMESPACE_USER, key, value, value.bytesize)
53
+ end
54
+
55
+ def remove(path, no_follow, key)
56
+ method = no_follow ? :extattr_delete_link : :extattr_delete_file
57
+ Error.check send(method, path, EXTATTR_NAMESPACE_USER, key)
58
+ end
59
+ end
60
+
61
+ end
62
+ end
@@ -1,3 +1,3 @@
1
1
  class Xattr
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/ffi-xattr.rb CHANGED
@@ -5,6 +5,8 @@ require 'ffi-xattr/error'
5
5
  case RUBY_PLATFORM
6
6
  when /linux/
7
7
  require 'ffi-xattr/linux_lib'
8
+ when /freebsd/
9
+ require 'ffi-xattr/freebsd_lib'
8
10
  when /darwin|bsd/
9
11
  require 'ffi-xattr/darwin_lib'
10
12
  when /mingw/
data/spec/xattr_spec.rb CHANGED
@@ -57,7 +57,7 @@ describe Xattr do
57
57
  value.should == "world"
58
58
  end
59
59
 
60
- called.should be_true
60
+ called.should == true
61
61
  end
62
62
 
63
63
  it "is Enumerable" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi-xattr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jari Bakken
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-12 00:00:00.000000000 Z
11
+ date: 2022-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -72,6 +72,7 @@ files:
72
72
  - lib/ffi-xattr/extensions.rb
73
73
  - lib/ffi-xattr/extensions/file.rb
74
74
  - lib/ffi-xattr/extensions/pathname.rb
75
+ - lib/ffi-xattr/freebsd_lib.rb
75
76
  - lib/ffi-xattr/linux_lib.rb
76
77
  - lib/ffi-xattr/version.rb
77
78
  - lib/ffi-xattr/windows_lib.rb
@@ -95,12 +96,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
96
  - !ruby/object:Gem::Version
96
97
  version: '0'
97
98
  requirements: []
98
- rubyforge_project: ffi-xattr
99
- rubygems_version: 2.2.0
99
+ rubygems_version: 3.0.3.1
100
100
  signing_key:
101
101
  specification_version: 4
102
102
  summary: Manipulate extended file attributes
103
103
  test_files:
104
104
  - spec/extensions_spec.rb
105
105
  - spec/xattr_spec.rb
106
- has_rdoc: