// Open is used to open an existing stable at the given path. If // successful, a new stable is returned. func OpenStable(path string) (*Stable, error) { stable, err := newStable(path) log.Infof("Opening stable in %q", stable.Root) if err != nil { return nil, err } if err := stable.ReadConfig(); err != nil { return nil, err } return stable, nil }
// unpackFrom will ensure that the distribution is unpacked and // installed in the distribution tree under the root directory for // distributions. If this function finishes successfully, nil is // returned, otherwise, an error is returned. func (dt *Dist) unpackDist(root, path string) error { log.Infof("Unpacking distribution %s into %s\n", path, root) switch pathType(path) { case TGZ_PATH: return dt.unpackTar(root, path) case ZIP_PATH: return dt.unpackZip(root, path) case DIR_PATH: dt.Name = filepath.Base(path) dt.Root = filepath.Join(root, dt.Name) os.Symlink(path, dt.Name) return nil default: return ErrInvalidDist } }
// CreateStable creates a new stable where distributions and servers // can be created. func CreateStable(path string) (*Stable, error) { stable, err := newStable(path) if err != nil { return nil, err } log.Infof("Creating stable in %q", stable.Root) if err := stable.setup(); err != nil { return nil, err } if err := stable.WriteConfig(); err != nil { return nil, err } return stable, nil }
func (stable *Stable) Destroy() error { log.Infof("Destroying stable in %q", stable.Root) return stable.teardown() }
func (stable *Stable) teardown() error { log.Infof("Destroying stable in %q\n", stable.Root) return os.RemoveAll(stable.Root) }