btrbk: rename %symlink -> %realpath_cache (returning real_path instead of real_url)

pull/88/head
Axel Burri 2016-03-30 23:43:41 +02:00
parent 7ee5778dee
commit 79caba4267
1 changed files with 11 additions and 13 deletions

24
btrbk
View File

@ -171,7 +171,7 @@ my %table_formats = (
my %url_cache; # map URL to btr_tree node
my %fstab_cache; # map HOST to btrfs mount points
my %uuid_cache; # map UUID to btr_tree node
my %symlink; # map URL to REAL_URL (symlink target)
my %realpath_cache; # map URL to realpath (symlink target)
my $dryrun;
my $loglevel = 1;
@ -566,7 +566,7 @@ sub btrfs_subvolume_show($)
$real_path = $1;
DEBUG "Real path for subvolume \"$vol->{PRINT}\" is: $real_path" if($real_path ne $path);
return undef unless(check_file($real_path, { absolute => 1 }));
$symlink{$vol->{URL}} = $vol->{URL_PREFIX} . $real_path if($real_path ne $path);
$realpath_cache{$vol->{URL}} = $real_path if($real_path ne $path);
}
else {
$real_path = $path;
@ -1148,13 +1148,10 @@ sub btrfs_mountpoint($)
TRACE "fstab_cache " . ($mounts ? "HIT" : "MISS") . ": $host";
# get real path
my $path = $symlink{$vol->{URL}};
if($path) {
die unless($path =~ s/^\Q$vol->{URL_PREFIX}\E//);
}
else {
my $path = $realpath_cache{$vol->{URL}};
unless($path) {
$path = system_realpath($vol);
$symlink{$vol->{URL}} = $vol->{URL_PREFIX} . $path;
$realpath_cache{$vol->{URL}} = $path;
}
return (undef, undef, undef) unless($path);
@ -1452,7 +1449,8 @@ sub vinfo_init_root($;@)
$tree_root = $url_cache{$vol->{URL}};
TRACE "url_cache " . ($tree_root ? "HIT" : "MISS") . ": URL=$vol->{URL}";
unless($tree_root) {
if(my $real_url = $symlink{$vol->{URL}}) {
if(my $real_path = $realpath_cache{$vol->{URL}}) {
my $real_url = $vol->{URL_PREFIX} . $real_path;
$tree_root = $url_cache{$real_url};
TRACE "url_cache " . ($tree_root ? "HIT" : "MISS") . ": REAL_URL=$real_url";
}
@ -1463,9 +1461,9 @@ sub vinfo_init_root($;@)
# url_cache miss, read the subvolume detail
my $detail = btrfs_subvolume_show($vol);
if($detail) {
my $real_url = $symlink{$vol->{URL}};
my $real_path = $realpath_cache{$vol->{URL}};
push @fill_cache, $vol->{URL};
push @fill_cache, $real_url if($real_url && (not $url_cache{$real_url}));
push @fill_cache, $vol->{URL_PREFIX} . $real_path if($real_path && (not $url_cache{$vol->{URL_PREFIX} . $real_path}));
# check uuid_cache
if($detail->{uuid}) {
@ -3462,7 +3460,7 @@ MAIN:
# check for duplicate snapshot locations
my $snapdir = config_key($svol, "snapshot_dir", postfix => '/') // "";
my $snapshot_basename = config_key($svol, "snapshot_name") // die;
my $snapshot_target = ($symlink{$sroot->{URL}} // $sroot->{URL}) . '/' . $snapdir . $snapshot_basename;
my $snapshot_target = $sroot->{URL_PREFIX} . ($realpath_cache{$sroot->{URL}} // $sroot->{PATH}) . '/' . $snapdir . $snapshot_basename;
if(my $prev = $snapshot_check{$snapshot_target}) {
ERROR "Subvolume \"$prev\" and \"$svol->{PRINT}\" will create same snapshot: $snapshot_target";
ERROR "Please fix \"snapshot_name\" configuration options!";
@ -3472,7 +3470,7 @@ MAIN:
foreach my $droot (vinfo_subsection($svol, 'target')) {
# check for duplicate snapshot locations
my $snapshot_backup_target = ($symlink{$droot->{URL}} // $droot->{URL}) . '/' . $snapshot_basename;
my $snapshot_backup_target = $droot->{URL_PREFIX} . ($realpath_cache{$droot->{URL}} // $droot->{PATH}) . '/' . $snapshot_basename;
if(my $prev = $backup_check{$snapshot_backup_target}) {
ERROR "Subvolume \"$prev\" and \"$svol->{PRINT}\" will create same backup target: $snapshot_backup_target";
ERROR "Please fix \"snapshot_name\" or \"target\" configuration options!";