Skip to content
Snippets Groups Projects
Unverified Commit 28514979 authored by Newbyte's avatar Newbyte :snowflake:
Browse files

misc: Also check for .zst-compressed variants of files

Initially I thought of breaking off the Stat + error check call into its
own function as to reduce repetition, but given that it's only useful in
this situation where it only happens twice anyway, I'm not sure it
actually would reduce complexity.

Additionally, this means that .zst-compressed variants of files will be
searched for in all contexts where this function is used. I'm not sure
this is desirable.

Closes https://gitlab.com/postmarketOS/postmarketos-mkinitfs/-/issues/39
parent 1a99953a
No related branches found
No related tags found
No related merge requests found
Pipeline #143068 passed
......@@ -41,10 +41,23 @@ func getFile(file string, required bool) (files []string, err error) {
fileInfo, err := os.Stat(file)
if err != nil {
if required {
return files, fmt.Errorf("getFile: failed to stat file %q: %w", file, err)
// Check if there is a Zstd-compressed version of the file
fileZstd := file + ".zst" // .zst is the extension used by linux-firmware
fmt.Print(fileZstd)
fileInfoZstd, errZstd := os.Stat(fileZstd)
if errZstd == nil {
file = fileZstd
fileInfo = fileInfoZstd
// Unset nil so we don't retain the error from the os.Stat call for the uncompressed version.
err = nil
} else {
if required {
return files, fmt.Errorf("getFile: failed to stat file %q: %w", file, err)
}
return files, nil
}
return files, nil
}
if fileInfo.IsDir() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment