func (eg *exampleManager) Uninstall(jirix *jiri.X, pdb *profiles.DB, root jiri.RelPath, target profiles.Target) error { version, err := eg.versionInfo.Select(target.Version()) if err != nil { return err } dir := eg.filename(root, target).Abs(jirix) if err := jirix.NewSeq().WriteFile(filepath.Join(dir, "version"), []byte(version), profilesutil.DefaultFilePerm). WriteFile(filepath.Join(dir, version), []byte(version), profilesutil.DefaultFilePerm). Remove(filepath.Join(dir, version)). Done(); err != nil { return err } if pdb.RemoveProfileTarget(eg.installer, eg.name, target) { eg.profile = nil } return nil }
func (eg *exampleManager) Install(jirix *jiri.X, pdb *profiles.DB, root jiri.RelPath, target profiles.Target) error { version, err := eg.versionInfo.Select(target.Version()) if err != nil { return err } target.SetVersion(version) dir := eg.filename(root, target).Abs(jirix) if err := jirix.NewSeq(). MkdirAll(dir, profilesutil.DefaultDirPerm). WriteFile(filepath.Join(dir, "version"), []byte(version), profilesutil.DefaultFilePerm). WriteFile(filepath.Join(dir, version), []byte(version), profilesutil.DefaultFilePerm). Done(); err != nil { return err } eg.profile = pdb.InstallProfile(eg.installer, eg.name, string(root)) target.InstallationDir = string(root) return pdb.AddProfileTarget(eg.installer, eg.name, target) }
func cleanupGC(jirix *jiri.X, db *profiles.DB, root jiri.RelPath, verbose bool, name string) error { mgr := profilesmanager.LookupManager(name) if mgr == nil { fmt.Fprintf(jirix.Stderr(), "%s is not linked into this binary\n", name) return nil } vi := mgr.VersionInfo() installer, profileName := profiles.SplitProfileName(name) profile := db.LookupProfile(installer, profileName) for _, target := range profile.Targets() { if vi.IsTargetOlderThanDefault(target.Version()) { err := mgr.Uninstall(jirix, db, root, *target) logResult(jirix, "Cleanup: -gc", mgr, *target, err) if err != nil { return err } } } return nil }
func writeDB(jirix *jiri.X, db *profiles.DB, installer, path string) error { // Do nothing if the installer is not supplied. This will generally // happen when/if writeDB is called from the top-level profile driver // command rather than from a subcommand. if installer == "" { return nil } fi, err := os.Stat(path) if err != nil { if !os.IsNotExist(err) { return err } // New setup, but the directory doesn't exist yet. if err := os.MkdirAll(path, os.FileMode(0755)); err != nil { return err } } else { if !fi.IsDir() { return fmt.Errorf("%s exists but is not a directory", path) } } // New setup with installers writing their own file in a directory return db.Write(jirix, installer, path) }
// ensureAction ensures that the requested profile and target // is installed/uninstalled, installing/uninstalling it if and only if necessary. func ensureAction(jirix *jiri.X, pdb *profiles.DB, action profiles.Action, installer, profile string, root jiri.RelPath, target profiles.Target) error { verb := "" switch action { case profiles.Install: verb = "install" case profiles.Uninstall: verb = "uninstall" default: return fmt.Errorf("unrecognised action %v", action) } if jirix.Verbose() { fmt.Fprintf(jirix.Stdout(), "%s %v %s\n", verb, action, target) } if t := pdb.LookupProfileTarget(installer, profile, target); t != nil { if jirix.Verbose() { fmt.Fprintf(jirix.Stdout(), "%v %v is already %sed as %v\n", profile, target, verb, t) } return nil } mgr := LookupManager(profiles.QualifiedProfileName(installer, profile)) if mgr == nil { return fmt.Errorf("profile %v is not supported", profile) } version, err := mgr.VersionInfo().Select(target.Version()) if err != nil { return err } target.SetVersion(version) if jirix.Verbose() { fmt.Fprintf(jirix.Stdout(), "%s %s %s\n", verb, profile, target.DebugString()) } if action == profiles.Install { return mgr.Install(jirix, pdb, root, target) } return mgr.Uninstall(jirix, pdb, root, target) }
func addProfileAndTargets(t *testing.T, pdb *profiles.DB, name string) { t1, _ := profiles.NewTarget("cpu1-os1@1", "A=B,C=D") t2, _ := profiles.NewTarget("cpu2-os2@bar", "A=B,C=D") pdb.InstallProfile("test", name, "") if err := pdb.AddProfileTarget("test", name, t1); err != nil { t.Fatal(err) } t2.InstallationDir = "bar" if err := pdb.AddProfileTarget("test", name, t2); err != nil { t.Fatal(err) } }
func cleanupRmAll(jirix *jiri.X, db *profiles.DB, root jiri.RelPath) error { s := jirix.NewSeq() if err := s.AssertFileExists(db.Path()).Remove(db.Path()).Done(); err != nil && !runutil.IsNotExist(err) { return err } else { if err := s.AssertDirExists(db.Path()).RemoveAll(db.Path()).Done(); err != nil && !runutil.IsNotExist(err) { return err } } d := root.Abs(jirix) err := s.AssertDirExists(d). Run("chmod", "-R", "u+w", d). RemoveAll(d). Done() if err == nil || runutil.IsNotExist(err) { fmt.Fprintf(jirix.Stdout(), "success\n") return nil } else { fmt.Fprintf(jirix.Stdout(), "%v\n", err) } return err }
func (p *myNewProfileMgr) Uninstall(jirix *jiri.X, pdb *profiles.DB, root jiri.RelPath, target profiles.Target) error { if pdb.RemoveProfileTarget(p.name, "", target) { p.profile = nil } return nil }
func (p *myNewProfileMgr) Install(jirix *jiri.X, pdb *profiles.DB, root jiri.RelPath, target profiles.Target) error { p.profile = pdb.InstallProfile(p.name, "", "root") return pdb.AddProfileTarget(p.name, "", target) }