ffi-xattr 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5181ad35070fb0035bf81d417c9ccae80f533384
4
+ data.tar.gz: d2ac366fbc7441c2a20f97e2d00de292db189273
5
+ SHA512:
6
+ metadata.gz: d79f9cf983ca89e0f53aabaac1b4c32b3f72b47815f58ddd80a6a7cf35e7278876fb85d7253eae3d3d4929958fcfac9af55f774a09f0b59f559e0cca258dab77
7
+ data.tar.gz: a443c8fd63b32eb20924c9e3d5841d2e89aae52530cef42e16cb50fddce9bba7b3b9fa64525ad79e3030d58875fba2bc24fa6113cf537884f721eeaceffa44f4
data/.travis.yml CHANGED
@@ -3,4 +3,4 @@ rvm:
3
3
  - 1.9.2
4
4
  - 1.9.3
5
5
  before_script:
6
- - sudo mount / -o remount,user_xattr
6
+ - 'sudo mount / -o remount,user_xattr || (echo "see https://github.com/travis-ci/travis-ci/issues/1281" && exit 1)'
data/LICENSE CHANGED
@@ -186,7 +186,7 @@ APPENDIX: How to apply the Apache License to your work.
186
186
  same "printed page" as the copyright notice for easier
187
187
  identification within third-party archives.
188
188
 
189
- Copyright 2011 Jari Bakken
189
+ Copyright 2011-2012 Jari Bakken
190
190
 
191
191
  Licensed under the Apache License, Version 2.0 (the "License");
192
192
  you may not use this file except in compliance with the License.
data/README.md CHANGED
@@ -33,7 +33,7 @@ Note on Patches/Pull Requests
33
33
  Copyright
34
34
  ---------
35
35
 
36
- Copyright 2011 Jari Bakken
36
+ Copyright 2011-2012 Jari Bakken
37
37
 
38
38
  Licensed under the Apache License, Version 2.0 (the "License");
39
39
  you may not use this file except in compliance with the License.
data/lib/ffi-xattr.rb CHANGED
@@ -7,6 +7,8 @@ when /linux/
7
7
  require 'ffi-xattr/linux_lib'
8
8
  when /darwin|bsd/
9
9
  require 'ffi-xattr/darwin_lib'
10
+ when /mingw/
11
+ require 'ffi-xattr/windows_lib'
10
12
  else
11
13
  raise NotImplementedError, "ffi-xattr not supported on #{RUBY_PLATFORM}"
12
14
  end
@@ -18,7 +20,7 @@ class Xattr
18
20
  # Use <tt>:no_follow => true</tt> in options to work on symlink itself instead of following it.
19
21
  def initialize(path, options = {})
20
22
  raise Errno::ENOENT, path unless File.exist?(path)
21
- @path = path
23
+ @path = path.to_str
22
24
  @no_follow = !!options[:no_follow]
23
25
  end
24
26
 
@@ -29,7 +29,7 @@ class Xattr # :nodoc: all
29
29
  str_ptr = FFI::MemoryPointer.new(:char, size)
30
30
  getxattr(path, key, str_ptr, size, 0, options)
31
31
 
32
- str_ptr.read_string
32
+ str_ptr.read_string(size)
33
33
  end
34
34
 
35
35
  def set(path, no_follow, key, value)
@@ -4,7 +4,7 @@ class Xattr # :nodoc: all
4
4
 
5
5
  ffi_lib "c"
6
6
 
7
- attach_function :strerror_r, [:int, :pointer, :size_t], :int
7
+ attach_function :strerror_r, [:int, :pointer, :size_t], :int unless RUBY_PLATFORM =~ /mingw/
8
8
 
9
9
  class << self
10
10
  def last
@@ -34,7 +34,7 @@ class Xattr # :nodoc: all
34
34
  str_ptr = FFI::MemoryPointer.new(:char, size)
35
35
  send(method, path, key, str_ptr, size)
36
36
 
37
- str_ptr.read_string
37
+ str_ptr.read_string(size)
38
38
  end
39
39
 
40
40
  def set(path, no_follow, key, value)
@@ -1,3 +1,3 @@
1
1
  class Xattr
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+ require 'ffi-xattr'
3
+
4
+ class Xattr # :nodoc: all
5
+ module Lib
6
+ class << self
7
+
8
+ def list(path, no_follow)
9
+ lines = `dir /r "#{path}"`.split("\n")
10
+
11
+ xattrs = []
12
+ lines.each { |line|
13
+ if line =~ /\:\$DATA$/
14
+ size = line.split(' ')[0].gsub(/[^0-9]/,'').to_i
15
+
16
+ if size > 0
17
+ xattrs << line.split(':')[1]
18
+ end
19
+ end
20
+ }
21
+ xattrs
22
+ end
23
+
24
+ def get(path, no_follow, key)
25
+ fp = "#{path}:#{key}"
26
+ if File.exists?(fp)
27
+ File.binread(fp)
28
+ else
29
+ raise "No such key. #{key.inspect} #{path.inspect}"
30
+ end
31
+ end
32
+
33
+ def set(path, no_follow, key, value)
34
+ File.open("#{path}:#{key}",'wb') { |io| io << value }
35
+ end
36
+
37
+ def remove(path, no_follow, key)
38
+ # done this way because Windows have no function to remove Alternate Data Stream
39
+ # quickest way is to set the value to 0 byte length instead of trying to create another file then apply the attributes, especially when dealing with a big file
40
+ self.set(path, false, key, '')
41
+ end
42
+ end
43
+
44
+ end
45
+ end
data/spec/xattr_spec.rb CHANGED
@@ -75,6 +75,26 @@ describe Xattr do
75
75
  lambda { Xattr.new("no-such-file") }.should raise_error(Errno::ENOENT)
76
76
  end
77
77
 
78
+ it "should raise type error if initialized with object that can not be directly converted to string" do
79
+ lambda{ Xattr.new(1) }.should raise_error(TypeError)
80
+ end
81
+
82
+ class SuperPath
83
+ def initialize(path)
84
+ @path = path
85
+ end
86
+
87
+ def to_str
88
+ @path.dup
89
+ end
90
+ end
91
+
92
+ it "should work with object that can be directly converted to string" do
93
+ super_path = SuperPath.new(path)
94
+ Xattr.new(super_path).set('user.foo', 'bar')
95
+ Xattr.new(super_path).get('user.foo').should == 'bar'
96
+ end
97
+
78
98
  describe "respecting :no_follow option" do
79
99
  let(:link) { "link.txt" }
80
100
  let(:xattr_f) { Xattr.new(link, :no_follow => false) }
metadata CHANGED
@@ -1,77 +1,64 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: ffi-xattr
3
- version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 4
10
- version: 0.0.4
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Jari Bakken
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2011-11-15 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- type: :runtime
22
- requirement: &id001 !ruby/object:Gem::Requirement
23
- none: false
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- hash: 3
28
- segments:
29
- - 0
30
- version: "0"
31
- prerelease: false
11
+ date: 2013-12-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
32
14
  name: ffi
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- type: :development
36
- requirement: &id002 !ruby/object:Gem::Requirement
37
- none: false
38
- requirements:
39
- - - ~>
40
- - !ruby/object:Gem::Version
41
- hash: 9
42
- segments:
43
- - 2
44
- - 5
45
- version: "2.5"
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
46
21
  prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
47
28
  name: rspec
48
- version_requirements: *id002
49
- - !ruby/object:Gem::Dependency
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '2.5'
50
34
  type: :development
51
- requirement: &id003 !ruby/object:Gem::Requirement
52
- none: false
53
- requirements:
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
54
38
  - - ~>
55
- - !ruby/object:Gem::Version
56
- hash: 63
57
- segments:
58
- - 0
59
- - 9
60
- - 2
39
+ - !ruby/object:Gem::Version
40
+ version: '2.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
61
47
  version: 0.9.2
48
+ type: :development
62
49
  prerelease: false
63
- name: rake
64
- version_requirements: *id003
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.9.2
65
55
  description: Manipulate extended file attributes
66
- email:
56
+ email:
67
57
  - jari.bakken@gmail.com
68
58
  executables: []
69
-
70
59
  extensions: []
71
-
72
60
  extra_rdoc_files: []
73
-
74
- files:
61
+ files:
75
62
  - .gitignore
76
63
  - .travis.yml
77
64
  - Gemfile
@@ -84,39 +71,31 @@ files:
84
71
  - lib/ffi-xattr/error.rb
85
72
  - lib/ffi-xattr/linux_lib.rb
86
73
  - lib/ffi-xattr/version.rb
74
+ - lib/ffi-xattr/windows_lib.rb
87
75
  - spec/xattr_spec.rb
88
76
  homepage: http://github.com/jarib/ffi-xattr
89
77
  licenses: []
90
-
78
+ metadata: {}
91
79
  post_install_message:
92
80
  rdoc_options: []
93
-
94
- require_paths:
81
+ require_paths:
95
82
  - lib
96
- required_ruby_version: !ruby/object:Gem::Requirement
97
- none: false
98
- requirements:
99
- - - ">="
100
- - !ruby/object:Gem::Version
101
- hash: 3
102
- segments:
103
- - 0
104
- version: "0"
105
- required_rubygems_version: !ruby/object:Gem::Requirement
106
- none: false
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- hash: 3
111
- segments:
112
- - 0
113
- version: "0"
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
114
93
  requirements: []
115
-
116
94
  rubyforge_project: ffi-xattr
117
- rubygems_version: 1.8.10
95
+ rubygems_version: 2.1.10
118
96
  signing_key:
119
- specification_version: 3
97
+ specification_version: 4
120
98
  summary: Manipulate extended file attributes
121
- test_files:
99
+ test_files:
122
100
  - spec/xattr_spec.rb
101
+ has_rdoc: