summaryrefslogtreecommitdiff
path: root/bin/checklinks
diff options
context:
space:
mode:
authorDaniel Friesel <derf@derf.homelinux.org>2010-01-09 15:13:48 +0100
committerDaniel Friesel <derf@derf.homelinux.org>2010-01-09 15:13:48 +0100
commitd29fce554f40b881fa13fd23cec825dea59282a4 (patch)
tree543926f0c75f09aa0e9d42b2789951d1fcf08f10 /bin/checklinks
parent47bb82e92626514e9e07d8ff733653e061e8cb6c (diff)
checklinks: Improve code readability
Diffstat (limited to 'bin/checklinks')
-rwxr-xr-xbin/checklinks26
1 files changed, 19 insertions, 7 deletions
diff --git a/bin/checklinks b/bin/checklinks
index 000a561..78318d2 100755
--- a/bin/checklinks
+++ b/bin/checklinks
@@ -29,18 +29,24 @@ GetOptions(
);
open(my $links, '<', $linkfile) or die("Can't open $linkfile: $!");
-while(<$links>) {
- chomp;
+while (my $line = <$links>) {
+ chomp($line);
+
foreach my $key (keys(%substitute)) {
- s/\$$key/$substitute{$key}/g;
+ $line =~ s/\$$key/$substitute{$key}/g;
}
- my ($type, $src, $dst) = split;
+
+ my ($type, $src, $dst) = split(/\s+/, $line);
+
next unless ($type eq 'soft' or $type eq 'hard');
+
if ($remove) {
remove_link($type, $src, $dst);
- } elsif ($type eq 'soft') {
+ }
+ elsif ($type eq 'soft') {
check_symlink($src, $dst);
- } elsif ($type eq 'hard') {
+ }
+ elsif ($type eq 'hard') {
check_hardlink($src, $dst);
}
}
@@ -64,6 +70,7 @@ sub check_symlink {
my $dst = shift;
mkdirs($src);
+
if (not -l "$base/$src" and not -e "$base/$src") {
symlink($dst, "$base/$src");
print_format('created', $src, $dst, 'cyan', 1);
@@ -90,6 +97,7 @@ sub check_hardlink {
my $dst = shift;
mkdirs($src);
+
if (not -e "$base/$dst") {
print_format('no dest', $src, $dst, 'red bold', 2);
}
@@ -115,6 +123,7 @@ sub mkdirs {
# the last element is the file
pop(@dirs);
+
foreach(@dirs) {
unless(-d "$path/$_") {
mkdir("$path/$_") or die("Can't create $path/$_: $!");
@@ -132,11 +141,14 @@ sub print_format {
}
return if ($level < $msglevel);
+
if (defined($color)) {
printf(colored('%-9s', $color), $message);
- } else {
+ }
+ else {
printf('%-9s', $message);
}
+
printf(" %-15s -> %-15s\n", $src, $dst);
return;
}