| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Enbld::Target::Symlink; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 2 |  |  | 2 |  | 12 | use strict; | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 87 |  | 
| 4 | 2 |  |  | 2 |  | 12 | use warnings; | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 67 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 2 |  |  | 2 |  | 10 | use File::Spec; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 52 |  | 
| 7 | 2 |  |  | 2 |  | 10 | use File::Path qw/make_path/; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 1639 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | require Enbld::Home; | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | # directory list for symbolic link | 
| 13 |  |  |  |  |  |  | our $dir_list = { | 
| 14 |  |  |  |  |  |  | 'bin' => { | 
| 15 |  |  |  |  |  |  | 'dir'   => 'bin', | 
| 16 |  |  |  |  |  |  | 'omit'  => undef, | 
| 17 |  |  |  |  |  |  | }, | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | 'sbin' => { | 
| 20 |  |  |  |  |  |  | 'dir'   => 'sbin', | 
| 21 |  |  |  |  |  |  | 'omit'  => undef, | 
| 22 |  |  |  |  |  |  | }, | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | 'lib' => { | 
| 25 |  |  |  |  |  |  | 'dir'   => 'lib', | 
| 26 |  |  |  |  |  |  | 'omit'  => [ 'pkgconfig', 'perl5' ], | 
| 27 |  |  |  |  |  |  | }, | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | 'pkgconfig' => { | 
| 30 |  |  |  |  |  |  | 'dir'   => File::Spec->catdir( 'lib', 'pkgconfig' ), | 
| 31 |  |  |  |  |  |  | 'omit'  => undef, | 
| 32 |  |  |  |  |  |  | }, | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | 'include'   => { | 
| 35 |  |  |  |  |  |  | 'dir'   => 'include', | 
| 36 |  |  |  |  |  |  | 'omit'  => undef, | 
| 37 |  |  |  |  |  |  | }, | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | 'script'    => { | 
| 40 |  |  |  |  |  |  | 'dir'   => 'script', | 
| 41 |  |  |  |  |  |  | 'omit'  => undef, | 
| 42 |  |  |  |  |  |  | }, | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | 'support-files' => { | 
| 45 |  |  |  |  |  |  | 'dir'   => 'support-files', | 
| 46 |  |  |  |  |  |  | 'omit'  => undef, | 
| 47 |  |  |  |  |  |  | }, | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | 'man-man1'      => { | 
| 50 |  |  |  |  |  |  | 'dir'   => File::Spec->catdir( 'man', 'man1' ), | 
| 51 |  |  |  |  |  |  | 'omit'  => undef, | 
| 52 |  |  |  |  |  |  | }, | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | 'man-man3'      => { | 
| 55 |  |  |  |  |  |  | 'dir'   => File::Spec->catdir( 'man', 'man3' ), | 
| 56 |  |  |  |  |  |  | 'omit'  => undef, | 
| 57 |  |  |  |  |  |  | }, | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | 'share-man1'      => { | 
| 60 |  |  |  |  |  |  | 'dir'   => File::Spec->catdir( 'share', 'man', 'man1' ), | 
| 61 |  |  |  |  |  |  | 'omit'  => undef, | 
| 62 |  |  |  |  |  |  | }, | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | 'share-man3'      => { | 
| 65 |  |  |  |  |  |  | 'dir'   => File::Spec->catdir( 'share', 'man', 'man3' ), | 
| 66 |  |  |  |  |  |  | 'omit'  => undef, | 
| 67 |  |  |  |  |  |  | }, | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | 'share'     => { | 
| 70 |  |  |  |  |  |  | 'dir'   => 'share', | 
| 71 |  |  |  |  |  |  | 'omit'  => [ 'emacs', 'info', 'man', 'doc', 'aclocal' ], | 
| 72 |  |  |  |  |  |  | }, | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | 'doc'       => { | 
| 75 |  |  |  |  |  |  | 'dir'   => File::Spec->catdir( 'share', 'doc' ), | 
| 76 |  |  |  |  |  |  | 'omit'  => undef, | 
| 77 |  |  |  |  |  |  | }, | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | 'site-lisp' => { | 
| 80 |  |  |  |  |  |  | 'dir'   => File::Spec->catdir( 'share', 'emacs', 'site-lisp' ), | 
| 81 |  |  |  |  |  |  | 'omit'  => undef, | 
| 82 |  |  |  |  |  |  | }, | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  | 'aclocal' => { | 
| 85 |  |  |  |  |  |  | 'dir'   => File::Spec->catdir( 'share', 'aclocal' ), | 
| 86 |  |  |  |  |  |  | 'omit'  => undef, | 
| 87 |  |  |  |  |  |  | }, | 
| 88 |  |  |  |  |  |  | }; | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  | sub delete_symlink { | 
| 91 | 28 |  |  | 28 | 0 | 168 | my ( $pkg, $old_depository ) = @_; | 
| 92 |  |  |  |  |  |  |  | 
| 93 | 28 |  |  |  |  | 77 | foreach my $dir ( sort keys %{ $dir_list } ) { | 
|  | 28 |  |  |  |  | 1304 |  | 
| 94 | 420 |  |  |  |  | 2406 | my $installed = File::Spec->catdir( | 
| 95 |  |  |  |  |  |  | Enbld::Home->home, | 
| 96 |  |  |  |  |  |  | $dir_list->{$dir}{dir} | 
| 97 |  |  |  |  |  |  | ); | 
| 98 |  |  |  |  |  |  |  | 
| 99 | 420 | 100 |  |  |  | 13317 | next unless ( -d $installed ); | 
| 100 |  |  |  |  |  |  |  | 
| 101 | 8 |  |  |  |  | 646 | opendir( my $dh, $installed ); | 
| 102 | 8 |  |  |  |  | 468 | my @list = grep { !/^\.{1,2}$/ } readdir $dh; | 
|  | 24 |  |  |  |  | 316 |  | 
| 103 | 8 |  |  |  |  | 124 | closedir $dh; | 
| 104 |  |  |  |  |  |  |  | 
| 105 | 8 |  |  |  |  | 198 | chdir $installed; | 
| 106 |  |  |  |  |  |  |  | 
| 107 | 8 |  |  |  |  | 33 | foreach my $file ( @list ) { | 
| 108 | 8 | 50 |  |  |  | 131 | next unless ( -l $file ); | 
| 109 |  |  |  |  |  |  |  | 
| 110 | 8 |  |  |  |  | 103 | my $link = readlink( $file ); | 
| 111 |  |  |  |  |  |  |  | 
| 112 | 8 | 100 |  |  |  | 180 | if ( index( $link, $old_depository ) == 0 ) { | 
| 113 | 5 |  |  |  |  | 533 | unlink $file; | 
| 114 |  |  |  |  |  |  | } | 
| 115 |  |  |  |  |  |  | } | 
| 116 |  |  |  |  |  |  | } | 
| 117 |  |  |  |  |  |  | } | 
| 118 |  |  |  |  |  |  |  | 
| 119 |  |  |  |  |  |  | sub create_symlink { | 
| 120 | 27 |  |  | 27 | 0 | 95 | my ( $pkg, $new_depository ) = @_; | 
| 121 |  |  |  |  |  |  |  | 
| 122 | 27 |  |  |  |  | 77 | foreach my $dir ( sort keys %{$dir_list} ) { | 
|  | 27 |  |  |  |  | 341 |  | 
| 123 | 405 |  |  |  |  | 2580 | my $link_from_path = | 
| 124 |  |  |  |  |  |  | File::Spec->catdir( $new_depository, $dir_list->{$dir}{dir} ); | 
| 125 |  |  |  |  |  |  |  | 
| 126 | 405 | 100 |  |  |  | 14267 | next unless ( -d $link_from_path ); | 
| 127 |  |  |  |  |  |  |  | 
| 128 | 27 |  |  |  |  | 12053 | opendir( my $dh, $link_from_path ); | 
| 129 | 27 |  |  |  |  | 1061 | my @list = grep { !/^\.{1,2}$/ } readdir $dh; | 
|  | 81 |  |  |  |  | 904 |  | 
| 130 | 27 |  |  |  |  | 347 | closedir $dh; | 
| 131 |  |  |  |  |  |  |  | 
| 132 | 27 |  |  |  |  | 323 | my $link_to_path = File::Spec->catdir( | 
| 133 |  |  |  |  |  |  | Enbld::Home->home, | 
| 134 |  |  |  |  |  |  | $dir_list->{$dir}{dir} | 
| 135 |  |  |  |  |  |  | ); | 
| 136 |  |  |  |  |  |  |  | 
| 137 | 27 | 100 |  |  |  | 737 | unless ( -d $link_to_path ) { | 
| 138 | 20 |  |  |  |  | 10517 | make_path( $link_to_path ); | 
| 139 |  |  |  |  |  |  | } | 
| 140 |  |  |  |  |  |  |  | 
| 141 | 27 |  |  |  |  | 85 | foreach my $file ( @list ) { | 
| 142 | 27 | 50 |  |  |  | 95 | next if ( grep {/^$file$/ } @{$dir_list->{$dir}{omit}} ); | 
|  | 0 |  |  |  |  | 0 |  | 
|  | 27 |  |  |  |  | 321 |  | 
| 143 |  |  |  |  |  |  |  | 
| 144 | 27 |  |  |  |  | 419 | my $symlink = File::Spec->catfile( $link_to_path, $file ); | 
| 145 |  |  |  |  |  |  |  | 
| 146 | 27 | 100 |  |  |  | 1053 | if ( -l $symlink ) { | 
| 147 | 3 |  |  |  |  | 285 | unlink $symlink; | 
| 148 |  |  |  |  |  |  | } | 
| 149 |  |  |  |  |  |  |  | 
| 150 | 27 | 50 |  |  |  | 512 | unless ( -e $symlink ) { | 
| 151 | 27 |  |  |  |  | 2179 | symlink File::Spec->catfile( $link_from_path, $file ), $symlink; | 
| 152 |  |  |  |  |  |  | } | 
| 153 |  |  |  |  |  |  | } | 
| 154 |  |  |  |  |  |  | } | 
| 155 |  |  |  |  |  |  | } | 
| 156 |  |  |  |  |  |  |  | 
| 157 |  |  |  |  |  |  |  | 
| 158 |  |  |  |  |  |  | 1; |