1#**************************************************************
2#
3#  Licensed to the Apache Software Foundation (ASF) under one
4#  or more contributor license agreements.  See the NOTICE file
5#  distributed with this work for additional information
6#  regarding copyright ownership.  The ASF licenses this file
7#  to you under the Apache License, Version 2.0 (the
8#  "License"); you may not use this file except in compliance
9#  with the License.  You may obtain a copy of the License at
10#
11#    http://www.apache.org/licenses/LICENSE-2.0
12#
13#  Unless required by applicable law or agreed to in writing,
14#  software distributed under the License is distributed on an
15#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16#  KIND, either express or implied.  See the License for the
17#  specific language governing permissions and limitations
18#  under the License.
19#
20#**************************************************************
21
22
23
24package par2script::undefine;
25
26use par2script::globals;
27
28##########################################################
29# Removing in the script all the gids, that are listed
30# in undefine scp files
31##########################################################
32
33sub undefine_gids
34{
35	my ($parfilecontent) = @_;
36
37	my $item;
38	foreach $item ( @par2script::globals::allitems )
39	{
40		my $unitem = "Un$item";
41
42		for ( my $i = 0; $i <= $#{$parfilecontent}; $i++ )
43		{
44			if ( ${$parfilecontent}[$i] =~ /^\s*$unitem\s*(\w+?)\s*$/ )
45			{
46				my $gid = $1;
47				delete($par2script::globals::definitions{$item}->{$gid});
48			}
49		}
50	}
51}
52
53##########################################################
54# Collecting all subdirectories of a specified directory
55##########################################################
56
57sub collect_children_dirs
58{
59	my ($gid, $collector) = @_;
60
61	my $diritem = "Directory";
62	my $parentkey = "ParentID";
63
64	if ( exists($par2script::globals::definitions{$diritem}) )
65	{
66		my $onedefinition;
67
68		foreach $onedefinition (keys %{$par2script::globals::definitions{$diritem}})
69		{
70			if ( $par2script::globals::definitions{$diritem}->{$onedefinition}->{$parentkey} eq $gid )
71			{
72				push(@{$collector}, $onedefinition);
73				collect_children_dirs($onedefinition, $collector);
74			}
75		}
76	}
77}
78
79##########################################################
80# Removing in the script complete profiles.
81# This includes the Profile and its ProfileItems.
82##########################################################
83
84sub remove_complete_item
85{
86	my ($item, $parfilecontent) = @_;
87
88	my $removeitem = "Remove$item";
89	my $dependentkey = "";
90	my $collect_children = 0;
91	my @gidcollector = ();
92	my @dependentitems = ();
93
94	if ( $item eq "Profile" )
95	{
96		@dependentitems = ("ProfileItem");
97		$dependentkey = "ProfileID";
98	}
99	elsif ( $item eq "Directory" )
100	{
101		@dependentitems = ("File", "Shortcut", "Unixlink");
102		$dependentkey = "Dir";
103		$collect_children = 1;
104	}
105
106	for ( my $i = 0; $i <= $#{$parfilecontent}; $i++ )
107	{
108		if ( ${$parfilecontent}[$i] =~ /^\s*$removeitem\s*(\w+?)\s*$/ )
109		{
110			my $onegid = $1;
111			push(@gidcollector, $onegid);
112			if ( $collect_children ) { collect_children_dirs($onegid, \@gidcollector); }
113
114			my $gid;
115			foreach $gid (@gidcollector)
116			{
117				delete($par2script::globals::definitions{$item}->{$gid});
118
119				# also deleting all dependent items, for example "ProfileItems" whose "ProfileID" is this "Profile"
120				my $depitem;
121				foreach $depitem ( @dependentitems )
122				{
123					if ( exists($par2script::globals::definitions{$depitem}) )
124					{
125						my $onedefinition;
126						foreach $onedefinition (keys %{$par2script::globals::definitions{$depitem}})
127						{
128							if ( $par2script::globals::definitions{$depitem}->{$onedefinition}->{$dependentkey} eq $gid )
129							{
130								delete($par2script::globals::definitions{$depitem}->{$onedefinition});
131							}
132						}
133					}
134				}
135			}
136		}
137	}
138}
139
1401;
141