btrbk: add append option to system_write_raw_info

ionice
Axel Burri 2022-10-19 11:18:40 +02:00
parent 89c0aa31d7
commit 08cb900a9e
1 changed files with 7 additions and 11 deletions

18
btrbk
View File

@ -2075,28 +2075,24 @@ sub system_read_raw_info_dir($)
}
sub system_write_raw_info($$)
sub system_write_raw_info($$;@)
{
my $vol = shift // die;
my $raw_info = shift // die;
my %opts = @_;
my $append = $opts{append};
my $info_file = $vol->{PATH} . '.info';
my @line;
push @line, "#btrbk-v$VERSION";
push @line, "# Do not edit this file";
# sort by %raw_info_sort, then by key
foreach(sort { (($raw_info_sort{$a} || 99) <=> ($raw_info_sort{$b} || 99)) || ($a cmp $b) } keys %$raw_info) {
my @line = $append ? () : ("#btrbk-v$VERSION", "# Do not edit this file");
foreach(sort { (($raw_info_sort{$a} // 99) <=> ($raw_info_sort{$b} // 99)) || ($a cmp $b) } keys %$raw_info) {
push @line, ($_ . '=' . $raw_info->{$_});
}
DEBUG "Creating raw info file " . ($raw_info->{INCOMPLETE} ? "(incomplete)" : "(complete)") . ": $info_file";
my $echo_text = (join '\n', @line);
TRACE "DUMP INFO_FILE=$info_file\n" . join("\n", @line) if($do_trace);
DEBUG "Writing (" . ($append ? "append:" . join(",", keys %$raw_info) : "create") . ") raw info file: $info_file";
my $ret = run_cmd(
{ cmd => [ 'echo', '-e', '-n', '"' . (join '\n', @line) . '\n"' ] },
{ redirect_to_file => { unsafe => $info_file },
{ ($append ? "append_to_file" : "redirect_to_file") => { unsafe => $info_file },
rsh => vinfo_rsh($vol),
});
return undef unless(defined($ret));