mirror of https://github.com/digint/btrbk
btrbk: add append option to system_write_raw_info
parent
89c0aa31d7
commit
08cb900a9e
18
btrbk
18
btrbk
|
@ -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 $vol = shift // die;
|
||||||
my $raw_info = shift // die;
|
my $raw_info = shift // die;
|
||||||
|
my %opts = @_;
|
||||||
|
my $append = $opts{append};
|
||||||
my $info_file = $vol->{PATH} . '.info';
|
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
|
# 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->{$_});
|
push @line, ($_ . '=' . $raw_info->{$_});
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG "Creating raw info file " . ($raw_info->{INCOMPLETE} ? "(incomplete)" : "(complete)") . ": $info_file";
|
DEBUG "Writing (" . ($append ? "append:" . join(",", keys %$raw_info) : "create") . ") raw info file: $info_file";
|
||||||
my $echo_text = (join '\n', @line);
|
|
||||||
TRACE "DUMP INFO_FILE=$info_file\n" . join("\n", @line) if($do_trace);
|
|
||||||
|
|
||||||
my $ret = run_cmd(
|
my $ret = run_cmd(
|
||||||
{ cmd => [ 'echo', '-e', '-n', '"' . (join '\n', @line) . '\n"' ] },
|
{ 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),
|
rsh => vinfo_rsh($vol),
|
||||||
});
|
});
|
||||||
return undef unless(defined($ret));
|
return undef unless(defined($ret));
|
||||||
|
|
Loading…
Reference in New Issue