Giter Club home page Giter Club logo

ffi-xattr's Introduction

Looking for new maintainer

ffi-xattr

Ruby library to manage extended file attributes.

Example

  xattr = Xattr.new("/path/to/file")
  xattr['user.foo'] = 'bar'

  xattr['user.foo'] #=> 'bar'
  xattr.list        #=> ["user.foo"]

  xattr.each { |key, value| ... }
  xattr.as_json     #=> {"user.foo" => "bar"}

Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so I don't break it in a future version unintentionally.
  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
  • Send me a pull request. Bonus points for topic branches.

Copyright

Copyright 2011-2014 Jari Bakken

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

ffi-xattr's People

Contributors

comomac avatar jarib avatar lwoggardner avatar smortex avatar toy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ffi-xattr's Issues

Add support for f*xattr

Currently, the gem supports listxattr, getxattr, setxattr and removexattr for manipulating extended attributes on files, and l*xattr for manipulating symbolic links. However, on my platform there's also the function family f*xattr, to manipulate extended attributes on file descriptors.

targetsetlistgetremove
file setxattr listxattr getxattr removexattr
symbolic link lsetxattr llistxattr lgetxattr lremovexattr
file descriptor fsetxattr flistxattr fgetxattr fremovexattr

I tried to create a patch, but didn't get it to work because I don't know enough about ffi. I'll try to append a patch file to this issue, so you can see what I'm trying to achieve.

Error on requiring ffi-xattr on FreeBSD

If you try to require ffi-xattr on FreeBSD 10/ ruby 1.9.3 you get:

LoadError: Could not open library 'c': Shared object "c" not found, required by "ruby19".
Could not open library 'libc.so': /usr/lib/libc.so: invalid file format
    from /usr/local/lib/ruby/gems/1.9/gems/ffi-1.9.3/lib/ffi/library.rb:133:in `block in ffi_lib'
    from /usr/local/lib/ruby/gems/1.9/gems/ffi-1.9.3/lib/ffi/library.rb:100:in `map'
    from /usr/local/lib/ruby/gems/1.9/gems/ffi-1.9.3/lib/ffi/library.rb:100:in `ffi_lib'
    from /usr/local/lib/ruby/gems/1.9/gems/ffi-xattr-0.1.2/lib/ffi-xattr/error.rb:5:in `<module:Error>'
    from /usr/local/lib/ruby/gems/1.9/gems/ffi-xattr-0.1.2/lib/ffi-xattr/error.rb:2:in `<class:Xattr>'
    from /usr/local/lib/ruby/gems/1.9/gems/ffi-xattr-0.1.2/lib/ffi-xattr/error.rb:1:in `<top (required)>'
    from /usr/local/lib/ruby/site_ruby/1.9/rubygems/custom_require.rb:36:in `require'
    from /usr/local/lib/ruby/site_ruby/1.9/rubygems/custom_require.rb:36:in `require'
    from /usr/local/lib/ruby/gems/1.9/gems/ffi-xattr-0.1.2/lib/ffi-xattr.rb:3:in `<top (required)>'
    from /usr/local/lib/ruby/site_ruby/1.9/rubygems/custom_require.rb:60:in `require'
    from /usr/local/lib/ruby/site_ruby/1.9/rubygems/custom_require.rb:60:in `rescue in require'
    from /usr/local/lib/ruby/site_ruby/1.9/rubygems/custom_require.rb:35:in `require'

I've looked into it and it seems the line ffi_lib "c" in lib/ffi-xattr//error.rb causes this problem. Unfortunatelly I am not familiar with ffi and have no idea what this does - or how to fix it.

a #to_hash and #to_h method would be nice

It would be great to implement a #to_hash and #to_h method. This should then be used by #as_json (or you can remove #as_json because all JSON libraries using an existing #to_hash method to create the dump…). Other gems also use objects which respond to #to_hash

Suggestion

def to_hash
  ret= {}
  each{ |k,v| ret.store(k, v) }
  ret
end
alias_method :to_h, :to_hash

def as_json(*_args)
  to_hash
end

Corrupt attribute values

Hello Jari,

getxattr does not return a NULL terminated string, which sometimes leads to corrupted attribute values being returned by str_ptr.read_string. Changing the calls to the following should fix this and also avoid a potential race condition between getting the size and the value:

   str_ptr = FFI::MemoryPointer.new(:char, size)
   size = send(method, path, key, str_ptr, size)
   str_ptr.read_string(size)

Support Pathname use with Xattr

I see issue #3 mentions mking Xattr work with Pathname, but it is implemented by calling "to_str" on the argument passed to Xattr#initialize

From what I've read #to_str is meant to describe objects that behave exactly like a string, and the only thing that implements it is String itself, so passing a Pathname doesn't actually work.

Pathname implements #to_s to return the underlying path as a String.

However, before I submit a pull request for this I'm wondering whether the alternative should be to provide an "ffi-xattr/extras" library that would extend Pathname (and File) with "xattr" methods so they could be used in a more natural way.

eg

require 'ffi-xattr/extras'

p = Pathname.new("/path/to/file")

puts p.xattr.list
puts p.parent.xattr.list

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.