my $raw = '';
- foreach my $machine (sort keys %$data) {
+ # sort longer entries first, so machine definitions with higher granularity are preferred
+ for my $machine (sort { length($b) <=> length($a) || $a cmp $b} keys %$data) {
my $d = $data->{$machine};
+ next if !defined($d); # allow "deleting" set entries
+
$raw .= "machine $machine\n";
$raw .= " login $d->{login}\n" if $d->{login};
$raw .= " password $d->{password}\n" if $d->{password};
sub write_apt_auth {
my ($filename, $fh, $data) = @_;
- my $raw = &$format_apt_auth_data($data);
+ my $raw = $format_apt_auth_data->($data);
die "write failed: $!" unless print $fh "$raw\n";
$orig->{$machine} = $data->{$machine};
}
- return &$format_apt_auth_data($orig);
+ return $format_apt_auth_data->($orig);
}
-register_file('apt-auth', "/etc/apt/auth.conf",
- \&read_apt_auth, \&write_apt_auth,
- \&update_apt_auth, perm => 0640);
+register_file(
+ 'apt-auth',
+ "/etc/apt/auth.conf",
+ \&read_apt_auth,
+ \&write_apt_auth,
+ \&update_apt_auth,
+ perm => 0640,
+);
1;