Skip to content

Commit

Permalink
offline-update: Log warning if ostree repo does not contain target hash
Browse files Browse the repository at this point in the history
When a target was manually added with `fioctl targets add`, it may
reference a ostree hash that is not included the factory's repo.
An offline bundle created in such condition will fail installation,
so printing a warning is appropriate.

Signed-off-by: Andre Detsch <[email protected]>
  • Loading branch information
detsch committed Oct 31, 2024
1 parent 9e1f8ea commit 47696c0
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions subcommands/targets/offline-update.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package targets
import (
"archive/tar"
"compress/bzip2"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -31,6 +32,7 @@ type (
hardwareID string
buildTag string
fetchedApps *client.FetchedApps
sha256 []byte
}

ouBundleMeta struct {
Expand Down Expand Up @@ -179,6 +181,15 @@ Notice that multiple targets in the same directory is only supported in LmP >= v
fmt.Printf("Downloading an ostree repo from the Target's OE build %d...\n", ti.ostreeVersion)
subcommands.DieNotNil(downloadOstree(factory, ti.ostreeVersion, ti.hardwareID, dstDir), "Failed to download Target's ostree repo:")
}

if ti.sha256 != nil {
sha256String := base64.StdEncoding.EncodeToString(ti.sha256)
expectedCommit := path.Join(dstDir, "ostree_repo", "objects", sha256String[0:2], sha256String[2:]+".commit")
if _, err := os.Stat(expectedCommit); errors.Is(err, os.ErrNotExist) {
fmt.Printf("WARNING: ostree repo does not contain target's hash %s, installation will fail. If the target references a custom ostree repo, re-run specifying --ostree-repo-source.\n", sha256String)
}
}

if !ouNoApps {
if (len(ouWave) > 0 || ouProd) && ti.fetchedApps == nil {
// Get the specified target from the list of factory targets to obtain the "original" tag/branch that produced
Expand Down Expand Up @@ -232,6 +243,10 @@ func getTargetInfo(targetFile *tuf.FileMeta) (*ouTargetInfo, error) {
}
info.hardwareID = custom.HardwareIds[0]
info.fetchedApps = custom.FetchedApps
sha256, ok := targetFile.Hashes["sha256"]
if ok {
info.sha256 = sha256
}
if info.fetchedApps == nil {
info.buildTag = custom.Tags[0] // See the assemble.py script in ci-scripts https://github.com/foundriesio/ci-scripts/blob/18b4fb154c37b6ad1bc6e7b7903a540b7a758f5d/assemble.py#L300
}
Expand Down

0 comments on commit 47696c0

Please sign in to comment.