<commit_before>require 'open3'

module OodSupport
  module ACLs
    # Object describing an NFSv4 ACL
    class Nfs4ACL < ACL
      # The binary used to get the file ACLs
      GET_FACL_BIN = 'nfs4_getfacl'

      # The binary used to set the file ACLs
      SET_FACL_BIN = 'nfs4_setfacl'

      # Name of owner for this ACL
      # @return [String] owner name
      attr_reader :owner

      # Name of owning group for this ACL
      # @return [String] group name
      attr_reader :group

      # Get ACL from file path
      # @param path [String] path to file or directory
      # @raise [InvalidPath] file path doesn't exist
      # @raise [BadExitCode] the command line called exited with non-zero status
      # @return [Nfs4ACL] acl generated from path
      def self.get_facl(path:)
        path = Pathname.new path
        raise InvalidPath, "invalid path: #{path}" unless path.exist?
        stat = path.stat
        acl, err, s = Open3.capture3(GET_FACL_BIN, path.to_s)
        raise BadExitCode, err unless s.success?
        parse(acl, owner: User.new(stat.uid), group: Group.new(stat.gid))
      end

      # Add ACL to file path
      # @param path [String] path to file or directory
      # @param entry [Nfs4Entry] entry to add to file
      # @raise [InvalidPath] file path doesn't exist
      # @raise [BadExitCode] the command line called exited with non-zero status
      # @return [Nfs4ACL] new acl of path
      def self.add_facl(path:, entry:)
        path = Pathname.new path
        raise InvalidPath, "invalid path: #{path}" unless path.exist?
        _, err, s = Open3.capture3(SET_FACL_BIN, '-a', entry.to_s, path.to_s)
        raise BadExitCode, err unless s.success?
        get_facl(path: path)
      end

      # Remove ACL from file path
      # @param path [String] path to file or directory
      # @param entry [Nfs4Entry] entry to remove from file
      # @raise [InvalidPath] file path doesn't exist
      # @raise [BadExitCode] the command line called exited with non-zero status
      # @return [Nfs4ACL] new acl of path
      def self.rem_facl(path:, entry:)
        path = Pathname.new path
        raise InvalidPath, "invalid path: #{path}" unless path.exist?
        _, err, s = Open3.capture3(SET_FACL_BIN, '-x', entry.to_s, path.to_s)
        raise BadExitCode, err unless s.success?
        get_facl(path: path)
      end

      # Modify in-place an entry for file path
      # @param path [String] path to file or directory
      # @param entry [Nfs4Entry] entry to modify in-place in file
      # @param new_entry [Nfs4Entry] new entry to be replaced with
      # @raise [InvalidPath] file path doesn't exist
      # @raise [BadExitCode] the command line called exited with non-zero status
      # @return [Nfs4ACL] new acl of path
      def self.mod_facl(path:, entry:, new_entry:)
        path = Pathname.new path
        raise InvalidPath, "invalid path: #{path}" unless path.exist?
        _, err, s = Open3.capture3(SET_FACL_BIN, '-m', entry.to_s, new_entry.to_s, path.to_s)
        raise BadExitCode, err unless s.success?<commit_msg>better variable name<commit_after>require 'open3'

module OodSupport
  module ACLs
    # Object describing an NFSv4 ACL
    class Nfs4ACL < ACL
      # The binary used to get the file ACLs
      GET_FACL_BIN = 'nfs4_getfacl'

      # The binary used to set the file ACLs
      SET_FACL_BIN = 'nfs4_setfacl'

      # Name of owner for this ACL
      # @return [String] owner name
      attr_reader :owner

      # Name of owning group for this ACL
      # @return [String] group name
      attr_reader :group

      # Get ACL from file path
      # @param path [String] path to file or directory
      # @raise [InvalidPath] file path doesn't exist
      # @raise [BadExitCode] the command line called exited with non-zero status
      # @return [Nfs4ACL] acl generated from path
      def self.get_facl(path:)
        path = Pathname.new path
        raise InvalidPath, "invalid path: #{path}" unless path.exist?
        stat = path.stat
        acl, err, s = Open3.capture3(GET_FACL_BIN, path.to_s)
        raise BadExitCode, err unless s.success?
        parse(acl, owner: User.new(stat.uid), group: Group.new(stat.gid))
      end

      # Add ACL to file path
      # @param path [String] path to file or directory
      # @param entry [Nfs4Entry] entry to add to file
      # @raise [InvalidPath] file path doesn't exist
      # @raise [BadExitCode] the command line called exited with non-zero status
      # @return [Nfs4ACL] new acl of path
      def self.add_facl(path:, entry:)
        path = Pathname.new path
        raise InvalidPath, "invalid path: #{path}" unless path.exist?
        _, err, s = Open3.capture3(SET_FACL_BIN, '-a', entry.to_s, path.to_s)
        raise BadExitCode, err unless s.success?
        get_facl(path: path)
      end

      # Remove ACL from file path
      # @param path [String] path to file or directory
      # @param entry [Nfs4Entry] entry to remove from file
      # @raise [InvalidPath] file path doesn't exist
      # @raise [BadExitCode] the command line called exited with non-zero status
      # @return [Nfs4ACL] new acl of path
      def self.rem_facl(path:, entry:)
        path = Pathname.new path
        raise InvalidPath, "invalid path: #{path}" unless path.exist?
        _, err, s = Open3.capture3(SET_FACL_BIN, '-x', entry.to_s, path.to_s)
        raise BadExitCode, err unless s.success?
        get_facl(path: path)
      end

      # Modify in-place an entry for file path
      # @param path [String] path to file or directory
      # @param old_entry [Nfs4Entry] old entry to modify in-place in file
      # @param new_entry [Nfs4Entry] new entry to be replaced with
      # @raise [InvalidPath] file path doesn't exist
      # @raise [BadExitCode] the command line called exited with non-zero status
      # @return [Nfs4ACL] new acl of path
      def self.mod_facl(path:, old_entry:, new_entry:)
        path = Pathname.new path
        raise InvalidPath, "invalid path: #{path}" unless path.exist?
        _, err, s = Open3.capture3(SET_FACL_BIN, '-m', old_entry.to_s, new_entry.to_s, path.to_s)
        raise BadExitCode, err unless s.success?
{'fraction_non_alphanumeric': 0.08866677414154442, 'fraction_numerical': 0.006770917298081574, 'mean_word_length': 2.6153846153846154, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6585202', 'n_tokens_mistral': 1997, 'n_tokens_neox': 1931, 'n_words': 692}