Issue #1859 - Part 5: Add format detection to unwrap_full_update.pl

This commit is contained in:
Moonchild 2022-01-23 11:50:20 +00:00 • committed by roytam1
commit b0e0cd7f92

View file

@ -22,19 +22,19 @@ else {
$MAR = "mar"; $MAR = "mar";
} }
if (defined($ENV{"MAR_OLD_FORMAT"})) { if (defined($ENV{"BZIP2"})) {
$MAR_OLD_FORMAT = 1; $BZIP2 = $ENV{"BZIP2"};
if (defined($ENV{"BZIP2"})) {
$BZIP2 = $ENV{"BZIP2"};
}
else {
$BZIP2 = "bzip2";
}
} }
else { else {
$MAR_OLD_FORMAT = 0; $BZIP2 = "bzip2";
if (defined($ENV{"XZ"})) { }
$XZ = $ENV{"XZ"};
if (defined($ENV{"XZ"})) {
$XZ = $ENV{"XZ"};
}
else {
if (system("xz --version > /dev/null 2>&1") != 0) {
die("The xz executable must be in the path.");
} }
else { else {
$XZ = "xz"; $XZ = "xz";
@ -62,15 +62,31 @@ $archive = $ARGV[0];
$? && die("Couldn't run \"$MAR\" -t"); $? && die("Couldn't run \"$MAR\" -t");
shift @marentries; if (system("$MAR -x \"$archive\"") != 0) {
die "Couldn't run $MAR -x";
}
system("$MAR -x \"$archive\"") == 0 || die "Couldn't run $MAR -x"; # Try to determine if the mar file contains bzip2 compressed files and if not
# assume that the mar file contains lzma compressed files. The updatev3.manifest
# file is checked since a valid mar file must have this file in the root path.
open(my $testfilename, "updatev3.manifest") or die $!;
binmode($testfilename);
read($testfilename, my $bytes, 3);
if ($bytes eq "BZh") {
$MAR_OLD_FORMAT = 1;
} else {
undef $MAR_OLD_FORMAT;
}
close $testfilename;
shift @marentries;
foreach (@marentries) { foreach (@marentries) {
tr/\n\r//d; tr/\n\r//d;
my @splits = split(/\t/,$_); my @splits = split(/\t/,$_);
my $file = $splits[2]; my $file = $splits[2];
print "Decompressing: " . $file . "\n";
if ($MAR_OLD_FORMAT == 1) { if ($MAR_OLD_FORMAT == 1) {
system("mv \"$file\" \"$file.bz2\"") == 0 || system("mv \"$file\" \"$file.bz2\"") == 0 ||
die "Couldn't mv \"$file\""; die "Couldn't mv \"$file\"";
@ -85,3 +101,4 @@ foreach (@marentries) {
} }
} }
print "Finished\n";