archive: support using lzma (MR 25)
fixes: https://gitlab.com/postmarketOS/postmarketos-mkinitfs/-/issues/2
This commit is contained in:
1
go.mod
1
go.mod
@@ -5,5 +5,6 @@ go 1.16
|
|||||||
require (
|
require (
|
||||||
github.com/cavaliercoder/go-cpio v0.0.0-20180626203310-925f9528c45e
|
github.com/cavaliercoder/go-cpio v0.0.0-20180626203310-925f9528c45e
|
||||||
github.com/klauspost/compress v1.15.12
|
github.com/klauspost/compress v1.15.12
|
||||||
|
github.com/ulikunitz/xz v0.5.10
|
||||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c
|
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c
|
||||||
)
|
)
|
||||||
|
2
go.sum
2
go.sum
@@ -2,5 +2,7 @@ github.com/cavaliercoder/go-cpio v0.0.0-20180626203310-925f9528c45e h1:hHg27A0RS
|
|||||||
github.com/cavaliercoder/go-cpio v0.0.0-20180626203310-925f9528c45e/go.mod h1:oDpT4efm8tSYHXV5tHSdRvBet/b/QzxZ+XyyPehvm3A=
|
github.com/cavaliercoder/go-cpio v0.0.0-20180626203310-925f9528c45e/go.mod h1:oDpT4efm8tSYHXV5tHSdRvBet/b/QzxZ+XyyPehvm3A=
|
||||||
github.com/klauspost/compress v1.15.12 h1:YClS/PImqYbn+UILDnqxQCZ3RehC9N318SU3kElDUEM=
|
github.com/klauspost/compress v1.15.12 h1:YClS/PImqYbn+UILDnqxQCZ3RehC9N318SU3kElDUEM=
|
||||||
github.com/klauspost/compress v1.15.12/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM=
|
github.com/klauspost/compress v1.15.12/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM=
|
||||||
|
github.com/ulikunitz/xz v0.5.10 h1:t92gobL9l3HE202wg3rlk19F6X+JOxl9BBrCCMYEYd8=
|
||||||
|
github.com/ulikunitz/xz v0.5.10/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
|
||||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I=
|
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I=
|
||||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
@@ -18,6 +18,7 @@ import (
|
|||||||
|
|
||||||
"github.com/cavaliercoder/go-cpio"
|
"github.com/cavaliercoder/go-cpio"
|
||||||
"github.com/klauspost/compress/zstd"
|
"github.com/klauspost/compress/zstd"
|
||||||
|
"github.com/ulikunitz/xz"
|
||||||
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/filelist"
|
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/filelist"
|
||||||
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/osutil"
|
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/osutil"
|
||||||
)
|
)
|
||||||
@@ -26,6 +27,7 @@ type CompressFormat string
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
FormatGzip CompressFormat = "gzip"
|
FormatGzip CompressFormat = "gzip"
|
||||||
|
FormatLzma CompressFormat = "lzma"
|
||||||
FormatZstd CompressFormat = "zstd"
|
FormatZstd CompressFormat = "zstd"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -98,6 +100,9 @@ func ExtractFormatLevel(s string) (format CompressFormat, level CompressLevel) {
|
|||||||
|
|
||||||
switch format {
|
switch format {
|
||||||
case FormatGzip:
|
case FormatGzip:
|
||||||
|
case FormatLzma:
|
||||||
|
log.Println("Format lzma doesn't support a compression level, using default settings")
|
||||||
|
level = LevelDefault
|
||||||
case FormatZstd:
|
case FormatZstd:
|
||||||
default:
|
default:
|
||||||
log.Print("Unknown or no compression format set, using gzip")
|
log.Print("Unknown or no compression format set, using gzip")
|
||||||
@@ -295,6 +300,11 @@ func (archive *Archive) writeCompressed(path string, mode os.FileMode) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
case FormatLzma:
|
||||||
|
compressor, err = xz.NewWriter(fd)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
case FormatZstd:
|
case FormatZstd:
|
||||||
level := zstd.SpeedDefault
|
level := zstd.SpeedDefault
|
||||||
switch archive.compress_level {
|
switch archive.compress_level {
|
||||||
|
@@ -243,6 +243,12 @@ func TestExtractFormatLevel(t *testing.T) {
|
|||||||
expectedFormat: FormatGzip,
|
expectedFormat: FormatGzip,
|
||||||
expectedLevel: LevelDefault,
|
expectedLevel: LevelDefault,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "lzma, fast",
|
||||||
|
in: "lzma:fast",
|
||||||
|
expectedFormat: FormatLzma,
|
||||||
|
expectedLevel: LevelDefault,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
Reference in New Issue
Block a user