Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / solenv / bin / modules / par2script / undefine.pm
blob43cbe2619322e32c5265f436ae50e6dc01400458
2 # This file is part of the LibreOffice project.
4 # This Source Code Form is subject to the terms of the Mozilla Public
5 # License, v. 2.0. If a copy of the MPL was not distributed with this
6 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 # This file incorporates work covered by the following license notice:
10 # Licensed to the Apache Software Foundation (ASF) under one or more
11 # contributor license agreements. See the NOTICE file distributed
12 # with this work for additional information regarding copyright
13 # ownership. The ASF licenses this file to you under the Apache
14 # License, Version 2.0 (the "License"); you may not use this file
15 # except in compliance with the License. You may obtain a copy of
16 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package par2script::undefine;
21 use par2script::globals;
23 ##########################################################
24 # Removing in the script all the gids, that are listed
25 # in undefine scp files
26 ##########################################################
28 sub undefine_gids
30 my ($parfilecontent) = @_;
32 my $item;
33 foreach $item ( @par2script::globals::allitems )
35 my $unitem = "Un$item";
37 for ( my $i = 0; $i <= $#{$parfilecontent}; $i++ )
39 if ( ${$parfilecontent}[$i] =~ /^\s*$unitem\s*(\w+?)\s*$/ )
41 my $gid = $1;
42 delete($par2script::globals::definitions{$item}->{$gid});
48 ##########################################################
49 # Collecting all subdirectories of a specified directory
50 ##########################################################
52 sub collect_children_dirs
54 my ($gid, $collector) = @_;
56 my $diritem = "Directory";
57 my $parentkey = "ParentID";
59 if ( exists($par2script::globals::definitions{$diritem}) )
61 my $onedefinition;
63 foreach $onedefinition (keys %{$par2script::globals::definitions{$diritem}})
65 if ( $par2script::globals::definitions{$diritem}->{$onedefinition}->{$parentkey} eq $gid )
67 push(@{$collector}, $onedefinition);
68 collect_children_dirs($onedefinition, $collector);
74 ##########################################################
75 # Removing in the script complete profiles.
76 # This includes the Profile and its ProfileItems.
77 ##########################################################
79 sub remove_complete_item
81 my ($item, $parfilecontent) = @_;
83 my $removeitem = "Remove$item";
84 my $dependentkey = "";
85 my $collect_children = 0;
86 my @gidcollector = ();
87 my @dependentitems = ();
89 if ( $item eq "Profile" )
91 @dependentitems = ("ProfileItem");
92 $dependentkey = "ProfileID";
94 elsif ( $item eq "Directory" )
96 @dependentitems = ("File", "Shortcut", "Unixlink");
97 $dependentkey = "Dir";
98 $collect_children = 1;
101 for ( my $i = 0; $i <= $#{$parfilecontent}; $i++ )
103 if ( ${$parfilecontent}[$i] =~ /^\s*$removeitem\s*(\w+?)\s*$/ )
105 my $onegid = $1;
106 push(@gidcollector, $onegid);
107 if ( $collect_children ) { collect_children_dirs($onegid, \@gidcollector); }
109 my $gid;
110 foreach $gid (@gidcollector)
112 delete($par2script::globals::definitions{$item}->{$gid});
114 # also deleting all dependent items, for example "ProfileItems" whose "ProfileID" is this "Profile"
115 my $depitem;
116 foreach $depitem ( @dependentitems )
118 if ( exists($par2script::globals::definitions{$depitem}) )
120 my $onedefinition;
121 foreach $onedefinition (keys %{$par2script::globals::definitions{$depitem}})
123 if ( $par2script::globals::definitions{$depitem}->{$onedefinition}->{$dependentkey} eq $gid )
125 delete($par2script::globals::definitions{$depitem}->{$onedefinition});