}
my $path = ip_path $ip;
- mkdir $path unless -d $path;
+ mkdir $path unless -e $path;
+ warn "WARNING: $path not directory" unless -d $path;
$path .= '/' . $name;
if ( defined $value ) {
write_file $path, $default;
warn "default $path = $default";
$value = $default;
+ } elsif ( -l $path ) {
+ $value = readlink $path;
} elsif ( -f $path ) {
$value = read_file $path;
chomp $value;
foreach my $file ( glob("$path/*"), glob("$path/*/*") ) {
my $name = $file;
$name =~ s{^$path/+}{} || die "can't remove $path from $name";
- $conf->{ $name } = read_file $file if -f $file;
+ next if -d $file;
+ $conf->{ $name } =
+ -l $file ? readlink $file :
+ -f $file ? read_file $file :
+ '?';
}
return $conf;
}
sub remove {
my $ip = shift;
if ( my $mac = mac_from_ip $ip ) {
- unlink "$server::conf/mac/$mac";
+ unlink mac_path($mac);
}
rmtree "$server::conf/ip/$ip";
}
my $mac = ip_path $ip, 'mac';
if ( -e $mac ) {
$mac = read_file $mac;
+ chomp $mac;
save_ip_mac( $ip, $mac );
warn "## $ip $mac\n";
}