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