class OSX::ACL

Constants

VERSION

Attributes

entries[RW]
path[RW]

Public Class Methods

of(path) click to toggle source
# File lib/acl.rb, line 23
def self.of(path)
  new.tap {|acl| acl.path = path }
end

Public Instance Methods

api() click to toggle source
# File lib/acl.rb, line 131
def api
  API
end
entry_lines() click to toggle source
# File lib/acl.rb, line 63
def entry_lines
  file_descriptor, acl_text_ptr, acl_ptr = nil
  begin
    file_descriptor = File.open(path, "r")
  rescue Errno::ELOOP
    return []
  rescue Errno::EOPNOTSUPP
    return []
  rescue Errno::ENOENT
    return []
  end
  acl_ptr = api.acl_get_fd(file_descriptor.fileno)
  acl_text_ptr = api.acl_to_text(acl_ptr, nil)
  return [] if acl_text_ptr.null?
  ace_lines = acl_text_ptr.read_string.split("\n")[1..-1]
  ace_lines
ensure
  api.acl_free(acl_text_ptr)
  api.acl_free(acl_ptr)
  file_descriptor.close if file_descriptor
end
file_flags() click to toggle source
# File lib/acl.rb, line 93
def file_flags
  flags = ""
  Open3.popen3("stat", "-f", "%f", path) do |stdin,stdout,stderr,thread|
    flags = stdout.read
  end
  flags.to_i.to_s(8)
end
make_entries() click to toggle source
# File lib/acl.rb, line 31
def make_entries
  Entries.new(self, entry_lines.map {|line| ACL::Entry.from_text(line) })
end
orphans() click to toggle source
# File lib/acl.rb, line 89
def orphans
  entries.select {|e| e.orphaned? }
end
preserving_flags() { || ... } click to toggle source

Wraps a file action

first removes file flags that would cause the action to fail
then yields to the block to perform the action
then restores the flags
# File lib/acl.rb, line 105
def preserving_flags
  original_file_flags = file_flags
  if original_file_flags == "0"
    yield
  else
    begin
      system("chflags", "0", path)
      yield
    ensure
      system("chflags", original_file_flags, path)
    end
  end
end
remove_entry_at_index(index) click to toggle source
# File lib/acl.rb, line 119
def remove_entry_at_index(index)
  args = ["chmod", "-a#", index.to_s, path]
  puts "#{args[0]} #{args[1]} #{args[2]} #{Shellwords.escape(args[3])} # #{entries[index].to_s}"
  if ENV['OSX_ACL_NOOP'] == "yes"
    true
  else
    preserving_flags do
      system(*args)
    end
  end
end
remove_orphans!() click to toggle source
# File lib/acl.rb, line 85
def remove_orphans!
  entries.remove_if {|entry| entry.orphaned? }
end