| package dkms |
| |
| import ( |
| "context" |
| |
| "cos.googlesource.com/cos/tools.git/src/pkg/gcs" |
| ) |
| |
| // Status returns the status of a DKMS package. |
| func Status(pkg *Package) PackageStatus { |
| pkgCopy := pkg |
| if pkg.Config == nil { |
| config, err := LoadConfig(pkg) |
| if err != nil { |
| return Broken |
| } |
| pkgCopy.Config = config |
| } |
| |
| added := IsAdded(pkgCopy) |
| if !added { |
| return Broken |
| } |
| |
| built := IsBuilt(pkgCopy) |
| installed := IsInstalled(pkgCopy) |
| |
| // The cases below are the only valid ones... |
| if added && built && installed { |
| return Installed |
| } |
| |
| if added && built && !installed { |
| return Built |
| } |
| |
| if added && !built && !installed { |
| return Added |
| } |
| |
| // ... any other case is considered broken. |
| return Broken |
| } |
| |
| // CachedStatus returns the status of a DKMS package. |
| // If a module is built or added only in the cache, the module will have a |
| // status of Built or Added, respectively. |
| func CachedStatus(ctx context.Context, pkg *Package, cache *gcs.GCSBucket) PackageStatus { |
| status := Status(pkg) |
| |
| // No need to check the cache in this case. |
| if status == Installed || status == Built { |
| return status |
| } |
| |
| pkgCopy := pkg |
| if pkg.Config == nil { |
| configBytes, err := cache.DownloadTextObject(ctx, pkg.CacheConfigPath()) |
| if err != nil { |
| return Broken |
| } |
| |
| config, err := ParseConfig(configBytes, pkg) |
| if err != nil { |
| return Broken |
| } |
| pkgCopy.Config = config |
| } |
| |
| if IsBuiltInCache(ctx, pkgCopy, cache) { |
| return Built |
| } |
| |
| if IsAddedInCache(ctx, pkgCopy, cache) { |
| return Added |
| } |
| |
| return Broken |
| } |