| package dkms | |
| import ( | |
| "context" | |
| "fmt" | |
| "os" | |
| "cos.googlesource.com/cos/tools.git/src/pkg/gcs" | |
| "github.com/golang/glog" | |
| ) | |
| // Remove removes a package from the DKMS source tree. | |
| // This will also unbuild and uninstall the package, if applicable. | |
| func Remove(pkg *Package) error { | |
| if !IsAdded(pkg) { | |
| glog.Info("module is not yet added; skipping removal from source tree") | |
| return nil | |
| } | |
| if err := Unbuild(pkg); err != nil { | |
| return err | |
| } | |
| sourceDir := pkg.SourceDir() | |
| glog.Info("removing package sources", sourceDir) | |
| if err := os.Remove(sourceDir); err != nil { | |
| return fmt.Errorf("failed to remove package sources: %v", err) | |
| } | |
| return nil | |
| } | |
| // Remove removes a package from the local DKMS source tree and from the cache. | |
| // | |
| // This will also unbuild the package locally and in the cache, if applicable. | |
| // If the package is installed, this will uninstall it. | |
| func CachedRemove(ctx context.Context, pkg *Package, cache *gcs.GCSBucket, options *Options) error { | |
| if err := CachedUnbuild(ctx, pkg, cache, options); err != nil { | |
| return err | |
| } | |
| if err := Remove(pkg); err != nil { | |
| return err | |
| } | |
| // Only remove from remote cache if the user explicitly asks for it. | |
| if options.Upload && IsAddedInCache(ctx, pkg, cache) { | |
| moduleSourceDir := pkg.CacheSourceDir() | |
| if err := cache.DeleteDir(ctx, moduleSourceDir); err != nil { | |
| return err | |
| } | |
| } | |
| return nil | |
| } |