require 'parser/protection.rb' require 'P4' # A class to hold the parsed protections table, and to apply those protections to the given filetree class Protections_Table attr_accessor :ft, :table, :groups # @param [P4] p4 Perforce API object # @param [Dir_Tree] ft The filetree object def initialize(p4, ft) @p4 = p4 @ft = ft @table = [] @groups = {:split_recs => [], :groups => [], :users => []} end # Add a protections record to @table # @param [String] split_record # @example ["", "pv", " 4 ", "db.protect", " 0 0 ", "*", " ", "*", " 31 0 ", "//..."] # @return [Protection] Technically not returned but just added to @table def add_protection_record(split_record) seq = split_record[4].strip.split(" ")[0].to_i is_group = split_record[4].strip.split(" ")[1].to_i user = split_record[5] host = split_record[7] perm = split_record[8].strip.split(" ")[0].to_i map_flag = split_record[8].strip.split(" ")[1].to_i depot_file = split_record[9] @table << Protection.new(seq, is_group, user, host, perm, map_flag, depot_file) end # Find all protections in @table that apply to the path param # @param [String] path A depot syntax path # @return [Array] Returns an array of protections, that apply to path def prots_applying_to_path(path) temp_map = P4::Map.new response = [] @table.each { |protection| temp_map.insert(protection.depot_file) if temp_map.includes?(path) response << protection end } return response end # Apply protections in @table to @ft # Protections are applied at the node before the first wildcard # For example "//depot/path/..." would be applied at node path def apply_protections_to_tree @table.each { |protection| apply_to = "//" split_path = protection.depot_file.split("/") split_path.each { |pathticle| if pathticle == "" next elsif pathticle =~ /(\.\.\.)|(\*)/ break else unless apply_to =~ /\/$/ apply_to << "/" apply_to << pathticle else apply_to << pathticle end end } @ft.apply_protection_to_tree(apply_to, protection) } end # Find all users and groups in @table # @return [Array] All users and groups def find_users_and_groups users_groups = [] @table.each { |entry| unless users_groups.include?([entry.user, entry.is_group]) users_groups << [entry.user, entry.is_group] end } return users_groups end def format_group_recs #@pv@ 8 @db.group@ @brett@ @g1@ 5 0 0 0 43200 0 #@pv@ 8 @db.group@ @g2@ @g1@ 2 0 0 0 43200 0 # user group | irrelavent # rec[3] rec[4] @groups[:split_recs].each {|split_rec| @users[:groups] << split_rec[4] @users[:users] << {:user => split_rec[3], :group => split_rec[4]} } end end