| 1 | package Sys::Config::Manage::Remove; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use File::Basename; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use base 'Error::Helper'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use String::ShellQuote; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use File::Spec; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use File::Path qw(remove_tree); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use String::ShellQuote; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | =head1 NAME | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | Sys::Config::Manage::Remove - Removes no longer desired files and/or directories. | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =head1 VERSION | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | Version 0.0.1 | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | =cut | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 2 | our $VERSION = '0.0.1'; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | use Sys::Config::Manage::Remove; | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | my $foo = Sys::Config::Manage::Remove->new(); | ||||||||||||||||||||||||||||
| 30 | ... | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | =head1 METHODS | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | =head2 new | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | =head3 args hash | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | =head4 scm | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | This is a initialized Sys::Config::Manage object. | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | $foo=Sys::Config::Manage::Remove->new(\%args); | ||||||||||||||||||||||||||||
| 43 | if($foo->error){ | ||||||||||||||||||||||||||||
| 44 | warn('error:'.$foo->error.': '.$foo->errorString); | ||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | =cut | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | sub new{ | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 50 | 0 | my %args; | |||||||||||||||||||||||||||
| 51 | 0 | ▶ | if(defined($_[1])){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 0 | %args= %{$_[1]}; | |||||||||||||||||||||||||||
| 53 | }; | ||||||||||||||||||||||||||||
| 54 | 0 | my $method='new'; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | my $self = { | |||||||||||||||||||||||||||
| 57 | module=>'Sys-Config-Manage-Scripts', | ||||||||||||||||||||||||||||
| 58 | perror=>undef, | ||||||||||||||||||||||||||||
| 59 | error=>undef, | ||||||||||||||||||||||||||||
| 60 | errorString=>"", | ||||||||||||||||||||||||||||
| 61 | }; | ||||||||||||||||||||||||||||
| 62 | 0 | bless $self; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | #make sure we have a Sys::Config::Manage | ||||||||||||||||||||||||||||
| 65 | 0 | ▶ | if(!defined( $args{scm} ) ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 0 | $self->{perror}=1; | |||||||||||||||||||||||||||
| 67 | 0 | $self->{error}=1; | |||||||||||||||||||||||||||
| 68 | 0 | $self->{errorString}='Nothing passed for the Sys::Config::Manage object'; | |||||||||||||||||||||||||||
| 69 | 0 | $self->warn; | |||||||||||||||||||||||||||
| 70 | 0 | return $self; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | #make sure that it is really a Sys::Config::Manage object | ||||||||||||||||||||||||||||
| 74 | 0 | ▶ | if( ref( $args{scm} ) ne "Sys::Config::Manage" ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 0 | $self->{perror}=1; | |||||||||||||||||||||||||||
| 76 | 0 | $self->{error}=2; | |||||||||||||||||||||||||||
| 77 | 0 | $self->{errorString}='$args{scm} is not a Sys::Config::Manage object'; | |||||||||||||||||||||||||||
| 78 | 0 | $self->warn; | |||||||||||||||||||||||||||
| 79 | 0 | return $self; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | $self->{scm}=$args{scm}; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | return $self; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | =head2 add | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | This adds a directory or file to be removed. | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | $foo->add( $configDir, $somethingToAdd ); | ||||||||||||||||||||||||||||
| 92 | if ( $foo->error ){ | ||||||||||||||||||||||||||||
| 93 | warn('Error:'.$foo->error.': '.$foo->errorString); | ||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | =cut | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 0 | ▶ | sub add{ | ||||||||||||||||||||||||||
|
Subroutine
add: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||
| 99 | 0 | my $self=$_[0]; | |||||||||||||||||||||||||||
| 100 | 0 | my $configDir=$_[1]; | |||||||||||||||||||||||||||
| 101 | 0 | my $item=$_[2]; | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | #blank any previous errors | ||||||||||||||||||||||||||||
| 104 | 0 | ▶ | if (!$self->errorblank) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 0 | return undef; | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | #make sure we have a directory to use | ||||||||||||||||||||||||||||
| 109 | 0 | ▶ | if (!defined($configDir)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 0 | $configDir=$self->{scm}->selectConfigDir; | |||||||||||||||||||||||||||
| 111 | 0 | ▶ | if ($self->{scm}->error) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 0 | $self->{error}=5; | |||||||||||||||||||||||||||
| 113 | $self->{errorString}='Sys::Config::Manage->selectConfigDir errored error="'. | ||||||||||||||||||||||||||||
| 114 | 0 | $self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"'; | |||||||||||||||||||||||||||
| 115 | 0 | $self->warn; | |||||||||||||||||||||||||||
| 116 | 0 | return undef; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | # make sure something is specified | ||||||||||||||||||||||||||||
| 121 | 0 | ▶ | if ( ! defined( $item ) ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | 0 | $self->{error}=3; | |||||||||||||||||||||||||||
| 123 | 0 | $self->{errorString}='No item that should be removed defined'; | |||||||||||||||||||||||||||
| 124 | 0 | $self->warn; | |||||||||||||||||||||||||||
| 125 | 0 | return undef; | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | # make sure it starts with a / or contain \n | ||||||||||||||||||||||||||||
| 129 | 0 | ▶ | if ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $item =~ m[^/] or $item =~ /\n/
MC/DC0%0/2
not $item =~ m[^/] or $item =~ /\n/
not $item =~ m[^/]
$item =~ /\n/
Truth table0%0/3
not(A) or B
A= not $item =~ m[^/]B= $item =~ /\n/
| |||||||||||||||||||||||||||||
| 130 | ( $item !~ /^\// ) || | ||||||||||||||||||||||||||||
| 131 | ( $item =~ /\n/ ) | ||||||||||||||||||||||||||||
| 132 | ){ | ||||||||||||||||||||||||||||
| 133 | 0 | $self->{error}=4; | |||||||||||||||||||||||||||
| 134 | 0 | $self->{errorString}='The path,"'.$item.'", does not appear to be a valid path'; | |||||||||||||||||||||||||||
| 135 | 0 | $self->warn; | |||||||||||||||||||||||||||
| 136 | 0 | return undef; | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 0 | $item=File::Spec->canonpath( $item ); | |||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 0 | my $exists=$self->exists( $configDir, $item ); | |||||||||||||||||||||||||||
| 142 | 0 | ▶ | if ( $self->error ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | 0 | $self->warnString('Failed to check if it already exists'); | |||||||||||||||||||||||||||
| 144 | 0 | return undef; | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | 0 | ▶ | if ( $exists ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 147 | 0 | $self->{error}=10; | |||||||||||||||||||||||||||
| 148 | 0 | $self->{errorString}='"'.$item.'" already exists'; | |||||||||||||||||||||||||||
| 149 | 0 | $self->warn; | |||||||||||||||||||||||||||
| 150 | 0 | return undef; | |||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 0 | my @list=$self->list( $configDir ); | |||||||||||||||||||||||||||
| 154 | 0 | ▶ | if ( $self->error ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 155 | 0 | $self->warnString('Failed to fetch the list for "'.$configDir.'"'); | |||||||||||||||||||||||||||
| 156 | 0 | return undef; | |||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | #add it to the list | ||||||||||||||||||||||||||||
| 160 | 0 | push( @list, $item ); | |||||||||||||||||||||||||||
| 161 | 0 | @list=sort( @list ); | |||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | #saves it | ||||||||||||||||||||||||||||
| 164 | 0 | $self->save( $configDir, \@list ); | |||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 0 | return 1; | |||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | =head2 clean | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | This removes everything in the remove list for a specified | ||||||||||||||||||||||||||||
| 172 | configuration directory. | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | There is one argument taken and that is the configuration | ||||||||||||||||||||||||||||
| 175 | directory. If it is not specified, it will be automatically | ||||||||||||||||||||||||||||
| 176 | choosen. | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | $foo->clean( $configDir ); | ||||||||||||||||||||||||||||
| 179 | if ( $foo->error ){ | ||||||||||||||||||||||||||||
| 180 | warn('Error:'.$foo->error.': '.$foo->errorString); | ||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | =cut | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | 0 | ▶ | sub clean{ | ||||||||||||||||||||||||||
|
Subroutine
clean: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||
| 186 | 0 | my $self=$_[0]; | |||||||||||||||||||||||||||
| 187 | 0 | my $configDir=$_[1]; | |||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | #blank any previous errors | ||||||||||||||||||||||||||||
| 190 | 0 | ▶ | if (!$self->errorblank) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 191 | 0 | return undef; | |||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | #make sure we have a directory to use | ||||||||||||||||||||||||||||
| 195 | 0 | ▶ | if (!defined($configDir)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 196 | 0 | $configDir=$self->{scm}->selectConfigDir; | |||||||||||||||||||||||||||
| 197 | 0 | ▶ | if ($self->{scm}->error) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 198 | 0 | $self->{error}=5; | |||||||||||||||||||||||||||
| 199 | $self->{errorString}='Sys::Config::Manage->selectConfigDir errored error="'. | ||||||||||||||||||||||||||||
| 200 | 0 | $self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"'; | |||||||||||||||||||||||||||
| 201 | 0 | $self->warn; | |||||||||||||||||||||||||||
| 202 | 0 | return undef; | |||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | #gets the list | ||||||||||||||||||||||||||||
| 207 | 0 | my @list=$self->list; | |||||||||||||||||||||||||||
| 208 | 0 | ▶ | if ( $self->error ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 209 | 0 | $self->warnString('Failed to get the remove list for "'.$configDir.'"'); | |||||||||||||||||||||||||||
| 210 | 0 | return undef; | |||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | 0 | my $int=0; | |||||||||||||||||||||||||||
| 214 | 0 | ▶ | while( defined( $list[$int] ) ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 215 | 0 | ▶ | if ( -d $list[$int] ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 216 | 0 | remove_tree( $list[$int], { error=>\my $err } ); | |||||||||||||||||||||||||||
| 217 | 0 | ▶ | if (@$err) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 218 | 0 | $self->{error}=11; | |||||||||||||||||||||||||||
| 219 | 0 | $self->{errorString}='Failed to remove the file "'.$list[$int].'"'; | |||||||||||||||||||||||||||
| 220 | 0 | $self->warn; | |||||||||||||||||||||||||||
| 221 | 0 | return undef; | |||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||
| 224 | 0 | ▶ | if ( -f $list[$int] ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 225 | 0 | ▶ | if ( ! unlink( $list[$int] ) ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 226 | 0 | $self->{error}=11; | |||||||||||||||||||||||||||
| 227 | 0 | $self->{errorString}='Failed to remove the file "'.$list[$int].'"'; | |||||||||||||||||||||||||||
| 228 | 0 | $self->warn; | |||||||||||||||||||||||||||
| 229 | 0 | return undef; | |||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | 0 | $int++; | |||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | 0 | return 1; | |||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | =head2 exists | ||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | This check if a path already exists in the list or not. | ||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | Two arguments are taken. The first is the configuration | ||||||||||||||||||||||||||||
| 244 | directory, which is automatically choosen if not specified. | ||||||||||||||||||||||||||||
| 245 | The second is the path to check for. | ||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | The returned value is a boolean. | ||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | my $exists=$foo->exists( $configDir, $path ); | ||||||||||||||||||||||||||||
| 250 | if ( $foo->error ){ | ||||||||||||||||||||||||||||
| 251 | warn('Error:'.$foo->error.': '.$foo->errorString); | ||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | =cut | ||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | 0 | ▶ | sub exists{ | ||||||||||||||||||||||||||
|
Subroutine
exists: not called CC=13 SCAR=52.0
Pod
documented
| |||||||||||||||||||||||||||||
| 257 | 0 | my $self=$_[0]; | |||||||||||||||||||||||||||
| 258 | 0 | my $configDir=$_[1]; | |||||||||||||||||||||||||||
| 259 | 0 | my $item=$_[2]; | |||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | #blank any previous errors | ||||||||||||||||||||||||||||
| 262 | 0 | ▶ | if (!$self->errorblank) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 263 | 0 | return undef; | |||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | # make sure something is specified | ||||||||||||||||||||||||||||
| 267 | 0 | ▶ | if ( ! defined( $item ) ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 268 | 0 | $self->{error}=3; | |||||||||||||||||||||||||||
| 269 | 0 | $self->{errorString}='No item that should be removed defined'; | |||||||||||||||||||||||||||
| 270 | 0 | $self->warn; | |||||||||||||||||||||||||||
| 271 | 0 | return undef; | |||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | # make sure it starts with a / or contain \n | ||||||||||||||||||||||||||||
| 275 | 0 | ▶ | if ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $item =~ m[^/] or $item =~ /\n/
MC/DC0%0/2
not $item =~ m[^/] or $item =~ /\n/
not $item =~ m[^/]
$item =~ /\n/
Truth table0%0/3
not(A) or B
A= not $item =~ m[^/]B= $item =~ /\n/
| |||||||||||||||||||||||||||||
| 276 | ( $item !~ /^\// ) || | ||||||||||||||||||||||||||||
| 277 | ( $item =~ /\n/ ) | ||||||||||||||||||||||||||||
| 278 | ){ | ||||||||||||||||||||||||||||
| 279 | 0 | $self->{error}=4; | |||||||||||||||||||||||||||
| 280 | 0 | $self->{errorString}='The path,"'.$item.'", does not appear to be a valid path'; | |||||||||||||||||||||||||||
| 281 | 0 | $self->warn; | |||||||||||||||||||||||||||
| 282 | 0 | return undef; | |||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | #make sure we have a directory to use | ||||||||||||||||||||||||||||
| 286 | 0 | ▶ | if (!defined($configDir)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 287 | 0 | $configDir=$self->{scm}->selectConfigDir; | |||||||||||||||||||||||||||
| 288 | 0 | ▶ | if ($self->{scm}->error) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 289 | 0 | $self->{error}=5; | |||||||||||||||||||||||||||
| 290 | $self->{errorString}='Sys::Config::Manage->selectConfigDir errored error="'. | ||||||||||||||||||||||||||||
| 291 | 0 | $self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"'; | |||||||||||||||||||||||||||
| 292 | 0 | $self->warn; | |||||||||||||||||||||||||||
| 293 | 0 | return undef; | |||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | #make sure the config directory is valid | ||||||||||||||||||||||||||||
| 298 | 0 | my $valid=$self->{scm}->validConfigDirName($configDir); | |||||||||||||||||||||||||||
| 299 | 0 | ▶ | if ($self->{scm}->error) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 300 | 0 | $self->{error}=7; | |||||||||||||||||||||||||||
| 301 | $self->{errorString}='Sys::Config::Manage->validConfigDirName errored error="'. | ||||||||||||||||||||||||||||
| 302 | 0 | $self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"'; | |||||||||||||||||||||||||||
| 303 | 0 | $self->warn; | |||||||||||||||||||||||||||
| 304 | 0 | return undef; | |||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||
| 306 | 0 | ▶ | if (defined( $valid )) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 307 | 0 | $self->{error}=8; | |||||||||||||||||||||||||||
| 308 | 0 | $self->{errorString}='The configuration directory name '.$valid; | |||||||||||||||||||||||||||
| 309 | 0 | $self->warn; | |||||||||||||||||||||||||||
| 310 | 0 | return undef; | |||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||
| 313 | #makes sure it exists | ||||||||||||||||||||||||||||
| 314 | 0 | ▶ | if ( ! -d $self->{scm}->{baseDir}.'/'.$configDir ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 315 | 0 | $self->{error}=9; | |||||||||||||||||||||||||||
| 316 | 0 | $self->{errorString}='The configuration directory, "'.$self->{baseDir}.'/'.$configDir.'", does not exist'; | |||||||||||||||||||||||||||
| 317 | 0 | $self->warn; | |||||||||||||||||||||||||||
| 318 | 0 | return undef; | |||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||
| 321 | 0 | $item=File::Spec->canonpath( $item ); | |||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||
| 323 | 0 | my @list=$self->list( $configDir ); | |||||||||||||||||||||||||||
| 324 | 0 | ▶ | if ( $self->error ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 325 | 0 | $self->warnString('Failed to fetch the list for "'.$configDir.'"'); | |||||||||||||||||||||||||||
| 326 | 0 | return undef; | |||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||
| 329 | 0 | my $int=0; | |||||||||||||||||||||||||||
| 330 | 0 | ▶ | while( defined( $list[$int] ) ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 331 | 0 | ▶ | if ( $list[$int] eq $item ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 332 | 0 | return 1; | |||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||
| 335 | 0 | $int++; | |||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||
| 338 | 0 | return 0; | |||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||
| 341 | =head2 list | ||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||
| 343 | This returns the list of the paths to remove. | ||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||
| 345 | One argument is taken and that is the configuration directory to | ||||||||||||||||||||||||||||
| 346 | us. If not specified, it is automatically selected. | ||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||
| 348 | my @removePaths=$foo->list( $configDir ); | ||||||||||||||||||||||||||||
| 349 | if ( $foo->error ){ | ||||||||||||||||||||||||||||
| 350 | warn('Error:'.$foo->error.': '.$foo->errorString); | ||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||
| 353 | =cut | ||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||
| 355 | 0 | ▶ | sub list{ | ||||||||||||||||||||||||||
|
Subroutine
list: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||
| 356 | 0 | my $self=$_[0]; | |||||||||||||||||||||||||||
| 357 | 0 | my $configDir=$_[1]; | |||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||
| 359 | #blank any previous errors | ||||||||||||||||||||||||||||
| 360 | 0 | ▶ | if (!$self->errorblank) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 361 | 0 | return undef; | |||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||
| 364 | #make sure we have a directory to use | ||||||||||||||||||||||||||||
| 365 | 0 | ▶ | if (!defined($configDir)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 366 | 0 | $configDir=$self->{scm}->selectConfigDir; | |||||||||||||||||||||||||||
| 367 | 0 | ▶ | if ($self->{scm}->error) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 368 | 0 | $self->{error}=5; | |||||||||||||||||||||||||||
| 369 | $self->{errorString}='Sys::Config::Manage->selectConfigDir errored error="'. | ||||||||||||||||||||||||||||
| 370 | 0 | $self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"'; | |||||||||||||||||||||||||||
| 371 | 0 | $self->warn; | |||||||||||||||||||||||||||
| 372 | 0 | return undef; | |||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||
| 376 | #make sure the config directory is valid | ||||||||||||||||||||||||||||
| 377 | 0 | my $valid=$self->{scm}->validConfigDirName($configDir); | |||||||||||||||||||||||||||
| 378 | 0 | ▶ | if ($self->{scm}->error) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 379 | 0 | $self->{error}=7; | |||||||||||||||||||||||||||
| 380 | $self->{errorString}='Sys::Config::Manage->validConfigDirName errored error="'. | ||||||||||||||||||||||||||||
| 381 | 0 | $self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"'; | |||||||||||||||||||||||||||
| 382 | 0 | $self->warn; | |||||||||||||||||||||||||||
| 383 | 0 | return undef; | |||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||
| 385 | 0 | ▶ | if (defined( $valid )) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 386 | 0 | $self->{error}=8; | |||||||||||||||||||||||||||
| 387 | 0 | $self->{errorString}='The configuration directory name '.$valid; | |||||||||||||||||||||||||||
| 388 | 0 | $self->warn; | |||||||||||||||||||||||||||
| 389 | 0 | return undef; | |||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||
| 392 | #makes sure it exists | ||||||||||||||||||||||||||||
| 393 | 0 | ▶ | if ( ! -d $self->{scm}->{baseDir}.'/'.$configDir ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 394 | 0 | $self->{error}=9; | |||||||||||||||||||||||||||
| 395 | 0 | $self->{errorString}='The configuration directory, "'.$self->{baseDir}.'/'.$configDir.'", does not exist'; | |||||||||||||||||||||||||||
| 396 | 0 | $self->warn; | |||||||||||||||||||||||||||
| 397 | 0 | return undef; | |||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||
| 400 | #reads it | ||||||||||||||||||||||||||||
| 401 | 0 | my @removelines; | |||||||||||||||||||||||||||
| 402 | 0 | my $removefile=$self->{scm}->{baseDir}.'/'.$configDir.'/.SysConfigManage/Remove/list'; | |||||||||||||||||||||||||||
| 403 | 0 | ▶ | if ( ! -f $removefile ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 404 | 0 | return @removelines; | |||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||
| 406 | 0 | my $fh; | |||||||||||||||||||||||||||
| 407 | 0 | ▶ | if ( ! open( $fh, '<', $removefile ) ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 408 | 0 | $self->{error}=6; | |||||||||||||||||||||||||||
| 409 | 0 | $self->{errorString}='Failed to open the remove file, "'.$removefile.'"'; | |||||||||||||||||||||||||||
| 410 | 0 | $self->warn; | |||||||||||||||||||||||||||
| 411 | 0 | return undef; | |||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||
| 413 | 0 | @removelines=<$fh>; | |||||||||||||||||||||||||||
| 414 | 0 | close( $fh ); | |||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||
| 416 | #chomp each line | ||||||||||||||||||||||||||||
| 417 | 0 | my $int=0; | |||||||||||||||||||||||||||
| 418 | 0 | ▶ | while ( defined( $removelines[$int] ) ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 419 | 0 | chomp( $removelines[$int] ); | |||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||
| 421 | 0 | $int++; | |||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||
| 424 | 0 | return @removelines; | |||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||
| 427 | =head2 remove | ||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||
| 429 | This removes the specified path from the remove list. | ||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||
| 431 | Two arguments are taken. The first is the configuration | ||||||||||||||||||||||||||||
| 432 | directory, which if not specified is automatically choosen. | ||||||||||||||||||||||||||||
| 433 | The second is the path to remove. | ||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||
| 435 | $foo->remove( $configDir, $path ); | ||||||||||||||||||||||||||||
| 436 | if ( $foo->error ){ | ||||||||||||||||||||||||||||
| 437 | warn('Error:'.$foo->error.': '.$foo->errorString); | ||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||
| 440 | =cut | ||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||
| 442 | 0 | ▶ | sub remove{ | ||||||||||||||||||||||||||
|
Subroutine
remove: not called CC=13 SCAR=52.0
Pod
documented
| |||||||||||||||||||||||||||||
| 443 | 0 | my $self=$_[0]; | |||||||||||||||||||||||||||
| 444 | 0 | my $configDir=$_[1]; | |||||||||||||||||||||||||||
| 445 | 0 | my $item=$_[2]; | |||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||
| 447 | #blank any previous errors | ||||||||||||||||||||||||||||
| 448 | 0 | ▶ | if (!$self->errorblank) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 449 | 0 | return undef; | |||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||
| 452 | #make sure we have a directory to use | ||||||||||||||||||||||||||||
| 453 | 0 | ▶ | if (!defined($configDir)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 454 | 0 | $configDir=$self->{scm}->selectConfigDir; | |||||||||||||||||||||||||||
| 455 | 0 | ▶ | if ($self->{scm}->error) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 456 | 0 | $self->{error}=5; | |||||||||||||||||||||||||||
| 457 | $self->{errorString}='Sys::Config::Manage->selectConfigDir errored error="'. | ||||||||||||||||||||||||||||
| 458 | 0 | $self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"'; | |||||||||||||||||||||||||||
| 459 | 0 | $self->warn; | |||||||||||||||||||||||||||
| 460 | 0 | return undef; | |||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||
| 464 | # make sure something is specified | ||||||||||||||||||||||||||||
| 465 | 0 | ▶ | if ( ! defined( $item ) ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 466 | 0 | $self->{error}=3; | |||||||||||||||||||||||||||
| 467 | 0 | $self->{errorString}='No item that should be removed defined'; | |||||||||||||||||||||||||||
| 468 | 0 | $self->warn; | |||||||||||||||||||||||||||
| 469 | 0 | return undef; | |||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||
| 472 | # make sure it starts with a / or contain \n | ||||||||||||||||||||||||||||
| 473 | 0 | ▶ | if ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $item =~ m[^/] or $item =~ /\n/
MC/DC0%0/2
not $item =~ m[^/] or $item =~ /\n/
not $item =~ m[^/]
$item =~ /\n/
Truth table0%0/3
not(A) or B
A= not $item =~ m[^/]B= $item =~ /\n/
| |||||||||||||||||||||||||||||
| 474 | ( $item !~ /^\// ) || | ||||||||||||||||||||||||||||
| 475 | ( $item =~ /\n/ ) | ||||||||||||||||||||||||||||
| 476 | ){ | ||||||||||||||||||||||||||||
| 477 | 0 | $self->{error}=4; | |||||||||||||||||||||||||||
| 478 | 0 | $self->{errorString}='The path,"'.$item.'", does not appear to be a valid path'; | |||||||||||||||||||||||||||
| 479 | 0 | $self->warn; | |||||||||||||||||||||||||||
| 480 | 0 | return undef; | |||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||
| 483 | 0 | $item=File::Spec->canonpath( $item ); | |||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||
| 485 | 0 | my $exists=$self->exists( $configDir, $item ); | |||||||||||||||||||||||||||
| 486 | 0 | ▶ | if ( $self->error ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 487 | 0 | $self->warnString('Failed to check if it already exists'); | |||||||||||||||||||||||||||
| 488 | 0 | return undef; | |||||||||||||||||||||||||||
| 489 | } | ||||||||||||||||||||||||||||
| 490 | 0 | ▶ | if ( ! $exists ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 491 | 0 | $self->{error}=13; | |||||||||||||||||||||||||||
| 492 | 0 | $self->{errorString}='"'.$item.'" the path does not exist'; | |||||||||||||||||||||||||||
| 493 | 0 | $self->warn; | |||||||||||||||||||||||||||
| 494 | 0 | return undef; | |||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||
| 497 | 0 | my @list=$self->list( $configDir ); | |||||||||||||||||||||||||||
| 498 | 0 | ▶ | if ( $self->error ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 499 | 0 | $self->warnString('Failed to fetch the list for "'.$configDir.'"'); | |||||||||||||||||||||||||||
| 500 | 0 | return undef; | |||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||
| 503 | 0 | my @newlist; | |||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||
| 505 | 0 | my $int=0; | |||||||||||||||||||||||||||
| 506 | 0 | ▶ | while ( defined( $list[$int] ) ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 507 | 0 | ▶ | if ( $list[$int] ne $item ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 508 | 0 | push( @newlist, $list[$int] ); | |||||||||||||||||||||||||||
| 509 | } | ||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||
| 511 | 0 | $int++; | |||||||||||||||||||||||||||
| 512 | } | ||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||
| 514 | 0 | $self->save( $configDir, \@newlist ); | |||||||||||||||||||||||||||
| 515 | 0 | ▶ | if ( $self->error ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 516 | 0 | $self->warnString( 'Failed to save the list' ); | |||||||||||||||||||||||||||
| 517 | 0 | return undef; | |||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||
| 520 | 0 | return 1; | |||||||||||||||||||||||||||
| 521 | } | ||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||
| 523 | =head2 save | ||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||
| 525 | This replaces the current remove list with another. | ||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||
| 527 | Two arguments are taken. The first is the configuration | ||||||||||||||||||||||||||||
| 528 | directory, which is automatically selected if not specified. | ||||||||||||||||||||||||||||
| 529 | The second is the list to replace it with. | ||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||
| 531 | $foo->save( $configDir, \@removeList ); | ||||||||||||||||||||||||||||
| 532 | if ( $foo->error ){ | ||||||||||||||||||||||||||||
| 533 | warn('Error:'.$foo->error.': '.$foo->errorString); | ||||||||||||||||||||||||||||
| 534 | } | ||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||
| 536 | =cut | ||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||
| 538 | 0 | ▶ | sub save{ | ||||||||||||||||||||||||||
|
Subroutine
save: not called CC=19 SCAR=59.4
Pod
documented
| |||||||||||||||||||||||||||||
| 539 | 0 | my $self=$_[0]; | |||||||||||||||||||||||||||
| 540 | 0 | my $configDir=$_[1]; | |||||||||||||||||||||||||||
| 541 | 0 | my @list; | |||||||||||||||||||||||||||
| 542 | 0 | ▶ | if(defined($_[2])){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 543 | 0 | @list= @{$_[2]}; | |||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||
| 546 | #blank any previous errors | ||||||||||||||||||||||||||||
| 547 | 0 | ▶ | if (!$self->errorblank) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 548 | 0 | return undef; | |||||||||||||||||||||||||||
| 549 | } | ||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||
| 551 | #make sure we have a directory to use | ||||||||||||||||||||||||||||
| 552 | 0 | ▶ | if (!defined($configDir)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 553 | 0 | $configDir=$self->{scm}->selectConfigDir; | |||||||||||||||||||||||||||
| 554 | 0 | ▶ | if ($self->{scm}->error) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 555 | 0 | $self->{error}=5; | |||||||||||||||||||||||||||
| 556 | $self->{errorString}='Sys::Config::Manage->selectConfigDir errored error="'. | ||||||||||||||||||||||||||||
| 557 | 0 | $self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"'; | |||||||||||||||||||||||||||
| 558 | 0 | $self->warn; | |||||||||||||||||||||||||||
| 559 | 0 | return undef; | |||||||||||||||||||||||||||
| 560 | } | ||||||||||||||||||||||||||||
| 561 | } | ||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||
| 563 | #make sure the config directory is valid | ||||||||||||||||||||||||||||
| 564 | 0 | my $valid=$self->{scm}->validConfigDirName($configDir); | |||||||||||||||||||||||||||
| 565 | 0 | ▶ | if ($self->{scm}->error) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 566 | 0 | $self->{error}=7; | |||||||||||||||||||||||||||
| 567 | $self->{errorString}='Sys::Config::Manage->validConfigDirName errored error="'. | ||||||||||||||||||||||||||||
| 568 | 0 | $self->{scm}->error.'" errorString="'.$self->{scm}->errorString.'"'; | |||||||||||||||||||||||||||
| 569 | 0 | $self->warn; | |||||||||||||||||||||||||||
| 570 | 0 | return undef; | |||||||||||||||||||||||||||
| 571 | } | ||||||||||||||||||||||||||||
| 572 | 0 | ▶ | if (defined( $valid )) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 573 | 0 | $self->{error}=8; | |||||||||||||||||||||||||||
| 574 | 0 | $self->{errorString}='The configuration directory name '.$valid; | |||||||||||||||||||||||||||
| 575 | 0 | $self->warn; | |||||||||||||||||||||||||||
| 576 | 0 | return undef; | |||||||||||||||||||||||||||
| 577 | } | ||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||
| 579 | 0 | my $towrite=''; | |||||||||||||||||||||||||||
| 580 | 0 | my $int=0; | |||||||||||||||||||||||||||
| 581 | 0 | ▶ | while( defined( $list[$int] ) ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||
| 583 | 0 | ▶ | if ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $list[$int] =~ m[^/] or $list[$int] =~ /\n/
MC/DC0%0/2
not $list[$int] =~ m[^/] or $list[$int] =~ /\n/
not $list[$int] =~ m[^/]
$list[$int] =~ /\n/
Truth table0%0/3
not(A) or B
A= not $list[$int] =~ m[^/]B= $list[$int] =~ /\n/
| |||||||||||||||||||||||||||||
| 584 | ($list[$int] !~ /^\// ) || | ||||||||||||||||||||||||||||
| 585 | ( $list[$int] =~ /\n/ ) | ||||||||||||||||||||||||||||
| 586 | ){ | ||||||||||||||||||||||||||||
| 587 | 0 | $self->{error}=4; | |||||||||||||||||||||||||||
| 588 | 0 | $self->{errorString}='The path, "'.$list[$int].'", does appear to be valid'; | |||||||||||||||||||||||||||
| 589 | 0 | $self->warn; | |||||||||||||||||||||||||||
| 590 | 0 | return undef; | |||||||||||||||||||||||||||
| 591 | } | ||||||||||||||||||||||||||||
| 592 | 0 | chomp($list[$int]); | |||||||||||||||||||||||||||
| 593 | 0 | $towrite=$towrite.$list[$int]."\n"; | |||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||
| 595 | 0 | $int++; | |||||||||||||||||||||||||||
| 596 | } | ||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||
| 598 | #makes sure the directory exists | ||||||||||||||||||||||||||||
| 599 | 0 | ▶ | if ( ! -d $self->{scm}->{baseDir}.'/'.$configDir.'/.SysConfigManage/' ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 600 | 0 | ▶ | if ( ! mkdir( $self->{scm}->{baseDir}.'/'.$configDir.'/.SysConfigManage/' ) ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 601 | 0 | $self->{error}=12; | |||||||||||||||||||||||||||
| 602 | 0 | $self->{errorString}='Failed to create "'.$self->{scm}->{baseDir}.'/'.$configDir.'/.SysConfigManage/"'; | |||||||||||||||||||||||||||
| 603 | 0 | $self->warn; | |||||||||||||||||||||||||||
| 604 | 0 | return undef; | |||||||||||||||||||||||||||
| 605 | } | ||||||||||||||||||||||||||||
| 606 | } | ||||||||||||||||||||||||||||
| 607 | 0 | ▶ | if ( ! -d $self->{scm}->{baseDir}.'/'.$configDir.'/.SysConfigManage/Remove' ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 608 | 0 | ▶ | if ( ! mkdir( $self->{scm}->{baseDir}.'/'.$configDir.'/.SysConfigManage/Remove/' ) ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 609 | 0 | $self->{error}=12; | |||||||||||||||||||||||||||
| 610 | 0 | $self->{errorString}='Failed to create "'.$self->{scm}->{baseDir}.'/'.$configDir.'/.SysConfigManage/Remove/"'; | |||||||||||||||||||||||||||
| 611 | 0 | $self->warn; | |||||||||||||||||||||||||||
| 612 | 0 | return undef; | |||||||||||||||||||||||||||
| 613 | } | ||||||||||||||||||||||||||||
| 614 | } | ||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||
| 616 | #saves it | ||||||||||||||||||||||||||||
| 617 | 0 | my $exists=0; | |||||||||||||||||||||||||||
| 618 | 0 | my $removefile=$self->{scm}->{baseDir}.'/'.$configDir.'/.SysConfigManage/Remove/list'; | |||||||||||||||||||||||||||
| 619 | 0 | ▶ | if ( -f $removefile ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 620 | 0 | $exists=1; | |||||||||||||||||||||||||||
| 621 | } | ||||||||||||||||||||||||||||
| 622 | 0 | my $fh; | |||||||||||||||||||||||||||
| 623 | 0 | ▶ | if ( ! open( $fh, '>', $removefile ) ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 624 | 0 | $self->{error}=6; | |||||||||||||||||||||||||||
| 625 | 0 | $self->{errorString}='Failed to open the remove file, "'.$removefile.'"'; | |||||||||||||||||||||||||||
| 626 | 0 | $self->warn; | |||||||||||||||||||||||||||
| 627 | 0 | return undef; | |||||||||||||||||||||||||||
| 628 | } | ||||||||||||||||||||||||||||
| 629 | 0 | print $fh $towrite; | |||||||||||||||||||||||||||
| 630 | 0 | close( $fh ); | |||||||||||||||||||||||||||
| 631 | |||||||||||||||||||||||||||||
| 632 | 0 | ▶ | if ( ! $exists ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 633 | 0 | my $command=$self->{scm}->getAddCommand; | |||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||
| 635 | 0 | ▶ | if ( defined( $command ) ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 636 | 0 | $removefile=shell_quote($removefile); | |||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||
| 638 | 0 | $command=~s/\%\%\%file\%\%\%/$removefile/g; | |||||||||||||||||||||||||||
| 639 | 0 | system($command); | |||||||||||||||||||||||||||
| 640 | 0 | my $exit = $?<<8; | |||||||||||||||||||||||||||
| 641 | 0 | ▶ | if ($exit ne '0') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 642 | 0 | $self->{error}=12; | |||||||||||||||||||||||||||
| 643 | 0 | $self->{errorString}='The add command failed. command="'.$command.'" exit="'.$exit.'"'; | |||||||||||||||||||||||||||
| 644 | 0 | $self->warn; | |||||||||||||||||||||||||||
| 645 | 0 | return undef; | |||||||||||||||||||||||||||
| 646 | } | ||||||||||||||||||||||||||||
| 647 | } | ||||||||||||||||||||||||||||
| 648 | } | ||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||
| 650 | 0 | return 1; | |||||||||||||||||||||||||||
| 651 | } | ||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||
| 653 | =head1 ERROR CODES | ||||||||||||||||||||||||||||
| 654 | |||||||||||||||||||||||||||||
| 655 | =head2 1 | ||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||
| 657 | Nothing passed for the Sys::Config::Manage object. | ||||||||||||||||||||||||||||
| 658 | |||||||||||||||||||||||||||||
| 659 | =head2 2 | ||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||
| 661 | $args{scm} is not a Sys::Config::Manage object. | ||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||
| 663 | =head2 3 | ||||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||
| 665 | No item that should be removed defined. | ||||||||||||||||||||||||||||
| 666 | |||||||||||||||||||||||||||||
| 667 | =head2 4 | ||||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||
| 669 | The path does not appear to be a valid path. This means it | ||||||||||||||||||||||||||||
| 670 | does not start with a "/" or contains a newline. | ||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||
| 672 | =head2 5 | ||||||||||||||||||||||||||||
| 673 | |||||||||||||||||||||||||||||
| 674 | Sys::Config::Manage->selectConfigDir errored. | ||||||||||||||||||||||||||||
| 675 | |||||||||||||||||||||||||||||
| 676 | =head2 6 | ||||||||||||||||||||||||||||
| 677 | |||||||||||||||||||||||||||||
| 678 | Failed to open the remove file. | ||||||||||||||||||||||||||||
| 679 | |||||||||||||||||||||||||||||
| 680 | =head2 7 | ||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||
| 682 | Sys::Config::Manage->validConfigDirName errored. | ||||||||||||||||||||||||||||
| 683 | |||||||||||||||||||||||||||||
| 684 | =head2 8 | ||||||||||||||||||||||||||||
| 685 | |||||||||||||||||||||||||||||
| 686 | Invalid configuration directory name. | ||||||||||||||||||||||||||||
| 687 | |||||||||||||||||||||||||||||
| 688 | =head2 9 | ||||||||||||||||||||||||||||
| 689 | |||||||||||||||||||||||||||||
| 690 | The configuration directory does not exist. | ||||||||||||||||||||||||||||
| 691 | |||||||||||||||||||||||||||||
| 692 | =head2 10 | ||||||||||||||||||||||||||||
| 693 | |||||||||||||||||||||||||||||
| 694 | It already exists. | ||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||
| 696 | =head2 11 | ||||||||||||||||||||||||||||
| 697 | |||||||||||||||||||||||||||||
| 698 | Failed to remove a file or path. | ||||||||||||||||||||||||||||
| 699 | |||||||||||||||||||||||||||||
| 700 | =head2 12 | ||||||||||||||||||||||||||||
| 701 | |||||||||||||||||||||||||||||
| 702 | Failed to add the new file. | ||||||||||||||||||||||||||||
| 703 | |||||||||||||||||||||||||||||
| 704 | =head2 13 | ||||||||||||||||||||||||||||
| 705 | |||||||||||||||||||||||||||||
| 706 | The path does not exist. | ||||||||||||||||||||||||||||
| 707 | |||||||||||||||||||||||||||||
| 708 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 709 | |||||||||||||||||||||||||||||
| 710 | Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >> | ||||||||||||||||||||||||||||
| 711 | |||||||||||||||||||||||||||||
| 712 | =head1 BUGS | ||||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||
| 714 | Please report any bugs or feature requests to C<bug-sys-config-manage-perms at rt.cpan.org>, or through | ||||||||||||||||||||||||||||
| 715 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Sys-Config-Manage-Perms>. I will be notified, and then you'll | ||||||||||||||||||||||||||||
| 716 | automatically be notified of progress on your bug as I make changes. | ||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||
| 718 | =head1 SUPPORT | ||||||||||||||||||||||||||||
| 719 | |||||||||||||||||||||||||||||
| 720 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||||||
| 721 | |||||||||||||||||||||||||||||
| 722 | perldoc Sys::Config::Manage::Perms | ||||||||||||||||||||||||||||
| 723 | |||||||||||||||||||||||||||||
| 724 | |||||||||||||||||||||||||||||
| 725 | You can also look for information at: | ||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||
| 727 | =over 4 | ||||||||||||||||||||||||||||
| 728 | |||||||||||||||||||||||||||||
| 729 | =item * RT: CPAN's request tracker | ||||||||||||||||||||||||||||
| 730 | |||||||||||||||||||||||||||||
| 731 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Sys-Config-Manage> | ||||||||||||||||||||||||||||
| 732 | |||||||||||||||||||||||||||||
| 733 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||||||||||||||||||||
| 734 | |||||||||||||||||||||||||||||
| 735 | L<http://annocpan.org/dist/Sys-Config-Manage> | ||||||||||||||||||||||||||||
| 736 | |||||||||||||||||||||||||||||
| 737 | =item * CPAN Ratings | ||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||
| 739 | L<http://cpanratings.perl.org/d/Sys-Config-Manage> | ||||||||||||||||||||||||||||
| 740 | |||||||||||||||||||||||||||||
| 741 | =item * Search CPAN | ||||||||||||||||||||||||||||
| 742 | |||||||||||||||||||||||||||||
| 743 | L<http://search.cpan.org/dist/Sys-Config-Manage/> | ||||||||||||||||||||||||||||
| 744 | |||||||||||||||||||||||||||||
| 745 | =back | ||||||||||||||||||||||||||||
| 746 | |||||||||||||||||||||||||||||
| 747 | |||||||||||||||||||||||||||||
| 748 | =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||||||||||||
| 749 | |||||||||||||||||||||||||||||
| 750 | |||||||||||||||||||||||||||||
| 751 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||
| 752 | |||||||||||||||||||||||||||||
| 753 | Copyright 2011 Zane C. Bowers-Hadley. | ||||||||||||||||||||||||||||
| 754 | |||||||||||||||||||||||||||||
| 755 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||
| 756 | under the terms of either: the GNU General Public License as published | ||||||||||||||||||||||||||||
| 757 | by the Free Software Foundation; or the Artistic License. | ||||||||||||||||||||||||||||
| 758 | |||||||||||||||||||||||||||||
| 759 | See http://dev.perl.org/licenses/ for more information. | ||||||||||||||||||||||||||||
| 760 | |||||||||||||||||||||||||||||
| 761 | |||||||||||||||||||||||||||||
| 762 | =cut | ||||||||||||||||||||||||||||
| 763 | |||||||||||||||||||||||||||||
| 764 | 2 | 1; # End of Sys::Config::Manage::Remove | |||||||||||||||||||||||||||