misc: Also check for .zst-compressed variants of files (MR 49)
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. Tested and works with arrow-db820c. I didn't test it on actual hardware, but I verified that the firmware ended up in the initramfs via $ pmbootstrap initfs ls. I choose this device because it uses firmware from linux-firmware and also needs said firmware present in the initramfs. Closes https://gitlab.com/postmarketOS/postmarketos-mkinitfs/-/issues/39
This commit is contained in:
committed by
Clayton Craft
parent
1a99953aa2
commit
dd5cdeace5
@@ -41,10 +41,22 @@ 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
|
||||
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 (also tried %q: %w)", file, err, fileZstd, errZstd)
|
||||
}
|
||||
|
||||
return files, nil
|
||||
}
|
||||
return files, nil
|
||||
}
|
||||
|
||||
if fileInfo.IsDir() {
|
||||
|
Reference in New Issue
Block a user